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 :-)

Will H2012-02-09T04:23:46Z

Favorite Answer

Try repaint during action performed.

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();
}
}

?2016-11-07T03:34:01Z

import java.applet.*; import java.awt.adventure; import java.awt.pictures; public classification NewClass2 extends Applet implements Runnable { int i; String message; public void init() { setBackground(java.awt.colour.eco-friendly); } public void initiate(){ new Thread(this).initiate(); } public void run() { at the same time as (authentic) { i++; repaint(); try { Thread.sleep(333); } capture (InterruptedException e) { ; } } } public void paint(pictures g) { g.drawString("i = " + i, 10, 20); g.drawString(message, 20, 20); } public boolean keyDown(adventure e, int key) { message = "fee = " + key; go back authentic; } }