星球大战源码 (JAR) Simon Jansen (C) 1999
- import java.applet.*;
- import java.awt.*;
- import java.awt.event.*;
- import java.awt.SystemColor.*;
- import java.net.*;
- import java.io.*;
- public class SwPlay extends Applet {
- public static void main (String[] s) {
- new AppletShell("Star Wars",500,250,false, false, new SwPlay());
- }
- DisplayArea displayArea = new DisplayArea(13, 67);
- MouseProcessor mouseProcessor = new MouseProcessor();
- SwPlayThread threadMain;
- public void init() {
- System.out.println("Inside INIT method");
- setLayout(new BorderLayout());
- displayArea.setForeground(Color.white);
- displayArea.setBackground(Color.black);
- this.add( displayArea, BorderLayout.CENTER );
- displayArea.show();
- show();
- }
- public void start() {
- System.out.println( "Inside START method" );
- if( ( threadMain == null ) || ( threadMain.isAlive() == false ) ){
- System.out.println( "Starting new thread" );
- threadMain = new SwPlayThread();
- threadMain.bFastForward = false;
- System.out.println("Adding mouse listener");
- displayArea.addMouseListener( mouseProcessor );
- System.out.println("Getting resource stream");
- threadMain.inputStream = getClass().getResourceAsStream( "data/sw1.txt" );
- if( threadMain.inputStream == null ){
- System.out.println( "Getting resource failed" );
- }
- if( threadMain == null ){
- System.out.println( "New threadMain failed" );
- }
- threadMain.bAtEnd = false;
- threadMain.displayArea = displayArea;
- threadMain.start();
- } else {
- System.out.println( "Resuming thread" );
- threadMain.newResume();
- }
- }
- public void stop() {
- System.out.println( "Inside STOP method" );
- if( threadMain.bAtEnd == false ) {
- System.out.println( "Suspending thread" );
- threadMain.newSuspend();
- } else {
- System.out.println( "Stopping thread" );
- threadMain.newStop();
- threadMain = null;
- }
- }
- public void destroy() {
- System.out.println( "Inside DESTROY method" );
- displayArea.destroy();
- if( threadMain != null ){
- System.out.println( "Stopping thread" );
- threadMain.stop();
- threadMain = null;
- }
- }
- //------------------------------------------------------------------------------
- class MouseProcessor extends MouseAdapter{
- MouseProcessor(){
- System.out.println("Inside MouseProcessor Constructor method");
- }
- public void mousePressed(MouseEvent e){
- System.out.println("Inside PRESSED method: FAST FORWARD");
- threadMain.bFastForward = true;
- threadMain.interrupt();
- }
- public void mouseReleased(MouseEvent e){
- System.out.println("Inside RELEASED method: NORMAL SPEED");
- threadMain.bFastForward = false;
- threadMain.interrupt();
- }
- }
- //------------------------------------------------------------------------------
- public class SwPlayThread extends Thread {
- public boolean bAtEnd;
- public boolean bFastForward;
- public DisplayArea displayArea;
- public InputStream inputStream;
- public InputStreamReader inputStreamReader;
- public LineNumberReader lineNumberReader;
- public MouseListener mouseListener;
- .......................
管理员回复: 来源网络!