My friend and I are in a Computer Science I class, and we are momentarily working on a project which asks you to import a method from a previously edited source, into another java source file. Here is our code.
import java.awt.Graphics;
import java.awt.Color;
import java.awt.Image;
import java.awt.Container;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.ImageIcon;
import java.awt.*;
public class PacerTest extends JPanel
{
private Image leftFoot;
private Image rightFoot;
private Image leftshoe;
private Image rightshoe;
// Constructor
public PacerTest()
{
leftshoe = (new ImageIcon("leftshoe.gif")).getImage();
rightshoe = (new ImageIcon("rightshoe.gif")).getImage();
}
// Called automatically when the panel needs repainting
public void paintComponent(Graphics g)
{
super.paintComponent(g);
int x = 500;
int y = 300;
int stepLength = 100;
int stepLength2 = 50;
Foot rightFoot = new Foot(x, y-50, leftshoe);
Foot leftFoot = new Foot(x, y, rightshoe);
for (int count = 1; count <= 4; count++)
{
leftFoot.draw(g);
rightFoot.draw(g);
leftFoot.moveForward(stepLength);
rightFoot.moveForward(stepLength);
leftFoot.turn(90);
rightFoot.turn(90);
rightFoot.moveSideways(-stepLength2);
rightFoot.moveForward(stepLength2);
}
}
public static void main(String[] args)
{
JFrame window = new JFrame("Feet");
window.setBounds(100, 100, 500, 480);
window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
PacerTest panel = new PacerTest();
panel.setBackground(Color.WHITE);
Container c = window.getContentPane();
c.add(panel);
window.setVisible(true);
}
}
instead of using the move forward, turn(90), and move sideways commands, we should be able to import a method from another class that predefines these commands. Does anyone know how to import a method? I have tried and it just comes up with "illegal start of expression" I would greatly appreciate it if someone could tell us what we are doing wrong, or point us in the right direction. -From our computer to your's- zach&kody