Logo 
Search:

Java Forum

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds

problem with my output

  Asked By: Diane    Date: May 01    Category: Java    Views: 495
  

My problem is that when the program is ran, the Center button takes
all the page. The way i would like it is that all the buttons are in
the bottom of the applet and image appears on top.

--------------------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);
add(Up);
add(Down);
add(Left);
add(Right);
keyPad.setLayout(new BorderLayout());
add(myCanvas,BorderLayout.NORTH);
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 problem with my output Or get search suggestion and latest updates.




Tagged: