Logo 
Search:

Java Forum

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds

fOR FPIERRA0800

  Asked By: Harry    Date: Jul 21    Category: Java    Views: 350
  

You were'nt adding the buttons to the south panel, but everything to
the applet

its fixed in following code




import java.awt.*;
import java.awt.event.*;
import java.applet.*;

public class MoveIt extends Applet implements ActionListener
{
private Image cup;
private Panel keyPad;
public int top =10;
public int left =10;

public void init()
{
cup = getImage(getDocumentBase(),"cup.gif");
Canvas myCanvas = new Canvas();
keyPad = new Panel();
Button Up = new Button("Up");
Button Down = new Button("Down");
Button Left = new Button("Left");
Button Right = new Button("Right");
Button Center = new Button("Center");
setBackground(Color.blue);

setLayout(new BorderLayout());

add(keyPad,BorderLayout.SOUTH);
keyPad.add(Up);
keyPad.add(Down);
keyPad.add(Left);
keyPad.add(Right);
//keyPad.setLayout(new BorderLayout());
add(myCanvas,BorderLayout.NORTH);
keyPad.add(Center);



Up.addActionListener(this);
Down.addActionListener(this);
Left.addActionListener(this);
Right.addActionListener(this);
Center.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 -= 10;
if(arg == "Down")
top +=10;
if(arg == "Left")
left -= 10;
if(arg == "Right")
left += 10;
if(arg == "Center")
{
top = 50;
left = 50;
}
}
// keyPad.repaint();

}

Share: 

 

No Answers Found. Be the First, To Post Answer.

 
Didn't find what you were looking for? Find more on fOR FPIERRA0800 Or get search suggestion and latest updates.

Related Topics:



Tagged:  

 

Related Post