Psw  

Posted by Kedawung Agency in

import java.awt.event.*;
import javax.swing.*;
import java.awt.*;
public class pesawat
implements KeyListener
{

public JButton bar = new JButton();
private int jalan_x;
private int jalan_y;
private JFrame xFrame;
public peluru xPeluru;
public pesawat(int jln_x,int jln_y,JFrame s) {

xFrame = s;
jalan_x=jln_x;
jalan_y=jln_y;
xFrame.add(bar);
bar.setBounds(jalan_x,jalan_y,50,20);
xPeluru = new peluru(jalan_x,jalan_y,xFrame);
xPeluru.button1.setVisible(false);
bar.addKeyListener(this);


}

public int getX()
{
return jalan_x;
}

public int getY()
{
return jalan_y;
}

public void keyPressed(KeyEvent e)
{
if(e.getKeyCode()==KeyEvent.VK_RIGHT)
{ if (jalan_x<=xFrame.getWidth()-bar.getWidth()-30)
{ jalan_x+=10;
bar.setBounds(jalan_x,jalan_y,50,20);}
}else if (e.getKeyCode()==KeyEvent.VK_LEFT)
{ if (jalan_x>=10)
{ jalan_x-=10;
bar.setBounds(jalan_x,jalan_y,50,20);}
}
else if(e.getKeyCode()==KeyEvent.VK_F)
{
if (xPeluru.button1.isVisible()==false)
{
xPeluru.setY(jalan_y);
xPeluru.setX(jalan_x);
xPeluru.setButton(true);
}
}
}

public void keyReleased(KeyEvent e)
{
}
public void keyTyped(KeyEvent e)
{
}


}

This entry was posted on Rabu, 19 Mei 2010 at 03.32 and is filed under . You can follow any responses to this entry through the comments feed .

0 komentar

Posting Komentar