package HappyBird;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
@SuppressWarnings("serial")
public class Cage extends Frame implements ActionListener{
private Button quit = new Button("Quit");
private Button start = new Button("Start");
private Button stop = new Button("Stop");
/*private Button fire = new Button("Fire");*/
private Bird birds[] = new Bird[10];
private Stone stones = null;
Image bird = Toolkit.getDefaultToolkit().getImage("bird.jpg");
Image stone = Toolkit.getDefaultToolkit().getImage("arrow.jpg");
public Cage(){
super("Cage with Birds");
setLayout (new FlowLayout());
add(quit); quit.addActionListener(this);
add(start); start.addActionListener(this);
add(stop); stop.addActionListener(this);
add(stones);stones.addKeyListener();
/*add(fire); fire.addActionListener(this);*/
validate(); setSize(600,600);
setVisible(true);
for(int i = 0;i
int x = (int)(getSize().width*Math.random());
int y = (int)(getSize().height*Math.random());
birds[i] = new Bird(this,x,y);
}
int y = (int)(getSize().height*Math.random());
int x = 1;
stones = new Stone(this,x, y);
}
public void actionPerformed(ActionEvent ae){
if(ae.getSource() == stop)
{
for(int i=0;i
birds[i].halt();
stones.halt();
}
if(ae.getSource() == start)
{
for(int i=0;i
int x=birds[i].x;
int y=birds[i].y;
birds[i].halt();
birds[i] = new Bird(this,birds[i].x,birds[i].y);
}
int x=stones.x;
int y=stones.y;
stones.halt();
stones=new Stone(this,x,y);
}
/*if(ae.getSource() == fire)
stones = new Stone(this,stones.x,stones.y);n++;*/
if(ae.getSource() == quit)
System.exit(0);
}
/*public void keyTyped(KeyEvent e) {
// TODO Auto-generated method stub
}
public void keyPressed(KeyEvent e){
// TODO Auto-generated method stub
int key = e.getKeyCode();
if(e.getKeyCode()==KeyEvent.VK_DOWN){
stones.y++;
stones.halt();
stones=new Stone(this,stones.x,stones.y);
}
else if(e.getKeyCode()==KeyEvent.VK_UP){
stones.y--;
}
else if(e.getKeyCode()==KeyEvent.VK_LEFT){
stones.x--;
}
else if(e.getKeyCode()==KeyEvent.VK_RIGHT){
stones.x++;
}
}
public void keyReleased(KeyEvent e) {
// TODO Auto-generated method stub
}*/
public void paint(Graphics g){
for(int i = 0;i
if(birds[i] !=null)
birds[i].draw(g);
stones.draw(g);
}
public static void main(String arg[]){
//TODO Auto-generated method stub @SuppressWarnings("unused")
Cage table = new Cage();
table.addKeyListener(table);
}
public Bird[] getBirds(){return birds;};
}