one error in Java code Please help?
Hi Everyone
I need help with this code please. This code is created to import a adjustable graphic in an Applet.
Code: import java.awt.*;
import java.awt.event.*;
import java.applet.*;
public class MoveIt extends Applet implements ActionListener
{
// Declare Variables
private Image cup;
private Panel keyPad;
public int top = 15;
public int left = 15;
private Button keysArray[];
public void init()
{
cup = getImage(getDocumentBase(), "cup.gif");
Canvas myCanvas = new Canvas();
// Construct Panel and Buttons
keypad = new Panel();
keys[1] = new Button("Up");
keys[2] = new Button("Left");
keys[3] = new Button("Right");
keys[4] = new Button("Down");
keys[5] = new Button("Center");
// Set Background Color
setBackground(blue);
// Set Layout Manager for Frame
this.setLayout(new BorderLayout());
// Set keypad Layout Manager
this.setLayout(new BorderLayout());
//Add Buttons to the keypad Panels
keypad.add(Up, BorderLayout.NORTH);
keypad.add(Down, BorderLayout.SOUTH);
keypad.add(Left, BorderLayout. EAST);
keypad.add(Right, BorderLayout.WEST);
keypad.add(Center, BorderLayout.Center);
add(myCanvas, BorderLayout.NORTH);
add(keypad, BorderLayout.SOUTH);
// Add ActionListener Statements for each of the Buttons
UpButton.addActionListener(this);
DownButton.addActionListener(this);
LeftButton.addActionListener(this);
RightButton.addActionListener(this);
CenterButton.addActionListener(this);
}
public void paint(Graphics g)
{
g.drawImage(cup, left, top, this);
}
public void actionPerformed(ActionEvent e)
{
String arg = e.getActionCommand();
if(arg == "Up")
top = top -15;
if(arg == "Down")
top = top + 15;
if(arg == "Left")
top = top - 15;
if(arg == "Right")
top = top + 15;
if(arg == "Center")
top = 60;
Left = 125;
}
repaint();
}
Error is: :\Course Technology\59850_Java3e_DF1-4\Chapters 5-8\Chapter06\MoveIt.java:90: invalid method declaration; return type required
repaint();
^
1 error
Thank You :-)