// (c) 1998 Ekkehard Kraemer (ekraemer@pluto.camelot.de) import java.applet.*; import java.awt.*; /** * The applet itself - just a button and some start-up logic. *

* Source * * @see BojngFrame * @see Bojng * @see Images */ public class BojngAppl extends Applet implements Runnable { /** Initializes button layout and starts the image loading thread. */ public BojngAppl() { super(); setLayout(new BorderLayout()); goButton=new Button("Go!"); goButton.enable(false); label=new Label(""); label.setAlignment(label.CENTER); add("Center",goButton); add("South",label); layout(); (new Thread(this)).start(); } /** Try to load images. */ public void run() { label.setText("Loading graphics..."); try { Thread.sleep(500); } catch (Exception e) {} if (!Images.init(this,getDocumentBase(),label)) { if (Images.errFile==null) label.setText("Error loading graphics..."); else label.setText("Error loading "+Images.errFile+".gif"); goButton.setLabel("Retry"); goButton.enable(true); return; } try { Thread.sleep(500); } catch (Exception e) {} label.setText(""); goButton.enable(true); goButton.setLabel("Go!"); } /** Handles mouse clicks, creates, starts and stops games. * * @param e the event */ public boolean handleEvent(Event e) { if (e.id==Event.ACTION_EVENT && e.target==goButton) { if (Images.imgs==null) { goButton.enable(false); (new Thread(this)).start(); } else { if (frame==null) { Label l=new Label("---"); l.setBackground(Color.black); l.setForeground(Color.green); l.setAlignment(Label.CENTER); // Font f=l.getFont(); Font nf=new Font("SansSerif",Font.PLAIN,20); l.setFont(nf); Stats s=new Stats(); Bojng b=new Bojng(getDocumentBase(),s,l); frame=new BojngFrame(b,s,l); goButton.setLabel("Stop!"); } else { frame.dispose(); frame=null; goButton.setLabel("Go!"); } } return true; } return false; } protected BojngFrame frame; // the main game window protected Button goButton; // the "Go" button protected Label label; // the status label }