Msh  

Posted by Kedawung Agency in

import java.awt.event.*;
import javax.swing.*;
import java.awt.*;
public class Musuh {
public JButton button1 = new JButton("Uvo");
private JButton button2 = new JButton("Uvo");
private JButton button3 = new JButton("Uvo");
private JButton button4 = new JButton("Uvo");
private JButton button5 = new JButton("Uvo");
private int jalan_x;
private int jalan_y;
private boolean status_y;
private boolean status_x;
public Timer Datetime;
private int countery=0;
private boolean status_menang;
private JFrame xframe;

public void setstatus_x(boolean stsx)
{
status_x= stsx;
}
public void setstatus_y(boolean stsy)
{
status_y= stsy;
}
public void setStatusmenang()
{
button1.setText("Hancur");
}
public boolean getStatusmenang()
{
return status_menang;
}
public int getX()
{
return jalan_x;
}
public int getY()
{
return jalan_y;
}
public Musuh() {
}

public void gantiArah()
{
if(status_x==true)
{
status_x=false;
}else{
status_x=true;
}

if(status_y==true)
{
status_y=false;
}else{
status_y=true;
}
}

public Musuh(int jlx, int jly, boolean sx, boolean sy,JFrame s) {

jalan_x=jlx;
jalan_y=jly;
status_x=sx;
status_y=sy;
xframe = s;

status_menang=false;
button2.setVisible(false);
button3.setVisible(false);
button4.setVisible(false);
button5.setVisible(false);
s.add(button1);
s.add(button2);
s.add(button3);
s.add(button4);
s.add(button5);
button1.setBounds(jalan_x,jalan_y,20,20);
button2.setBounds(jalan_x-4,jalan_y,5,5);
button3.setBounds(jalan_x+24,jalan_y,5,5);
button4.setBounds(jalan_x,jalan_y-4,5,5);
button5.setBounds(jalan_x,jalan_y+24,5,5);

Datetime= new Timer(200,mondar_mandir);
Datetime.start();
}

private ActionListener mondar_mandir = new ActionListener()
{
public void actionPerformed(ActionEvent e)
{ //Target hancur
button1.setBounds(jalan_x,jalan_y,20,20);
button2.setBounds(jalan_x-4,jalan_y,5,5);
button3.setBounds(jalan_x+24,jalan_y,5,5);
button4.setBounds(jalan_x,jalan_y-4,5,5);
button5.setBounds(jalan_x,jalan_y+24,5,5);
if (button1.getText().equals("Hancur"))
{
countery+=1;
if (countery>=5)
{
button2.setVisible(false);
button3.setVisible(false);
button4.setVisible(false);
button5.setVisible(false);
jalan_x=0;
jalan_y=0;
}else
{
button1.setVisible(false);
button2.setVisible(true);
button3.setVisible(true);
button4.setVisible(true);
button5.setVisible(true);
}
}
//Target Mondar mandir
button1.setBounds(jalan_x,jalan_y,20,20);
if (jalan_y>=xframe.getHeight()-50)
{ status_y = true;
//status_menang=true;
//Datetime.stop();
}else if (jalan_y <=10)
{
status_y =false;
}

if (status_y==true)
{
jalan_y-=10;
}else
jalan_y+=10;

if (jalan_x>=xframe.getWidth()-30)
{ status_x = true;
}
else if (jalan_x <=0)
{
status_x =false;
}

if (status_x==true)
{
jalan_x-=10;
}else
jalan_x+=10;
}
};
}

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

0 komentar

Posting Komentar