import java.awt.*; import java.awt.event.*; import java.applet.*; public class Centipede extends Applet implements ActionListener { private int rectX=0,rectY=0; private int rectWidth=300, rectHeight=400; private Button btnStart, btnStop; //buttons private CentipedeBug centipede; //centipede object private Player player; //player object private Panel buttonsPanel = new Panel(); //I've created a panel to hold the start button //public Canvas mainCanvas = new Canvas(); //a canvas is created for the main animation space *** IS THIS A GOOD IDEA TO MAKE THIS PUBLIC? //---------------------------- //init() //---------------------------- public void init() //runs only once { buttonsPanel.setBackground(Color.black); //create a start button btnStart = new Button("Start"); buttonsPanel.add(btnStart); //button is added to panel btnStart.addActionListener(this); add(buttonsPanel); //remember this step, the panel must be added to the applet window //mainCanvas.setBackground(Color.gray); //mainCanvas.setSize(250,250); //add(mainCanvas); } //---------------------------- //actionPerformed(): listens to button clicks //---------------------------- public void actionPerformed(ActionEvent event) { //if the start button is pressed if(event.getSource()==btnStart) { Graphics g=getGraphics(); Graphics g2=getGraphics(); //for some reason I need to have a seperate Graphics object for each thread centipede = new CentipedeBug(g); centipede.start(); //start the centipede thread player = new Player(g2); player.start(); //start the centipede thread } } public void paint(Graphics g) { g.setColor(Color.white); g.fillRect(rectX,rectY,rectWidth,rectHeight); } /*class myCanvas extends Canvas { public void paint(Graphics g) { g.setColor(Color.black); g.drawString("I want the game to be drawn here",50,100); } }*/ }