r3.dvi

Similar documents
アプレットの作成

Java演習(4) -- 変数と型 --

r3.dvi

Java演習(9) -- クラスとメソッド --

やさしいJavaプログラミング -Great Ideas for Java Programming サンプルPDF

19 3!! (+) (>) (++) (+=) for while 3.1!! (20, 20) (1)(Blocks1.java) import javax.swing.japplet; import java.awt.graphics;

Java 2 p.2 2 Java Hello0.class JVM Hello0 java > java Hello0.class Hello World! javac Java JVM java JVM : Java > javac 2> Q Foo.java Java : Q 2.

< F2D F B834E2E6A7464>

Microsoft PowerPoint prog1_doc2x.pptx

Microsoft PowerPoint prog1_doc2.pptx

I HTML HashMap (i) (ii) :.java import java.net.*; import java.io.*; import java.util.hashmap; public class SimpleStopWatch { public static voi

K227 Java 2

Applet java.lang.object java.awt.component java.awt.container java.awt.panel java.applet.applet

II Java :30 12:00 I. I IV II. III. IV. ( a d) V. : this==null, T == N A ActionListener C class D actionperformed G getsource I implements K

Local variable x y i paint public class Sample extends Applet { public void paint( Graphics gc ) { int x, y;... int i=10 ; while ( i < 100 ) {... i +=

2 p.2 2 Java Hello0.class JVM Hello0 java > java Hello0.class Hello World! javac Java JVM java JVM : Java > javac 2> Q Foo.java Java : Q B

< F2D82518CC282CC D2E6A7464>

< F2D825282CC947B909482CC A815B83682E6A>

新・明解Java入門

Java 3 p.2 3 Java : boolean Graphics draw3drect fill3drect C int C OK while (1) int boolean switch case C Calendar java.util.calendar A

シミュレーションの簡単な例 GUI 無しのシミュレーションを作る GUI を作る パラメタを設定するデモンストレーションをする 2 オブジェクト指向プログラミング特論

2 p.2 2 Java Hello0.class JVM Hello0 java > java Hello0.class Hello World! javac Java JVM java JVM : Java > javac 2> Q Foo.java Java : Q B

Java学習教材

10K pdf

3 p.1 3 Java Java Java try catch C Java if for while C 3.1 boolean Java if C if ( ) 1 if ( ) 1 else , 2 { } boolean true false 2 boolean Gr

< F2D A839382CC906A2E6A7464>

:30 12:00 I. I VII II. III. IV. ( a d) V. VI : this==null, T == N A ActionListener A addactionlistener C class D actionperforme

Java Java Java Java Java 4 p * *** ***** *** * Unix p a,b,c,d 100,200,250,500 a*b = a*b+c = a*b+c*d = (a+b)*(c+d) = 225

Java言語 第1回

< F2D82518E9F8AD CC834F CC8CFC82AB82C68D4C>

2 p.2 2 Java > javac Hello0.java Hello0.class JVM Hello0 java > java Hello0.class Hello World! javac Java JVM java JVM : Java > javac 2> Q Foo.j

< F2D BCA82CC978E89BA82CC8EC08CB12E6A7464>

I java A

try catch Exception Java try catch try { } catch ( Exception e ) { } e 16-1 try catch 0 try { int x = 0; int y = 10 / x; } catch ( Exception e ) { Sys

JAVA入門

解きながら学ぶJava入門編

r4.dvi

Java updated

問題1 以下に示すプログラムは、次の処理をするプログラムである

< F2D82518E9F8AD CC95BD8D7388DA93AE2E6A7464>

10/ / /30 3. ( ) 11/ 6 4. UNIX + C socket 11/13 5. ( ) C 11/20 6. http, CGI Perl 11/27 7. ( ) Perl 12/ 4 8. Windows Winsock 12/11 9. JAV

JavaプログラミングⅠ

KeyListener init addkeylistener addactionlistener addkeylistener addkeylistener( this ); this.addkeylistener( this ); KeyListener public void keytyped

8 if switch for while do while 2

Chapter JDK KeyListener keypressed(keyevent e ) keyreleased(keyevent e ) keytyped(keyevent e ) MouseListener mouseclicked(mouseeven

ALG2012-F.ppt

Transcription:

00 3 2000.6.10 0 Java ( 7 1 7 1 GSSM 1? 1 1.1 4 4a 4b / / 0 255 HTML X 0 255 16 (0,32,255 #0020FF Java xclock -bg #0020FF xclock ^C (Control C xclock 4c 1

import java.applet.applet; import java.awt.*; public class r2ex4c extends Applet { Font fn = new Font("Helvetica", Font.BOLD, 36); public void paint(graphics g) { g.setfont(fn); for(int i = 0; i < 10; ++i) { g.setcolor(new Color(i*25, 100+i*10, 255-i*20)); g.drawstring("hello, World", 30+i*3, 30+i*10);! 1.2 8b 8a 8 5 8b 1 import java.applet.applet; import java.awt.*; public class r2ex8b extends Applet { int[] x = new int[100]; int[] y = new int[100]; public void paint(graphics g) { g.setcolor(new Color(100, 0, 255)); double cx = 150; double cy = 100; double longradius = 100.0; double shortradius = 35.0; int num = 5; for(int i = 0; i < 2*num; ++i) { double rad = (2.0 * Math.PI) * i / (2*num); if(i%2!= 0) { x[i] = (int)(cx + longradius * Math.cos(rad)); y[i] = (int)(cy + longradius * Math.sin(rad)); else { x[i] = (int)(cx + shortradius * Math.cos(rad)); y[i] = (int)(cy + shortradius * Math.sin(rad)); g.fillpolygon(x, y, 2*num); 2

5 100.0 num 2 2? 5 5 1 double int Java (C C++ (double)(2*num 1.3 8d 8c 8d ( 8d (? 2 fillpolygon( import java.applet.applet; import java.awt.*; public class r2ex8d extends Applet { public void paint(graphics g) { g.setcolor(color.red); g.fillrect(70, 20, 160, 160); g.setcolor(color.white); g.fillrect(130, 40, 40, 120); g.fillrect(90, 80, 120, 40); Color.red? Color ( Math.PI 2 Java ( [...], ::= ::= ::= [public] class { ::= [extends ] [implements, ] ::= [public] [static] [= ]; ::= [public] [static] [ ] (, ) [ ] { 3

1 ( ::= [public] interface { ::= [public] [static] (, ); ::= ::= [] void ::= boolean byte char int long float double ::= throws [, ] ( if while for ::= [= ]; ; if( ) [else ] while( ) for([ =] ; ; ) { break; continue; return [ ]; ::= [ ] new (, ) new [ ] new []{,. (, ). (, ).. ( ) ::= [l] [f] "..."... l long int f float double a = b; = + - * / % & ^ ~ << >> &&! ==!= < > <= >= = += -= *= ++ -- 3 new (... ( new [ ] new []{,.. 2 4

. (...). (...) ( static class... { public static void method1(...) {... public void method2(...) {... method1 method2 public void ( 3 class... { static int var1; int var2; public static void method1(int x,...) { int y;... public void method2(int z,...) { int t;... var1 var2 y t x z 4 ( ( interface Animal { public void walk(double speed); // public void tell(string message); // ( interface Figure { public void addtime(double dt); // public void draw(graphics g); // 5

... Figure f = new Triangle(...);... f.addtime(1.00); f.draw(g); f Figure 5! class Circle implements Figure { Color col; double cx, cy, rad; public Circle(Color c, double x, double y, double r) { col = c; cx = x; cy = y; rad = r; public void addtime(double dt) { public void draw(graphics g) { g.setcolor(col); g.filloval((int)(cx-rad), (int)(cy-rad), (int)(rad*2), (int)(rad*2)); (1) Figure Figure 2 ( (2) col cx cy rad (3) new Circle(... new new (4) addtime( (5) draw( Graphics Figure Circle 6

import java.applet.applet; import java.awt.*; public class R3Sample1 extends Applet { Figure f1 = new Circle(Color.blue, 100.0, 100.0, 30.0); Figure f2 = new Circle(Color.red, 120.0, 80.0, 20.0); public void paint(graphics g) { f1.addtime(10.0); f1.draw(g); f2.addtime(10.0); f2.draw(g); interface Figure { public void addtime(double time); public void draw(graphics g); class Circle implements Figure { Color col; double cx, cy, rad; public Circle(Color c, double x, double y, double r) { col = c; cx = x; cy = y; rad = r; public void addtime(double t) { public void draw(graphics g) { g.setcolor(col); g.filloval((int)(cx-rad),(int)(cy-rad),(int)(rad*2),(int)(rad*2)); paint() 1 10 1 HTML (! <html><head><title>sample</title></head><body> <h1>r3sample1</h1> <applet code="r3sample1.class" width=300 height=200></applet> </body></html> 7

2 2 a. b. c. : d. : 2 e. Helvatica 24 3 2 : vx vy(x /Y addtime() x = x + V x t y = y + V y t 6 (?)! CPU 2 3 paint( Java Thread Runnable public interface Runnable { public void run(); run( ( 7 import java.applet.applet; import java.awt.*; public class R3Sample2 extends Applet { Figure f1 = new RotPolygon(Color.blue, 100.0, 100.0, 50.0, 5, -0.5); Figure f2 = new RotPolygon(Color.red, 150.0, 80.0, 70.0, 3, 0.8); boolean running; long basetime; 8

public void paint(graphics g) { long time = System.currentTimeMillis(); double dt = 0.001*(time-basetime); basetime = time; f1.addtime(dt); f1.draw(g); f2.addtime(dt); f2.draw(g); public void start() { running = true; basetime = System.currentTimeMillis(); (new Thread(new Timer())).start(); public void stop() { running = false; running ( true false ( basetime paint( start(stop( ( running true running false class Timer implements Runnable { public void run() { while(running) { try { Thread.sleep(100); catch(exception e) { repaint(); Timer Runnable implements run( running true 100 repaint()( try { A catch(exception e) { B A ( B running repaint( Timer ( 9

interface Figure { public void addtime(double time); public void draw(graphics g); class RotPolygon implements Figure { int[] px, py; Color col; int num; double cx, cy, rad, theta, vtheta; public RotPolygon(Color c, double x, double y, double r, int n, double v) { col = c; num = n; cx = x; cy = y; rad = r; theta = 0.0; vtheta = v; px = new int[num]; py = new int[num]; public void addtime(double dt) { theta = theta + dt*vtheta; public void draw(graphics g) { for(int i = 0; i < num; ++i) { double t = theta + (2.0 * Math.PI) * i / num; px[i] = (int)(cx + rad * Math.cos(t)); py[i] = (int)(cx + rad * Math.sin(t)); g.setcolor(col); g.fillpolygon(px, py, num); 1 (! 2 4 ( 5 a. ( ) b. c. 8 ( ( : (simulation 10

import java.applet.applet; import java.awt.*; public class R3Sample2 extends Applet { Figure f1 = new BounceCircle(Color.blue, 100.0, 100.0, 30.0, 30.0, 95.0); Figure f2 = new BounceCircle(Color.red, 120.0, 80.0, 20.0, -85.0, 50.0); boolean running; long basetime; public void paint(graphics g) { long time = System.currentTimeMillis(); double dt = 0.001*(time-basetime); basetime = time; f1.addtime(dt); f1.draw(g); f2.addtime(dt); f2.draw(g); public void start() { running = true; basetime = System.currentTimeMillis(); (new Thread(new Timer())).start(); public void stop() { running = false; class Timer implements Runnable { public void run() { while(running) { try { Thread.sleep(100); catch(exception e) { repaint(); interface Figure { public void addtime(double time); public void draw(graphics g); class BounceCircle implements Figure { double width = 300.0; double height = 200.0; Color col; double cx, cy, rad, vx, vy; 11

public BounceCircle(Color c, double x, double y, double r, double vx1, double vy1) { col = c; cx = x; cy = y; rad = r; vx = vx1; vy = vy1; public void addtime(double dt) { cx = cx + vx*dt; cy = cy + vy*dt; if(cx < 0 && vx < 0.0) { vx = -vx; if(cx > width && vx > 0.0) { vx = -vx; if(cy < 0 && vy < 0.0) { vy = -vy; if(cy > height && vy > 0.0) { vy = -vy; public void draw(graphics g) { g.setcolor(col); g.filloval((int)(cx-rad),(int)(cy-rad),(int)(rad*2),(int)(rad*2)); ( X /Y addtime( t X /Y X /Y 6 ( 7 BounceCirle a. b. ( ( c. ( d. (!: ) 8 12