<JSTORM> Revision <10> JSTORM http://wwwjstormpekr
Issued by: < > Revision: <10> <2000/8/02> Document Information Document title: Document file name: Revision number: <10> Issued by: Issue Date: <2000/8/2 > Status: doc (pjh@jstormpekr) : (junoyoon@jstormpekr) Final Content Information Audience Abstract Reference Benchmark information - JSTORM <2/135>
Issued by: < > Revision: <10> <2000/8/02> Document Approvals Signature date Signature date Revision History Revision Date Author Description of change JSTORM <3/135>
Issued by: < > Revision: <10> <2000/8/02> 1 Table of Contents 1 2 2 1 2 3 1 2 3 - (ICEBLOX) 4 1 URL 2 / 3 - / - JSTORM <4/135>
Issued by: < > Revision: <10> <2000/8/02>, (what),,,,, JDK 101, Window 95 Netscape 30 Explorer 30 JDK11 JDK 10X JDK 10X JDK11, JDK1 1, JDK11 JSTORM <5/135>
Issued by: < > Revision: <10> <2000/8/02> 1, * C++ (,, ), (!) * *, *, * C/C++ (type checking), *, (machine code), (Byte Code) * (multithread) JSTORM <6/135>
Issued by: < > Revision: <10> <2000/8/02>,, < 1>, (C ) CPU ( ), JSTORM <7/135>
Issued by: < > Revision: <10> <2000/8/02> < 2>,, (Java Virtual Machine),,,,, < 3>, (container), HTML, JSTORM <8/135>
Issued by: < > Revision: <10> <2000/8/02> JSTORM <9/135>
Issued by: < > Revision: <10> <2000/8/02> 1) JDK(Java Development Kit),,, JDK URL JDK 11 http://wwwjavasoftcom/ ftp://ftpjavasoftcom/pub/www/java ftp://ftpjavasoftcom/pub/java JDK * java :, * javac :, java, clas s * appletviewer : HTML * jdb : * javap : * javah : C * javadoc : HTML 2) JDK (prompt),, Visual J++ Visual Cafe Latte Java Workshop JDK 1) Windows 95 FTP exe, MSDOS java JSTORM <10/135>
Issued by: < > Revision: <10> <2000/8/02> 2) Unix FTP gz tar tar java JDK, path java bin JDK 1) Windows 965 autoexecbatpath java \bin ) path=c:\java\bin;c:\windows 2) Unix 2 < 4> autoexecbat cshrc path java /bin ) set PATH /usr/local/java/bin:/usr/local/bin 2 * (Application) JDK, (standalone) JSTORM <11/135>
Issued by: < > Revision: <10> <2000/8/02> * (Applet) HTML, ( netscape 20, Internet Explorer 30 ) /,, 1) public static void main(string argv[]) { [import ;] /* _ java */ public class _ { public static void main(string argv[]) { < > "Hello, World" public class HelloWorld { public static void main(string argv[]) { Systemoutprintln( Hello, World"); 1) main(), HelloWorldjava 2) javac HelloWorldjava HelloWorldclas s JSTORM <12/135>
Issued by: < > Revision: <10> <2000/8/02> 3) java HelloWorld", < 5> "Hello, World" < 5> 2) javaappletapplet init(), start(), stop(), paint() import javaappletapplet; public class Example extends Applet{ public void start(){ < > Hello, World", JSTORM <13/135>
Issued by: < > Revision: <10> <2000/8/02> import javaawtgraphics; public class HelloWorld2 extends javaappletapplet { public void init() { resize(150, 25); public void paint(graphics g) { gdrawstring("hello world!", 50, 25); 1) HelloWorld2java 2) javac HelloWorld2java HelloWorld2cl ass ( ) 3) "examplehtml" <html><head><title>a simple program</title></head> <body><applet code="helloworldclass" width=150 height=25></applet> </body></html> 4) appletviewer examplehtml", examplehtml < 6> < 6> 3) &? "public static void main()", JSTORM <14/135>
Issued by: < > Revision: <10> <2000/8/02> import javaawtgraphics; public class HelloMerge extends javaappletapplet { public static void main(string argv[]) { Systemoutprintln("Hello, World"); public void init() { resize(150, 25); public void paint(graphics g) { gdrawstring("hello world!", 50, 25);, "public static void main()", JSTORM <15/135>
Issued by: < > Revision: <10> <2000/8/02> 1 2, < 1> (thing), (place), (concept),,,,, < 1> < 2>, < 2> ( ) ( ),,, JSTORM <16/135>
Issued by: < > Revision: <10> <2000/8/02> < 3>,, < 3> 2,,,,,, import javautil*; public class Company { public static void main(string[] args) { Employee[] worker = new Employee[3]; worker[0] = new Employee("haha", 40000, new Date(89,9,1)); /* Manager Employee -> worker[1] = new Manager("hoho", 60000, new Date(87,11,1)); worker[2] = new Employee("hihi", 50000, new Date(90,9,10)); int i; /* worker[1]raisesalary(10) Manager for ( i=0; i<workerlength;i++) worker[i]raisesalary(10); for ( i=0; i<workerlength;i++) worker[i]print(); JSTORM <17/135>
Issued by: < > Revision: <10> <2000/8/02> class Employee { private String name; private double salary; private Date hiredate; public Employee(String n, double s, Date d) { name = n; salary = s; hiredate = d; public void print() { Systemoutprintln(name + " " + salary + " " + hireyear()); public void raisesalary(double bypercent) { salary *= 1 + bypercent/100; public int hireyear() { return hiredategetyear(); /* Employee, ManagerEmployee */ class Manager extends Employee { public Manager(String n, double s, Date d) { super(n,s,d); /* Employee raisesalary */ public void raisesalary(double bypercent) { Date todate = new Date(); double bonus = 05*(toDategetYear() - hireyear()); superraisesalary(bypercent+bonus); < > Companyjava JSTORM <18/135>
Issued by: < > Revision: <10> <2000/8/02>, < > < 4> worker[1] = new Manager("hoho", 60000, new Date(87,11,1)); workeremployee, Manager? ManagerEmployee, for ( i=0; i<workerlength;i++) worker[i]raisesalary(10); worker[1]raisesalary(10)employee raisesalary()? Managerrais esalary?, workeremployee Employee worker[1] Manager Manager worker[0], woker[1], worker[2] raisesalary(), worker[0],worker[2]employee, worker[1]manager,,, worker JSTORM <19/135>
Issued by: < > Revision: <10> <2000/8/02> Employee[] worker = new Employee[4]; worker[3] = new PartTimer("kiki", 10000, new Date(96,1,1)); for ( i=0; i<workerlength;i++) worker[i]raisesalary(10); for ( i=0; i<workerlength;i++) worker[i]print(); public class PartTimer extends Employee { public void raisesalary(double bypercent) { // CPascal JSTORM <20/135>
Issued by: < > Revision: <10> <2000/8/02> 3 au (gif, jpeg), (, 3 ),, au 2,, 1 ( ),, 1 20-30 (loop), while( moreframetopaint) { paintcurrentframe(); sleep for some time; // advancetonextframe();,, 2(, ) Runnable run(), paint(), JSTORM <21/135>
Issued by: < > Revision: <10> <2000/8/02> import javaawt*; /* implements, */ public class Example1Applet extends javaappletapplet implements Runnable { int frame; // int delay; // Thread animator; // /** *, * */ public void init() { String str = getparameter("fps"); // HTML, "fps int fps = (str!= null)? IntegerparseInt(str) : // delay = (fps > 0)?(1000 / fps) : 100; // milisecond, 1000/fps /** *, */ public void start() { animator = new Thread(this); // animatorstart(); //, run() /** *, * */ public void run() { while (ThreadcurrentThread() == animator) { //, //, repaint(); // try { Threadsleep(delay); // delay catch (InterruptedException e) { JSTORM <22/135>
Issued by: < > Revision: <10> <2000/8/02> break; /* frame++, */ frame++; /** * HTML, * */ public void stop() { animator = null; // /* public void paint(graphics g), public void update(graphics g),, */ < >,, 2,,, 3, 1), paint() paint() import javaawt*; JSTORM <23/135>
Issued by: < > Revision: <10> <2000/8/02> public class Example4Applet extends javaappletapplet implements Runnable { int frame; int delay; Thread animator; /** * Initialize the applet and compute the delay between frames */ public void init() { String str = getparameter("fps"); int fps = (str!= null)? IntegerparseInt(str) : 10; delay = (fps > 0)? (1000 / fps) : 100; public void start() { animator = new Thread(this); animatorstart(); public void run() { long tm = SystemcurrentTimeMillis(); // while (ThreadcurrentThread() == animator) { repaint(); // delay, try { tm += delay; Threadsleep(Mathmax(0, tm - SystemcurrentTimeMillis())); catch (InterruptedException e) { break; // Advance the frame frame++; public void stop() { animator = null; /** * frame * JSTORM <24/135>
Issued by: < > Revision: <10> <2000/8/02> */ public void paint(graphics g) { Dimension d = size(); // int h = dheight / 2; // 2 for (int x = 0 ; x < dwidth ; x++) { //, int y1 = (int)((10 + Mathsin((x - frame) * 005)) * h); int y2 = (int)((10 + Mathsin((x + frame) * 007)) * h); gdrawline(x, y1, x, y2); < > Example4Appletjava HTML HTML APPLET width, height, <TITLE> 1</TITLE> <center> <H1> </H1> </center> <APPLET code=example4appletclass width=500 height=50> <param name=fps value=10> </applet> <HR> < > Example4Applethtml HTML < 1> JSTORM <25/135>
Issued by: < > Revision: <10> <2000/8/02> < 1> 1,? repaint()! run() while repaint(), paint(), paint() (Threadsleep()), (frame++) repaint(),, run(),? 2) repaint() repaint() repaint() update() update() paint() update(), update(), import javaawt*; public class Example5Applet extends javaappletapplet implements Runnable { int frame; int delay; Thread animator; public void init() { String str = getparameter("fps"); int fps = (str!= null)? IntegerparseInt(str) : 10; delay = (fps > 0)? (1000 / fps) : 100; public void start() { animator = new Thread(this); animatorstart(); JSTORM <26/135>
Issued by: < > Revision: <10> <2000/8/02> public void run() { long tm = SystemcurrentTimeMillis(); while (ThreadcurrentThread() == animator) { repaint(); try { tm += delay; Threadsleep(Mathmax(0, tm - SystemcurrentTimeMillis())); catch (InterruptedException e) { break; frame++; public void stop() { animator = null; /** * update(), update() */ public void paint(graphics g) { update(g); /** * update(), *, * */ public void update(graphics g) { Color bg = getbackground(); // Dimension d = size(); int h = dheight / 2; for (int x = 0 ; x < dwidth ; x++) { int y1 = (int)((10 + Mathsin((x - frame) * 005)) * h); int y2 = (int)((10 + Mathsin((x + frame) * 007)) * h); if (y1 > y2) { // int t = y1; y1 = y2; y2 = t; JSTORM <27/135>
Issued by: < > Revision: <10> <2000/8/02> gsetcolor(bg); // gdrawline(x, 0, x, y1); // gdrawline(x, y2, x, dheight); // gsetcolor(colorblack); // gdrawline(x, y1, x, y2); //, < > Example5Appletjava HTML <TITLE> 2</TITLE> <center> <H1> </H1> </center> <APPLET code=example5appletclass width=500 height=50> <param name=fps value=10> </applet> <HR> < > example5applethtml HTML < 2> < 2> 2 1,? JSTORM <28/135>
Issued by: < > Revision: <10> <2000/8/02> while repaint() repai nt()update() update(), Component update() update(), u pdate() update(), (T hreadsleep()) (frame++) repaint(), while 1,? 3),, 1) (off screen), 2), 3),,, paint()update(), import javaawt*; 1) 2) CPU (cache), public class Example6Applet extends javaappletapplet implements Runnable { int frame; int delay; Thread animator; JSTORM <29/135>
Issued by: < > Revision: <10> <2000/8/02> Dimension offdimension; //, Image offimage; // Image Graphics offgraphics; // Graphics public void init() { String str = getparameter("fps"); int fps = (str!= null)? IntegerparseInt(str) : 10; delay = (fps > 0)? (1000 / fps) : 100; public void start() { animator = new Thread(this); animatorstart(); public void run() { long tm = SystemcurrentTimeMillis(); while (ThreadcurrentThread() == animator) { repaint(); try { tm += delay; Threadsleep(Mathmax(0, tm - SystemcurrentTimeMillis())); catch (InterruptedException e) { break; frame++; public void stop() { animator = null; offimage = null; offgraphics = null; /** *, update() * 1 Image Graphics * 2 * 3 * 4 */ public void update(graphics g) { JSTORM <30/135>
Issued by: < > Revision: <10> <2000/8/02> Dimension d = size(); // Image Graphics if ((offgraphics == null) (dwidth!= offdimensionwidth) (dheight!= offdimensionheight)) { offdimension = d; offimage = createimage(dwidth, dheight); // offgraphics = offimagegetgraphics(); // offgraphicssetcolor(getbackground()); // offgraphicsfillrect(0, 0, dwidth, dheight);// offgraphicssetcolor(colorblack); // // paintframe(offgraphics); // gdrawimage(offimage, 0, 0, null); /** * paint() (,, * ), */ public void paint(graphics g) { if (offimage!= null) { gdrawimage(offimage, 0, 0, null); /** * */ public void paintframe(graphics g) { Dimension d = size(); int h = dheight / 2; for (int x = 0 ; x < dwidth ; x++) { int y1 = (int)((10 + Mathsin((x - frame) * 005)) * h); int y2 = (int)((10 + Mathsin((x + frame) * 007)) * h); gdrawline(x, y1, x, y2); JSTORM <31/135>
Issued by: < > Revision: <10> <2000/8/02> < > Example6Appletjava HTML <TITLE> 3</TITLE> <center> <H1> </H1> </center> <APPLET code=example6appletclass width=500 height=50> <param name=fps value=10> </applet> <HR> < > Example6Applethtml Example5Appletjava, update() paintframe() update() offimage = createimage(dwidth, dheight); I mage Image Graphics offgraphics = offimagegetgraphics(); offimage Image, offgraphics Graphics Image getgra phics() Graphics offgraphics Image offimage Graphics, offimage offgraphicssetcolor(getbackground()); offgraphicsfillrect(0, 0, dwidth, dheight); offgraphicssetcolor(colorblack); offimage paintframe(), off Image offimage offgraphics JSTORM <32/135>
Issued by: < > Revision: <10> <2000/8/02> gdrawimage(offimage, 0, 0, null); offimage (top corner, ) (0, 0) g Graphics, drawimage(image img, int x, i nt y, ImageObserver observer) HTML < 3> < 3> 3, update()paintframe(),, gifjpeg,, < 4>, < 5> < 4> cargif JSTORM <33/135>
Issued by: < > Revision: <10> <2000/8/02> import javaawt*; < 5> worldgif public class Example7Applet extends javaappletapplet implements Runnable { int frame; int delay; Thread animator; Dimension offdimension; Image offimage; Graphics offgraphics; Image world; // Image Image car; // Image /* */ public void init() { String str = getparameter("fps"); int fps = (str!= null)? IntegerparseInt(str) : 10; delay = (fps > 0)? (1000 / fps) : 100; world = getimage(getcodebase(), "worldgif"); //, worldgif car = getimage(getcodebase(), "cargif"); //, cargif public void start() { animator = new Thread(this); animatorstart(); public void run() { long tm = SystemcurrentTimeMillis(); while (ThreadcurrentThread() == animator) { repaint(); try { tm += delay; Threadsleep(Mathmax(0, tm - SystemcurrentTimeMillis())); catch (InterruptedException e) { JSTORM <34/135>
Issued by: < > Revision: <10> <2000/8/02> break; frame++; public void stop() { animator = null; offimage = null; offgraphics = null; public void update(graphics g) { Dimension d = size(); if ((offgraphics == null) (dwidth!= offdimensionwidth) (dheight!= offdimensionheight)) { offdimension = d; offimage = createimage(dwidth, dheight); offgraphics = offimagegetgraphics(); offgraphicssetcolor(getbackground()); offgraphicsfillrect(0, 0, dwidth, dheight); offgraphicssetcolor(colorblack); paintframe(offgraphics); gdrawimage(offimage, 0, 0, null); public void paint(graphics g) { update(g); /** * 2 * Graphics g */ public void paintframe(graphics g) { Dimension d = size(); int w = worldgetwidth(this); // int h = worldgetheight(this); // if ((w > 0) && (h > 0)) { //, JSTORM <35/135>
Issued by: < > Revision: <10> <2000/8/02> gdrawimage(world, (dwidth - w)/2, (dheight - h)/2, this); w = cargetwidth(this); h = cargetheight(this); if ((w > 0) && (h > 0)) { //, w += dwidth; // gdrawimage(car, dwidth - ((frame * 5) % w), (dheight - h)/3, this); // gdrawimage(car, dwidth - ((frame * 7) % w), (dheight - h)/2, this); < > Example7Appletjava 200 <TITLE> 2</TITLE> <center> <H1> </H1> <APPLET code=example7appletclass width=200 height=200> <param name=fps value=10> </applet> </center> <HR> < > Example7Applethtml HTML < 6> JSTORM <36/135>
Issued by: < > Revision: <10> <2000/8/02> < 6> Example6Appletjava, init()paintframe() init() world = getimage(getcodebase(), "worldgif"); car = getimage(getcodebase(), "cargif");, worldgifcargif world, car Image worldgifcargif Image getimage(url url, String name)applet, URL name paintframe() offimage 2 gdrawimage(world, (dwidth - w)/2, (dheight - h)/2, this); gdrawimage(car, dwidth - ((frame * 5) % w), (dheight - h)/3, t his); gdrawimage(car, dwidth - ((frame * 7) % w), (dheight - h)/2, this); 2 x frame run() while repaint(), frame 2, JSTORM <37/135>
Issued by: < > Revision: <10> <2000/8/02>, duke, < 7> 10 < 7> duke10 import javaawt*; import javaapplet*; public class Example8Applet extends javaappletapplet implements Runnable { int frame; int delay; Thread animator; Dimension offdimension; Image offimage; Graphics offgraphics; Image frames[]; // Image public void init() { String str = getparameter("fps"); int fps = (str!= null)? IntegerparseInt(str) : 10; delay = (fps > 0)? (1000 / fps) : 100; frames = new Image[10]; // 10 Image for (int i = 1 ; i <= 10 ; i++) { // Image frames[i-1] = getimage(getcodebase(), "duke/t" + i + "gif"); public void start() { animator = new Thread(this); animatorstart(); public void run() { long tm = SystemcurrentTimeMillis(); while (ThreadcurrentThread() == animator) { JSTORM <38/135>
Issued by: < > Revision: <10> <2000/8/02> repaint(); try { tm += delay; Threadsleep(Mathmax(0, tm - SystemcurrentTimeMillis())); catch (InterruptedException e) { break; frame++; public void stop() { animator = null; offimage = null; offgraphics = null; public void update(graphics g) { Dimension d = size(); if ((offgraphics == null) (dwidth!= offdimensionwidth) (dheight!= offdimensionheight)) { offdimension = d; offimage = createimage(dwidth, dheight); offgraphics = offimagegetgraphics(); offgraphicssetcolor(getbackground()); offgraphicsfillrect(0, 0, dwidth, dheight); offgraphicssetcolor(colorblack); paintframe(offgraphics); gdrawimage(offimage, 0, 0, null); public void paint(graphics g) { update(g); /** * frames, * JSTORM <39/135>
Issued by: < > Revision: <10> <2000/8/02> */ public void paintframe(graphics g) { gdrawimage(frames[frame % 10], 0, 0, null); < > Example8Appletjava HTML T1gif~T10gif 55, 68 (pixel) 55, 68 <TITLE> </TITLE> <center> <H1> </H1> <APPLET code=example8appletclass width=55 height=68> <param name=fps value=10> </applet> </center> <HR> < > Example8Applethtml HTML < 8> < 8> init(), JSTORM <40/135>
Issued by: < > Revision: <10> <2000/8/02> frames = new Image[10]; for (int i = 1 ; i <= 10 ; i++) { frames[i-1] = getimage(getcodebase(), "duke/t" + i + "gif"); 10 frames, getimage duke T1gif T10gif paintframe(), frame s gdrawimage(frames[frame % 10], 0, 0, null); frames frame%10 frames 10, 0 9 frame, frame10 (0 9) frame repaint() 1,, Example7AppletjavaExample8Appletjava,, getimage(), MediaTracker Example8Appletjava, Example8Appletjava public class Example9Applet implements Runnable { MediaTracker tracker; public void init() { tracker = new MediaTracker(this); frames = new Image[10]; for (int i = 1 ; i <= 10 ; i++) { frames[i-1] = getimage(getcodebase(), "duke/t" + i + "gif"); trackeraddimage(frames[i-1], 0); // JSTORM <41/135>
Issued by: < > Revision: <10> <2000/8/02> public void paintframe(graphics g) { //, if (trackerstatusid(0, true) == MediaTrackerCOMPLETE) { gdrawimage(frames[frame % 10], 0, 0, null); < > Example9Appletjava init() tracker = new MediaTracker(this);, trackeraddimage(frames[i-1], 0); 0 MediaTracker addimage(image img, int id) id img paintframe() if (trackerstatusid(0, true) == MediaTrackerCOMPLETE) { gdrawimage(frames[frame % 10], 0, 0, null); trackerstatusid(0, true)0 MediaTracker MediaTracker static COMPLETE, Example9Applet, Exa mple8applet 2 (sun) au 1) javaappletapplet - void play(url sound), void play(url sound, String location) URL, location URL, JSTORM <42/135>
Issued by: < > Revision: <10> <2000/8/02> - AudioClip getaudioclip(url url, String location) url, location Audio Clip 2) javaappletaudioclip getaudioclip, AudioClip play(), stop(), loop() AudioClip clip = getaudioclip(getcodebase(), "audio/loopau"); clipplay(); // loopau clipstop(); // cliploop(); // stop() loop(),, init() getaudioclip(),, 4, import javaawtgraphics; import javaapplet*; public class AudioExample extends Applet implements Runnable { AudioClip bgsound; // AudioClip AudioClip beep; // AudioClip Thread sound_runner; // /** init() */ public void init() { bgsound = getaudioclip(getcodebase(), "loopau"); beep = getaudioclip(getcodebase(), "beepau"); /** */ public void start() { if (sound_runner == null) { sound_runner = new Thread(this); sound_runnerstart(); JSTORM <43/135>
Issued by: < > Revision: <10> <2000/8/02> /**, stop() */ public void stop() { if ( sound_runner!= null) { if (bgsound!= null) bgsoundstop(); sound_runnerstop(); sound_runner = null; public void run() { if (bgsound!= null) bgsoundloop(); while( sound_runner!= null) { try { Threadsleep(4000); catch (InterruptedException e) { if (bgsound!= null) beepplay(); public void paint(graphics g) { gdrawstring("we are playing sounds Let's Listen!", 10, 10); < > AudioExamplejava HTML, <TITLE> </TITLE> <center> <H1> </H1> <APPLET code=audioexampleclass width=100 height=50> </applet> </center> <HR> < > AudioExamplehtml loopaubeepau AudioExamplehtm l, init(), start(), paint(), run() JSTORM <44/135>
Issued by: < > Revision: <10> <2000/8/02> 3,,, MUD, 1 2 3, 4 1, 2 1,,,,,, 2 1), 2),,, " (thing), public class thing { int x, y; //, (x,y) Image picture; // Image JSTORM <45/135>
Issued by: < > Revision: <10> <2000/8/02> int priority; // int velocity; //, boolean visible; //, true // /** */ public thing(image picture) { thispicture = picture; //, Image 2,,, (x,y), (x,y) 2,,,,, *, init(), Enemy public class Enemy { int x, y; //, (x,y) Image picture; // Image int velocity; //, boolean visible; //, true JSTORM <46/135>
Issued by: < > Revision: <10> <2000/8/02> /** */ public Enemy(Image picture) { thispicture = picture; public void fire(int x, int y) // (x,y) { public void move(int x, int y) // (x,y) { Enemy[] ufo; public void init() { ufo = new Enemy[100]; // 100 for ( int i=0; i<100; i++) ufo[i] = Enemy(); // Enemy, Linked List, Linked List List, List *, run(),, run(), public void run() { while (game!=null) // Thread game, { try { Threadsleep(snooze); // catch (InterruptedException e) { JSTORM <47/135>
Issued by: < > Revision: <10> <2000/8/02> switch (gamestate) // { case : (, gameloop() ); break; default: break; repaint(); //, repaint(), 1), public boolean keydown(javaawtevent e,int key) { switch (key) { case : ; break; default: break; public boolean keyup(event e, int key) x,y switch(key) { case 97: ufox -= 2; // A, 2 break; x, y, x JSTORM <48/135>
Issued by: < > Revision: <10> <2000/8/02> 2) public boolean mousedown(event evt, int x, int y) public boolean mouseup(event evt, int x, int y) public boolean mousemove(event evt, int x, int y) public boolean mousedrag(event evt, int x, int y) public boolean mouseenter(event evt, int x, int y) public boolean mo useexit(event evt, int x, int y ) x,y *,, repaint(), rep aint() update() update() public void paint(graphics g) { gdrawimage(offimage,0,0,this); // public void update(graphics g) { int k; switch (gamestate) // { case : //, // offgraphicsdrawimage(, x, y, this); // for (k=0; k< ; k++) offgraphicsdrawimage(, x, y, this); break; default: break; paint(g); // JSTORM <49/135>
Issued by: < > Revision: <10> <2000/8/02> offgraphics Graphics, of fimage ( ), ufothing, ufo[k]i mage x, y ufo[k]x, ufo[k]y update(), Linked List for Linkded List * AudioClip fire_sound; init(),, public void init() { fire_sound = getaudioclip(getcodebase(), "sound/fire_soundau"); public void gameloop() { ufofire(120, 30); // ufo (120, 30) fire_soundplay(); public class extends Applet implements Runnable { ; public void init() { 1 2, Image 3, 4 JSTORM <50/135>
Issued by: < > Revision: <10> <2000/8/02> 5 public void start() { public void run() {, public void paint() { public void update() {,,,,,,,,,,, < 9>1 JSTORM <51/135>
Issued by: < > Revision: <10> <2000/8/02> // Iceblox // By Karl Harnell, April 8 1996 import javaawt*; import javaawtimage*; import javanet*; < 9> (icebloxgif) public class iceblox extends javaappletapplet implements Runnable { int i,j,k; final int playx=390,playy=330,mainx=390,mainy=348,smalls=48,blockx=13,blocky=11; final int animp[]={7,8,9,8,10,11,12,11,4,5,6,5,1,2,3,2; final int animf[]={32,33,34,35,36,35,34,33; final int levflame[]={2,3,4,2,3,4,levrock[]={5,6,7,8,9,10; final int levspeed[]={3,3,3,5,5,5,levice[]={35,33,31,29,27,25; final int effmax=5; int playarea[]; int gamestate,counter,dir,infront,infront2,level,coins; int efflevel,lives=3; int x[],y[],dx[],dy[],motion[],look[],creature[],ccount[],actors,flames; int sideix[]={0,-1,1,-15,15,coordx[]={0,-30,30,0,0,coordy[]={0,0,0,-30,30; Image collection,offimage,playfield,small[],title; Graphics offgraphics,playgraphics,tempg; MediaTracker tracker; ImageFilter filter; ImageProducer collectionproducer; long snooze=100,score; Thread game; Math m; /**, Image */ public void init() JSTORM <52/135>
Issued by: < > Revision: <10> <2000/8/02> { setbackground(colorblack); offimage=createimage(mainx,mainy); offgraphics=offimagegetgraphics(); offgraphicssetcolor(colorblack); offgraphicsfillrect(0,0,mainx,mainy); playfield=createimage(playx,playy); playgraphics=playfieldgetgraphics(); playgraphicssetcolor(colorblack); tracker=new MediaTracker(this); collection = getimage(getcodebase(),"icebloxgif"); trackeraddimage(collection,0); try { trackerwaitforid(0); catch(interruptedexception e) { collectionproducer=collectiongetsource(); small=new Image[smalls]; k=0;i=0;j=0; while (k<smalls) { filter=new CropImageFilter(j*30,i*30,30,30); small[k]=createimage(new FilteredImageSource( collectionproducer,filter)); trackeraddimage(small[k],1); k++; j++; if (j==8) { j=0; i++; filter=new CropImageFilter(0,180,224,64); title=createimage(new FilteredImageSource( collectionproducer,filter)); trackeraddimage(title,1); playarea=new int[(blockx+2)*(blocky+3)]; x=new int[20]; y=new int[20]; dx=new int[20]; dy=new int[20]; look=new int[20]; motion=new int[20]; creature=new int[20]; ccount=new int[20]; JSTORM <53/135>
Issued by: < > Revision: <10> <2000/8/02> gamestate=7; try { trackerwaitforid(1); catch(interruptedexception e) { resize(mainx,mainy); /** */ public void run() { while (game!=null) { try { gamesleep(snooze); catch (InterruptedException e) { counter=(counter+1)&255; switch (gamestate) { case 0: preparefield(); break; case 1: showfield(); break; case 2: gameloop(); // break; case 3: happypenguin(); break; case 4: clearfield(); break; case 5: fixdeath(); break; case 6: gameover(); break; case 7: drawintro1(); break; case 8: JSTORM <54/135>
Issued by: < > Revision: <10> <2000/8/02> waitintro1(); break; case 9: drawintro2(); break; case 10: waitintro2(); break; case 11: drawintro3(); break; case 12: waitintro3(); break; default: break; repaint(); public void start() { if (game==null) { game=new Thread(this); gamestart(); public void stop() { if ((game!=null)&&(gameisalive())) { gamestop(); game=null; public boolean keydown(javaawtevent e,int key) { if (gamestate==2) { switch (key) { case 97: dir=1; // A break; case 100: dir=2; // D JSTORM <55/135>
Issued by: < > Revision: <10> <2000/8/02> break; case 107: dir=3; // K break; case 109: dir=4; // M break; default: break; else if ((gamestate>6)&&(key==32)) gamestate=0; return false; public boolean keyup(javaawtevent e,int key) { dir=0; return false; /**,, */ public void preparefield() { int i,j,p,q; if (level>effmax) efflevel=effmax; else efflevel=level; offgraphicssetcolor(colorblack); offgraphicsfillrect(0,0,mainx,mainy); playgraphicssetcolor(colorblack); playgraphicsfillrect(0,0,playx,playy); offgraphicssetcolor(colorlightgray); offgraphicsfill3drect(0,mainy-playy-4,mainx,4,true); offgraphicssetcolor(colorwhite); offgraphicsdrawstring("score:",2,12); updatescore(0); offgraphicsdrawstring("level: "+(level+1),125,12); offgraphicsdrawstring("spare LIVES:",220,12); for (i=0;i<lives;i++) offgraphicsdrawimage(small[13],300+i*15,-16,this); for (i=0;i<(blockx+2)*(blocky+3);i++) playarea[i]=1; for (i=1;i<=blocky;i++) for (j=1;j<=blockx;j++) JSTORM <56/135>
Issued by: < > Revision: <10> <2000/8/02> playarea[i*(blockx+2)+j]=0; playarea[blockx+3]=1; i=0; while (i<levice[efflevel]) // { p=1+(int)(mrandom()*blockx); q=1+(int)(mrandom()*blocky); if (playarea[q*(blockx+2)+p]==0) { playarea[q*(blockx+2)+p]=2; playgraphicsdrawimage(small[16],(p-1)*30,(q-1)*30,this); i++; i=0; while (i<levrock[efflevel]) // { p=1+(int)(mrandom()*blockx); q=1+(int)(mrandom()*blocky); if (playarea[q*(blockx+2)+p]==0) { playarea[q*(blockx+2)+p]=1; playgraphicsdrawimage(small[14],(p-1)*30,(q-1)*30,this); i++; i=0; while (i<5) // { p=1+(int)(mrandom()*blockx); q=1+(int)(mrandom()*blocky); if (playarea[q*(blockx+2)+p]==0) { playarea[q*(blockx+2)+p]=10; playgraphicsdrawimage(small[24],(p-1)*30,(q-1)*30,this); i++; playarea[blockx+3]=0; // Clear start square gamestate=1; snooze=100; counter=0; motion[0]=0; actors=1; coins=0; flames=0; look[0]=0; JSTORM <57/135>
Issued by: < > Revision: <10> <2000/8/02> x[0]=30; y[0]=30; dx[0]=6; dy[0]=6; look[0]=2; creature[0]=1; for (i=0;i<20;i++) ccount[i]=0; public void showfield() { Graphics savegraphics; savegraphics=offgraphicscreate(); offgraphicscliprect(playx/2-(counter*playx/2/30),mainy-playy+ playy/2-(counter*playy/2/30),counter*playx/30,counter*playy/30); offgraphicsdrawimage(playfield,0,mainy-playy,this); if (counter==30) { gamestate=2; snooze=100; offgraphics=savegraphics; /** */ public void gameloop() { if (flames<levflame[efflevel]) { if (x[0]<(playx/2)) x[actors]=playx+30; else x[actors]=0; y[actors]=30*(1+(int)(mrandom()*blocky)); j=(y[actors]/30)*(blockx+2)+x[actors]/30; motion[actors]=0; dx[actors]=levspeed[efflevel]; dy[actors]=levspeed[efflevel]; creature[actors]=4; if ((playarea[j+1]==0) (playarea[j-1]==0)) { actors++; flames++; for (i=0;i<actors;i++) { JSTORM <58/135>
Issued by: < > Revision: <10> <2000/8/02> ccount[i]++; switch(motion[i]) { case 1: x[i]-=dx[i]; break; case 2: x[i]+=dx[i]; break; case 3: y[i]-=dy[i]; break; case 4: y[i]+=dy[i]; break; default: break; j=(y[i]/30)*(blockx+2)+x[i]/30; switch(creature[i]) { case 1: // if ((x[i]%30 == 0)&&(y[i]%30 == 0)) motion[i]=0; if (motion[i]==0) { infront=playarea[j+sideix[dir]]; if ((j+2*sideix[dir])<0) infront2=1; else infront2=playarea[j+2*sideix[dir]]; if (infront==0) motion[i]=dir; else { if ((infront2==0)&&((infront==2) (infront==10))) //? { if (infront==2) { creature[actors]=2; look[actors]=16; else JSTORM <59/135>
Issued by: < > Revision: <10> <2000/8/02> { creature[actors]=3; look[actors]=24; x[actors]=x[i]+coordx[dir]; y[actors]=y[i]+coordy[dir]; dx[actors]=15; dy[actors]=15; playgraphicsfillrect(x[actors]-30,y[actors]-30,30,30); motion[actors]=dir; actors++; playarea[j+sideix[dir]]=0; else if ((infront>1)&&(infront<18)) // Crack ice { playarea[j+sideix[dir]]++; if (infront==9) // All cracked? { playgraphicsfillrect(x[i]+coordx[dir]-30,y[i]+coordy[dir]-30,30,30); playarea[j+sideix[dir]]=0; updatescore(5); else if (infront==17) { playgraphicsfillrect(x[i]+coordx[dir]-30,y[i]+coordy[dir]-30,30,30); playarea[j+sideix[dir]]=0; updatescore(100); coins++; else JSTORM <60/135>
Issued by: < > Revision: <10> <2000/8/02> playgraphicsdrawimage(small[infront+15],x[i]+coordx[dir]-30,y[i]+coordy[dir]-30,this); if (motion[i]!=0) look[i]=animp[(motion[i]-1)*4+counter%4]; for (k=1;k<actors;k++) if (creature[k]==4) if (((x[k]-x[i])<20)&&((x[i]- x[k])<20)&&((y[k]-y[i])<20)&&((y[i]-y[k])<20)) { creature[k]=6; x[k]=0; y[k]=0; motion[k]=0; ccount[i]=0; dx[i]=0; dy[i]=0; creature[i]=7; break; case 2: // if ((x[i]%30 == 0)&&(y[i]%30 == 0)&&(playArea[j+sideIX[motion[i]]]!=0)) { playarea[j]=2; playgraphicsdrawimage(small[16],x[i]- 30,y[i]-30,this); removeactor(i); break; case 3: // if ((x[i]%30 == 0)&&(y[i]%30 == 0)&&(playArea[j+sideIX[motion[i]]]!=0)) { playarea[j]=10; playgraphicsdrawimage(small[24],x[i]- 30,y[i]-30,this); removeactor(i); break; case 4: // look[i]=animf[counter%8]; if (motion[i]==0) motion[i]=(int)(1+mrandom()*4); if ((x[i]%30 == 0)&&(y[i]%30 == 0)) // JSTORM <61/135>
Issued by: < > Revision: <10> <2000/8/02> { if (((x[i]-x[0])<3)&&((x[0]-x[i])<3)) { if (y[i]>y[0]) motion[i]=3; else motion[i]=4; else if (((y[i]-y[0])<3)&&((y[0]-y[i])<3)) { if (x[i]>x[0]) motion[i]=1; else motion[i]=2; if (playarea[j+sideix[motion[i]]]!=0) motion[i]=0; for (k=1;k<actors;k++) //? if ((creature[k]&254)==2) if // (((x[k]- x[i])<30)&&((x[i]-x[k])<30)&&((y[k]-y[i])<30)&&((y[i]-y[k])<30)) { creature[i]=5; k=actors; look[i]=37; motion[i]=0; ccount[i]=0; updatescore(50); break; case 5: // "50" look[i]=37+(counter&1); if (ccount[i]>20) { flames --; removeactor(i); break; case 6: // break; case 7: //, if (ccount[i]<8) look[i]=39+ccount[i]; else if (ccount[i]<30) look[i]=47; JSTORM <62/135>
Issued by: < > Revision: <10> <2000/8/02> else { lives--; if (lives<0) gamestate=5; else { actors=1; flames=0; counter=0; dx[i]=6; dy[i]=6; creature[0]=1; look[0]=2; offgraphicssetcolor(colorblack); offgraphicsfillrect(300,0,45,14); for (k=0;k<lives;k++) offgraphicsdrawimage(small[13],300+k*15,-16,this); break; default: break; if (coins>4) { gamestate=3; updatescore(1000); counter=0; coins=0; offgraphicsdrawimage(playfield,0,mainy-playy,this); public void happypenguin() { if (counter>35) { level++; gamestate=4; counter=0; public void clearfield() { JSTORM <63/135>
Issued by: < > Revision: <10> <2000/8/02> offgraphicssetcolor(colorblack); offgraphicsfillrect(playx/2-(playx*counter/30),mainy-playy/2-(playy*counter/30), playx*counter/15,playy*counter/15); if (counter>14) gamestate=0; public void fixdeath() { offgraphicssetcolor(colorblack); offgraphicsfillrect(0,0,mainx,mainy); offgraphicssetcolor(colorwhite); offgraphicsdrawstring("game OVER",175,100); offgraphicsdrawstring("you scored "+score,160,130); offgraphicsdrawimage(small[2],190,150,this); counter=0; gamestate=6; public void gameover() { if (counter>80) gamestate=7; public void drawintro1() { level=0; score=0; lives=3; offgraphicssetcolor(colorblack); offgraphicsfillrect(0,0,mainx,mainy); offgraphicssetcolor(colorwhite); offgraphicsdrawimage(title,(mainx-224)/2,10,this); offgraphicsdrawstring("actors AND OBJECTS",145,97); offgraphicsdrawimage(small[2],140,110,this); offgraphicsdrawstring("pixel Pete, the penguin",180,130); offgraphicsdrawimage(small[34],120,150,this); offgraphicsdrawimage(small[32],140,150,this); offgraphicsdrawstring("evil flames",180,170); offgraphicsdrawimage(small[16],140,190,this); offgraphicsdrawstring("ice cube",180,210); offgraphicsdrawimage(small[14],140,230,this); offgraphicsdrawstring("solid rock",180,250); offgraphicsdrawimage(small[24],140,270,this); offgraphicsdrawstring("frozen gold coin",180,290); offgraphicsdrawstring("press SPACE to start",138,330); counter=0; gamestate=8; JSTORM <64/135>
Issued by: < > Revision: <10> <2000/8/02> public void waitintro1() { offgraphicssetcolor(colorblack); offgraphicsfillrect(120,150,50,30); offgraphicsdrawimage(small[animf[(counter+2)&7]],120,150,this); offgraphicsdrawimage(small[animf[counter&7]],140,150,this); if (counter>70) gamestate=9; public void drawintro2() { offgraphicssetcolor(colorblack); offgraphicsfillrect(0,75,mainx,230); offgraphicssetcolor(colorwhite); offgraphicsdrawstring("how TO PLAY",165,97); offgraphicsdrawimage(small[2],140,110,this); offgraphicsdrawstring("move up, down, left and right",180,122); offgraphicsdrawstring("with the K, M, A and D keys",180,137); offgraphicsdrawimage(small[10],70,150,this); offgraphicsdrawimage(small[16],140,150,this); offgraphicsdrawstring("walk against ice cubes",180,162); offgraphicsdrawstring("to move them out of the way",180,177); offgraphicsdrawline(110,160,136,160); offgraphicsdrawline(116,169,136,169); offgraphicsdrawimage(small[10],80,190,this); offgraphicsdrawimage(small[18],110,190,this); offgraphicsdrawimage(small[16],140,190,this); offgraphicsdrawstring("walk against blocked",180,202); offgraphicsdrawstring("ice cubes to crack them",180,217); offgraphicsdrawimage(small[28],110,230,this); offgraphicsdrawimage(small[9],140,230,this); offgraphicsdrawstring("free the gold coins by",180,242); offgraphicsdrawstring("crushing the ice around them",180,257); offgraphicsdrawimage(small[9],80,270,this); offgraphicsdrawimage(small[32],140,270,this); offgraphicsdrawline(110,280,126,280); offgraphicsdrawline(110,289,130,289); offgraphicsdrawstring("and watch out",180,282); offgraphicsdrawstring("for the flames",180,297); gamestate=10; counter=0; public void waitintro2() { offgraphicssetcolor(colorblack); offgraphicsdrawimage(small[1+(counter % 12)],140,110,this); offgraphicsfillrect(140,270,30,30); JSTORM <65/135>
Issued by: < > Revision: <10> <2000/8/02> offgraphicsdrawimage(small[animf[counter&7]],140,270,this); if (counter>80) gamestate=11; public void drawintro3() { offgraphicssetcolor(colorblack); offgraphicsfillrect(0,75,mainx,230); offgraphicssetcolor(colorwhite); offgraphicsdrawstring("scoring",180,97); offgraphicsdrawimage(small[10],110,110,this); offgraphicsdrawimage(small[18],140,110,this); offgraphicsdrawstring("breaking ice,",180,122); offgraphicsdrawstring("5 points",180,137); offgraphicsdrawimage(small[33],60,150,this); offgraphicsdrawimage(small[16],80,150,this); offgraphicsdrawimage(small[9],140,150,this); offgraphicsdrawline(112,160,126,160); offgraphicsdrawline(112,169,130,169); offgraphicsdrawstring("putting out flame",180,162); offgraphicsdrawstring("with ice, 50 points",180,177); offgraphicsdrawimage(small[10],110,190,this); offgraphicsdrawimage(small[27],140,190,this); offgraphicsdrawstring("freeing coin,",180,202); offgraphicsdrawstring("100 points",180,217); for (j=0;j<5;j++) offgraphicsdrawimage(small[15],100-9*j,230,this); offgraphicsdrawimage(small[39],140,230,this); offgraphicsdrawstring("taking all coins and advancing",180,242); offgraphicsdrawstring("to next level, 1000 points",180,257); gamestate=12; counter=0; public void waitintro3() { offgraphicssetcolor(colorblack); offgraphicsfillrect(60,150,20,30); offgraphicsdrawimage(small[animf[counter&7]],60,150,this); offgraphicsdrawimage(small[16],80,150,this); if (counter>70) gamestate=7; public void removeactor(int i) { int j; for (j=i;j<actors;j++) { JSTORM <66/135>
Issued by: < > Revision: <10> <2000/8/02> x[j]=x[j+1]; y[j]=y[j+1]; dx[j]=dx[j+1]; dy[j]=dy[j+1]; look[j]=look[j+1]; motion[j]=motion[j+1]; creature[j]=creature[j+1]; actors--; public void updatescore(long i) { score+=i; offgraphicssetcolor(colorblack); offgraphicsfillrect(50,0,60,12); offgraphicssetcolor(colorwhite); offgraphicsdrawstring(stringvalueof(score),50,12); public void paint(graphics g) { gdrawimage(offimage,0,0,this); public void update(graphics g) { int k; switch (gamestate) { case 2: // offgraphicsdrawimage(playfield,0,mainy-playy,this); for (k=0;k<actors;k++) offgraphicsdrawimage(small[look[k]],x[k]-30,y[k]- 30+mainY-playY,this); break; case 3: offgraphicsdrawimage(small[39*(counter&1)],x[0]-30,y[0]- 30+mainY-playY,this); break; default: break; paint(g); < > Icebloxjava HTML JSTORM <67/135>
Issued by: < > Revision: <10> <2000/8/02> <HTML> <HEAD> <TITLE> </TITLE> </HEAD> <body bgcolor=ffffff> <center> <h2> </h2> < > <APPLET CODE="icebloxclass" width=350 height=390> </APPLET> </center> </BODY> </HTML> < > Icebloxhtml, 3, < 10> JSTORM <68/135>
Issued by: < > Revision: <10> <2000/8/02> < 11> < 12>, < 13> JSTORM <69/135>
Issued by: < > Revision: <10> <2000/8/02> < 13> *,,, javaawtimage < 14> (30, 40), 30 < 14> JSTORM <70/135>
Issued by: < > Revision: <10> <2000/8/02> Image collection; // ImageFilter filter; ImageProducer collectionproducer; Image part; // collection public void init() { collection = getimage(getcodebase(),"icebloxgif"); // collectionproducer=collectiongetsource(); // ImageProducer filter=new CropImageFilter(30, 40, 30, 30); // (30,40), 30 part = createimage(new FilteredImageSource(collectionProducer,filter)); // *,,?, < 15> < 15> (xa1<(xb1+xbsx)) and (xb1<(xa1+xasx)) and (ya1<(yb1+ybsy)) and (yb1<(ya1+yasy)),,, JSTORM <71/135>
Issued by: < > Revision: <10> <2000/8/02>, JSTORM <72/135>
Issued by: < > Revision: <10> <2000/8/02> 4, javanet, U RL Socket, ServerSocket, DatagramSocket Java 10X 1 URL URL < 1> URL(Uniform Resource Locator) (resource) < 1> URL URL URL, 1) URL(String url) URL selab = new URL("http://objectcsecauackr"); - selab, http://objectcsecauackr URL 2) URL(URL baseurl, String relativeurl) URL, seintro =new URL(selab, introhtml) ; -"http://objectcsecauackr/introhtml" URL seintro JSTORM <73/135>
Issued by: < > Revision: <10> <2000/8/02> URL CGI, http://objectcsecauackr" URL import javanet*; import javaio*; class URLInput { public static void main( String args[]) { try { URL selab = new URL("http://objectcsecauackr/"); DataInputStream in_stream; // URL String inputline; // URL String in_stream = new DataInputStream(selabopenStream()); while ((inputline = in_streamreadline())!= null) { Systemoutprintln(inputLine) ; // in_streamclose(); // catch (MalformedURLException me) { Systemoutprintln("MalformedURLException: " + me); catch (IOException ioe) { Systemoutprintln("IOException: "+ioe); < > URLInputjava "java URLInput" in_stream = new DataInputStream(selabopenStream()); URL openstream() URL, DataInputStream, DataInputStream URL while ((inputline = in_streamreadline())!= null) { JSTORM <74/135>
Issued by: < > Revision: <10> <2000/8/02> http://objectcsecauackr" (examcokr), CGI (enter) CGI "Success", Failure" CGI, CGI? import javaio* ; import javanet* ; public class Success { public static void main(string args[]) { try{ if (argslength!= 1) { // Systemerrprintln("Usage: java Success seat_number"); Systemexit (1); String seat_num = URLEncoderencode(args[0]); // (encoding) URL url = new URL("http://examcokr/cgi-bin/enter"); // CGI URL URLConnection connection = urlopenconnection(); PrintStream outstream = new PrintStream(connectiongetOutputStream()); DataInputStream instream; String inputline; outstreamprintln(seat_num); outstreamclose(); instream = new DataInputStream(connectiongetInputStream()); while ((inputline = instreamreadline())!= null) { Systemoutprintln(inputLine) ; // CGI instreamclose(); catch (MalformedURLException me) { Systemerrprintln("MalformedURLExceprion: " + me); catch (IOException ioe) { Systemerrprintln("IOException: " + ioe); < > Successjava JSTORM <75/135>
Issued by: < > Revision: <10> <2000/8/02> "java Success examcokr cg i-bin/enter CGI, String seat_num = URLEncoderencode(args[0]); URLEncoder (static) encode(string str)str x-www-formurlencoded" MIME CGI x-www-form-urlencoded", CGI URL, URLConnection connection = urlopenconnection(); PrintStream outstream = new PrintStream(connectiongetOutputStream()); URL, PrintStream PrintStream outstream, outstream outstreamprintln(seat_num); (seat_num) URL, CGI, CGI instream = n ew DataInputStream(connectiongetInputStream()); while ((inputline = instreamreadline())!= null) { Systemoutprintln(inputLine) ; instream, instreamreadline() CGI DataInputStream, PrintStream, CGI 1 CGI URL URL url = new URL("http://examcokr/cgi-bin/enter"); URLConnection connection = urlopenconnection(); 2 URL (Stream) PrintStream outstream = new PrintStream(connectiongetOutputStream()); DataInputStream instream = new DataInputStream(connectiongetInputStream()); 3, CGI outstreamprintln(seat_num); JSTORM <76/135>
Issued by: < > Revision: <10> <2000/8/02> 4 CGI, instream = new DataInputStream(connectiongetInputStream()); while ((inputline = instreamreadline())!= null) { Systemoutprintln(inputLine) ; 5 outstreamclose(); instreamclose(); 2 / URL, (Socket),,,,,, javanet Socket, ServerSocket, DatagramSocket TCPUDP, 2, UDP TCP, / /,,,, 2,,,, / 3, 1 / JSTORM <77/135>
Issued by: < > Revision: <10> <2000/8/02> < 1> /, ( ), 2 / < 2> / ( ),,, MUD 3 /,, DB, DB JSTORM <78/135>
Issued by: < > Revision: <10> <2000/8/02> < 3> / 1, 2 < 4> / < 4> /, 1, Socket echosocket = new Socket(, ); 2, PrintStream os = new PrintStream(echoSocketgetOutputStream());, OutputStream, JSTORM <79/135>
Issued by: < > Revision: <10> <2000/8/02> 3 osprintln( ); 4, DataInputStream is = new DataInputStream(echoSocketgetInputStream()); 5 String in_string = isreadline(); 6, osclose(); isclose(); echosocketclose();,,, l ServerSocket serversocket = new ServerSocket( ); - Socket clientsocket = serversocketaccept(); -, ServerSocketaccept() 2, DataInputStream is = new DataInputStream(clientSocketgetInputStream()) ; 3 String in_str = isreadline(); 4, PrintStream os = new PrintStream(clientSocketgetOutputStream()); 5 osprintln( ); 6, JSTORM <80/135>
Issued by: < > Revision: <10> <2000/8/02> isclose() ; osclose(); clientsocketclose(); serversocketclose();,, Data InputStream, PrintStream, BufferedInputStream, 3 BufferedInputStream = new BufferedInputStream(clientSocketgetInputStream()) ; /! < 1> /,,, import javaapplet*; import javaawt*; import javaio*; import javanet*; import javalang*; public class nut_client extends Applet { int PORT = 9878; // Socket c_socket; DataInputStream in; PrintStream out; TextField inputfield; // TextArea outputarea; // StreamListener listener; // public void init() { try { // c_socket = new Socket(thisgetCodeBase()getHost(), PORT); JSTORM <81/135>
Issued by: < > Revision: <10> <2000/8/02> Systemoutprintln("Client! make socket successfully"); in = new DataInputStream(c_socketgetInputStream()); out = new PrintStream(c_socketgetOutputStream()); Systemoutprintln("Client! make stream successfully!"); inputfield = new TextField(); outputarea = new TextArea(); outputareaseteditable(false); // thissetlayout(new BorderLayout()); thisadd("north", inputfield); thisadd("center", outputarea); listener = new StreamListener(in, outputarea); // thisshowstatus("connected to "+c_socketgetinetaddress()gethostname()+" : "+c_socketgetport()); catch (IOException e){ thisshowstatus(etostring()); /** GUI */ public boolean action(event e, Object what) { if (etarget == inputfield) { //, Enter outprintln((string)earg); //, inputfieldsettext(""); // return true; return false; /** */ class StreamListener extends Thread { DataInputStream in; TextArea output; /* */ public StreamListener(DataInputStream in, TextArea output) { Systemoutprintln("Client! enter in StreamListener"); thisin = in; thisoutput = output; thisstart(); // public void run() { // String line; JSTORM <82/135>
Issued by: < > Revision: <10> <2000/8/02> Systemoutprintln("enter in run()"); try { for ( ; ; ) { line = inreadline(); // Systemoutprintln("Client! line : "+line); if (line == null) break; outputsettext(line); // catch (IOException e){ outputsettext(etostring()); outputsettext("connection closed by server"); < > nut_clientjava HTML <HTML> <HEAD> <TITLE> Socket Test </TITLE> </HEAD> <APPLET CODE="nut_clientclass" WIDTH=300 HEIGHT=300> </APPLET> </BODY> </HTML>, < 5> JSTORM <83/135>
Issued by: < > Revision: <10> <2000/8/02> < 5> < 6>,, c_socket = new Socket(thisgetCodeBase()getHost(), PORT); thisgetcodebase()gethost() g JSTORM <84/135>
Issued by: < > Revision: <10> <2000/8/02> etcodebase() URL, URL /, GUI, action() action() Enter, java nut_server &"(& ) import javaio*; import javanet*; import javalang*; public class nut_server extends Thread { int PORT = 9878; // ServerSocket s_socket; public static void main(string[] args) { int port=0; new nut_server(port); // public nut_server(int port) { if (port == 0) port = PORT; try { s_socket = new ServerSocket(port); // ServerSocket Systemoutprintln("open server socket successfully!"); catch (IOException e) { error_handling(e, "fail to open server socket") ; Systemoutprintln("Server : listening on port "+port); thisstart(); // public void run() { // JSTORM <85/135>
Issued by: < > Revision: <10> <2000/8/02> try { while (true) { // // Socket c_socket = s_socketaccept(); Systemoutprintln("accept client socket successfully!"); Connection c = new Connection(c_socket); // catch (IOException e) {error_handling(e, "fail in accepting a client") ; // error handling routine public static void error_handling(ioexception e, String msg) { Systemerrprintln(msg+" : "+e); Systemexit(1); /**, * */ class Connection extends Thread { Socket client=null; DataInputStream in=null; PrintStream out=null; public Connection(Socket c_socket) { client = c_socket; try { // in = new DataInputStream(clientgetInputStream()); out = new PrintStream(clientgetOutputStream()); Systemoutprintln("make data stream successfully"); catch (IOException e) { try { clientclose(); Systemoutprintln("close the client socket successfully"); c atch (IOException e1) {error_handling(e1, "fail in closing client socket"); error_handling(e, "fail in getting socket streams"); thisstart(); // JSTORM <86/135>
Issued by: < > Revision: <10> <2000/8/02> public void run() { String line; StringBuffer revline; int len; try { for ( ; ; ) { line = inreadline(); // Systemoutprintln("line : "+line); if (line == null) break; len = linelength(); Systemoutprintln("the length of this string : "+len); revline = new StringBuffer(len); for (int i=len-1; i>=0; i--) // revlineinsert(len-1-i, linecharat(i)); outprintln(revline); // Systemoutprintln("revline : "+revline); catch (IOException e) {error_handling(e, "line input or output error"); try{ clientclose(); catch (IOException e) { error_handling(e, "finally fail in closing client socket"); // error handling routine public static void error_handling(ioexception e, String msg) { Systemerrprintln(msg+" : "+e); Systemexit(1); < > nut_serverjava "java nut_server &", 100,, Connection JSTORM <87/135>
Issued by: < > Revision: <10> <2000/8/02> while (true) { Socket c_socket = s_socketaccept(); Systemoutprintln("accept client socket successfully!"); Connection c = new Connection(c_socket); //,, Connection while, Connection run(), ( ), "Connect" Log Out" import javaawt*; import javaappletapplet; import javanet*; import javaio*; public class Client extends Applet implements Runnable { boolean is_connected = false; TextField textfield; TextArea textarea; // TextField name; // Socket to_server; DataInputStream is; PrintStream os; Thread thread; Label name_box; Label input_box; Label users; TextArea user_list; // Button quit; // JSTORM <88/135>
Issued by: < > Revision: <10> <2000/8/02> Button connect; // public void init() { setbackground(colorlightgray); setfont(new Font("Helvetica", FontPLAIN, 12)); textfield = new TextField(55); textarea = new Text Area(10, 55); user_list = new TextArea(10,30); textareaseteditable(false); user_listseteditable(false); name = new TextField(25); quit = new Button("Log Out"); connect = new Button ("Connect"); name_box = new Label("Your name is: ",LabelLEFT); input_box = new Label("Type your text on the line below",labelleft); users = new Label("These are the people online: "); // add(name_box); add(name); add(connect); add(quit); add(textarea); add(input_box); add(textfield); add(users); add(user_list); validate(); public void start(){ thread = new Thread(this,"main"); threadstart(); public void run(){ try{ textareaappendtext("hit the connect button to start\n"); while (true){ try{threadsleep(300);catch(interruptedexception e){ if (!is_connected is == null os == null) //, continue; // if (isavailable() > 0 ){ //, String text = isreadline() + '\n'; // text if (textstartswith("##names##")) // JSTORM <89/135>
Issued by: < > Revision: <10> <2000/8/02> write_list(textsubstring(9)); // else textareaappendtext(text);//, catch(ioexception e){ /** */ public void write_list(string list){ int i; int next; user_listsettext (""); // for (i=0;i<listlength();i++){ // next = listindexof(' ',i); // if (next >= listlength() next == -1) break; user_listappendtext(listsubstring(i,next)+'\n'); // i = next; // /**, */ public boolean handleevent(event evt) { if (!is_connected && evtid == EventACTION_EVENT){// GUI, textareaappendtext("hit the connect button to connect\n"); if(evttarget==name ){ // name, String text=namegettext(); textareaappendtext("trying to connect\n"); try{ try{ to_server = new Socket(getCodeBase()getHost(),4444); catch(unknownhostexception e){ textareaappendtext("not able to connect, sorry\n"); return superhandleevent(evt); false); is = new DataInputStream(new BufferedInputStream(to_servergetInputStream())); os = new PrintStream (new BufferedOutputStream(to_servergetOutputStream(),1024), catch(ioexception e){ is_connected = true; //make a connection osprintln("##name##" + text); osflush(); textareaappendtext("\nyour name is '"+text+"' right now \n"); JSTORM <90/135>
Issued by: < > Revision: <10> <2000/8/02> // GUI if (evtid==eventaction_event&&is_connected){ if (os == null is == null){ textareaappendtext("an error has occured\n"); return superhandleevent(evt); if (evttarget == textfield){ // String text = textfieldgettext(); textfieldsettext(""); osprintln(text); // osflush(); if (evttarget == quit && is_connected){ // textareaappendtext("preparing to log off\n"); if (os == null is == null){ textareaappendtext("an error has occured Not logged on\n"); return superhandleevent(evt); osprintln("##quit##"); osflush(); try{ if (os!= null) osclose(); if (is!= null) isclose(); if (to_server!= null) to_serverclose(); catch(ioexception e){textareaappendtext("error loggin off\n"); textareaappendtext("sucessfully logged off\n"); user_listsettext(""); //clear the user list is_connected = false; //no longer connected if (evttarget == connect &&!is_connected){ //, String text=namegettext(); int len = textlength(); if(len!= 0 ) { textareaappendtext("trying to connect\n"); try{ try{ to_server = new Socket(getCodeBase()getHost(),4444); catch(unknownhostexception e){ textareaappendtext("not able to connect, sorry\n"); JSTORM <91/135>
Issued by: < > Revision: <10> <2000/8/02> return superhandleevent(evt); is = new DataInputStream(new BufferedInputStream(to_servergetInputStream())); os = new PrintStream (new BufferedOutputStream(to_servergetOutputStream(),1024), false); catch(ioexception e){ is_connected = true; // return superhandleevent(evt); osprintln("##name##" + text); osflush(); textareaappendtext("\nyour name is '"+text+"' right now \n"); /*, */ public void stop(){ textareaappendtext("preparing to log off\n"); if (os!= null){ osprintln("##quit##"); osflush(); try{ if (os!= null) osclose(); if (is!= null) isclose(); if (to_server!= null) to_serverclose(); catch(ioexception e){textareaappendtext("error loggin off\n"); textareaappendtext("sucessfully logged off\n"); user_listsettext(""); // is_connected = false; // < > Clientjava HTML <html> <applet code = "Clientclass", width = 500 height = 500> </applet> </html> JSTORM <92/135>
Issued by: < > Revision: <10> <2000/8/02> < > Clienthtml HTML, < 6> < 6> "kck", "kjs" hahaha" handleevent GUI action(), GUI,, import javanet*; import javaio*; import javalang*; class Server{ JSTORM <93/135>
Issued by: < > Revision: <10> <2000/8/02> static int users = 0; // static socket_stuff clients[] = new socket_stuff[29]; // 29 public static void main(string args[]) { ServerSocket serversocket = null; int i; try { serversocket = new ServerSocket(4444); catch (IOException e) { Systemoutprintln("Could not listen on port: " + 4444 + ", " + e); Systemexit(1); Socket clientsocket = null; connection user = new connection(serversocket); if (users == 0){ //, try { clientsocket = serversocketaccept(); catch (IOException e) { //Systemoutprintln("Accept failed: " + 4444 + ", " + e); Systemexit(1); add_client(new socket_stuff(clientsocket)); // String inputline,outputline; // String userstart(); // connection try { inputline = "Greetings user"; i = users; // int test; boolean flag = true; while (users >= 0) { // 1 if (users>0 && i<=users ){ test = clients[i]can_read(); if (test == -1){ //, remove_client(i); // else if (test == 1){ //, inputline = clients[i]read_string(); // flag = process_line(inputline,i); // if (flag){ // if (clients[i]!= null) JSTORM <94/135>
Issued by: < > Revision: <10> <2000/8/02> write_all(clients[i]name+": "+inputline); // // 2, try{ userjoin(2); catch(interruptedexception e) { if (userconnected() == true){ //, add_client(new socket_stuff(userget_socket())); // userresume(); // i++; if (i>users && users>=1) // i=1; if (i>users && users<1) i=0; serversocketclose(); catch(ioexception e){ /** */ static void send_names(){ //sends the name list to every body String names = new String("##names##"); // int i; if (users < 1) //, return; for (i=1;i<=users;i++) // if (clients [i]!= null) //if everthing is in order names = names + clients[i]name + " "; // write_all(names); // /**,, * Log out" */ static boolean process_line (String line,int i){ //false if don't echo line if (linestartswith("##name##")){ //, JSTORM <95/135>
Issued by: < > Revision: <10> <2000/8/02> clients[i]name = linesubstring(8); // // clients[i]write_string("name changed to "+linesubstring(8)); send_names(); // return false; else if (lineequals("##quit##")){ // Log out", write_all(clients[i]name+" is logging out"); // "Logout" remove_client(i); return false; return true; //, /** */ static void write_all (String text){ int i; for (i=1;i<=users;i++) clients[i]write_string(text); /** */ static void add_client(socket_stuff client){ if (users >= 25){ // 25, clientwrite_string("sorry, there are too many users right now"); clientkill(); return; clients[++users] = client; // clients[users]write_string("you have been connected"); // send_names(); // /** */ static void remove_client(int client){ clients[client]kill(); // clients[client]=clients[users]; // clients[users]=null; // users--; // 1 send_names(); // JSTORM <96/135>
Issued by: < > Revision: <10> <2000/8/02> /**, *, */ class connection extends Thread{ Socket socket = null; // public boolean is_connected = false; // ServerSocket server = null; connection (ServerSocket server_sock){ server = server_sock; boolean connected(){ return is_connected; /** */ Socket get_socket(){ Systemoutprintln("Returning the socket"); is_connected = false; return socket; public void run(){ while (true){ // is_connected = false; //Systemoutprintln("In run Method"); //, add_client() // if (!is_connected) { //Systemoutprintln("Trying for new connection"); try{ socket = serveraccept(); // catch(ioexception e) { //Systemoutprintln("Problem with accept"); //Systemoutprintln("Received new connection"); is_connected = true; thissuspend(); //, JSTORM <97/135>
Issued by: < > Revision: <10> <2000/8/02> /** */ class socket_stuff{ Socket socket; DataInputStream is; PrintStream os; String name = new String("Guest"); // socket_stuff(socket client){ //Systemoutprintln("getting the socket info"); //get the streams try{ is = new DataInputStream(new BufferedInputStream(clientgetInputStream())); os = new PrintStream (new BufferedOutputStream(clientgetOutputStream(), 1024), false); socket = client; catch(ioexception e){ /** */ public void write_string (String s){ //Systemoutprintln ("Writing to socket"); osprintln(s); // osflush(); /** */ public String read_string(){ //Systemoutprintln("Reading from socket"); try{ String inputline = isreadline(); // return inputline; catch(ioexception e){ return "null"; /** */ public int can_read(){ boolean test; if (oscheckerror()){ //, Systemoutprintln("oscheckError"); return -1; try{ test = (isavailable()>1); // catch(ioexception e){ return -1; JSTORM <98/135>
Issued by: < > Revision: <10> <2000/8/02> if (test) // 1 return 1; else return 0; // 0 /** */ public void kill(){ try{ if (os!= null) osclose(); if (is!= null) isclose(); if (socket!= null) socketclose(); catch (IOException e){ < > Serverjava Server, connection, socket_stuff 3 Server, connectionsocket_stuff,, ( "quit") connection,,,, socket_stuff, JSTORM <99/135>
Issued by: < > Revision: <10> <2000/8/02> (prototype), 1) - -, - ( ) 2) -, -, ( ), -, 1), java ServerBaduk &" 2) "Badukclass" HTML <html> <head> <title> ABadukApplet</title> </head> <body bgcolor="ffffff"> <center> <h2>!</h2> <appletcode="badukclass"width=480height=470> </applet> </center> </body> </html> JSTORM <100/135>
Issued by: < > Revision: <10> <2000/8/02> < > Badukhtml! Badukhtml", ( ) ID "pjh" ID, ID (< 1> ) < 1> pjh" ID haha", "Request" ID < 2>, "haha", Ok" < 2> "Request",, haha" < 3> pjh" < 3> haha" JSTORM <101/135>
Issued by: < > Revision: <10> <2000/8/02>, "haha""ok", pjh" Start", < 4> < 4> Start",, ( ), Log out" import javaappletapplet; import javaawt*; import javaio*; import javanet*; public class Baduk extends Applet implements BadukConstant{ Panel p,s; public Inframe f=new Inframe(this); public BadukLogic bl = new BadukLogic(this,f); public void init(){ setbackground(colorwhite); p = new Panel(); /* Panel */ JSTORM <102/135>