星球大战源码 (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;
.......................

点击下载starwars.zip

关注微信公众号,手机阅读更方便: 程序员的阅微草堂

知识共享许可协议莿鸟栖草堂CFC4N 创作,采用 知识共享 署名-非商业性使用-相同方式共享(3.0未本地化版本)许可协议进行许可。基于http://www.cnxct.com上的作品创作。转载请注明转自:星球大战源码 (JAR) Simon Jansen (C) 1999

One thought on “星球大战源码 (JAR) Simon Jansen (C) 1999

发表评论

电子邮件地址不会被公开。 必填项已用*标注

This site uses Akismet to reduce spam. Learn how your comment data is processed.