r3.dvi

Similar documents
r4.dvi

r2.dvi

r6.dvi

r14.dvi

r8.dvi

r5.dvi

アプレットの作成

r14.dvi

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

r3.dvi

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

untitled

Thread

6 p.1 6 Java GUI GUI paintcomponent GUI mouseclicked, keypressed, actionperformed mouseclicked paintcomponent thread, 1 GUI 6.0.2, mutlithread C


Java演習(6) -- 条件分岐 --

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

r2.dvi

< F2D834F838C A815B A CC>

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 B838A835882CC8CF68EAE2E6A7464>

< F2D F B834E2E6A7464>

Microsoft PowerPoint prog1_doc2x.pptx

Java演習(2) -- 簡単なプログラム --

Microsoft PowerPoint prog1_doc2.pptx

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

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


2

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

< F2D82B682E182F182AF82F12E6A7464>

< F2D89BA8EE882C E6A7464>

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

< F2D8EA CE909482CC92EA82852E6A7464>

教材ドットコムオリジナル教材 0から始めるiアフ リ リファレンス i アプリ簡易リファレンス ver i アプリ Java 独自のメソッド (1)iアプリの命令を使えるようにする import com.nttdocomo.ui.*; (2) 乱数を使う import java.u

< F2D92DE82E8914B82CC977088D32E6A7464>

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

表示の更新もそういた作業のひとつに当たる スレッドの使用アニメーション アニメーションやシミュレーションなどは画面の更新が一定のタイミングで行われていく この連続した画面の更新をスレッドを利用して行う しかし paint() メソッドを直接呼び出して表示を更新することはできない その理由

< 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

I. (i) Java? (A). 2Apples (B). Vitamin-C (C). Peach21 (D). Pine_Apple (ii) Java? (A). Java (B). Java (C). Java (D). JavaScript Java JavaScript Java (i

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

Safari AppletViewer Web HTML Netscape Web Web 15-1 Applet Web Applet init Web paint Web start Web HTML stop destroy update init Web paint start Web up

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学習教材

問1

: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

10K pdf

任意の加算プログラム

< F2D E E6A7464>

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>

tn_soturon_sjis.dvi

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

: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

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

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

( ) p.1 x y y = ( x ) 1 γ γ = filtergamma.java import java.applet.*; public class filtergamma extends Applet{ Image img; Image new_img; publi

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解答.doc

Programming-C-9.key

JAVA入門

解きながら学ぶJava入門編

Microsoft PowerPoint - OOP.pptx

vol.30.}...`.X...b.h

r4.dvi

Java updated

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

Java プログラミング Ⅰ 3 回目変 数 今日の講義講義で学ぶ内容 変数とは 変数の使い方 キーボード入力の仕方 変 数 変 数 一時的に値を記憶させておく機能 変数は 型 ( データ型 ) と識別子をもちます 2 型 ( データ型 ) 変数に記憶する値の種類変数の型は 記憶できる値の種類と範囲

< F2D B825082CC96E291E82E6A7464>

:30 12:00 I. I V II. III. IV. ( a d) V. VI : A ActionListener aa addactionlistener AE ActionEvent K KeyListener ak addkeyliste

< 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プログラミングⅠ

ただし 無作為にスレッドを複数実行すると 結果不正やデッドロックが起きる可能性がある 複数のスレッド ( マルチスレッド ) を安全に実行する ( スレッドセーフにする ) ためには 同期処理を用いるこ とが必要になる 同期処理は 予約語 synchronized で行うことができる ここでは sy

Microsoft PowerPoint - prog10.ppt

Microsoft PowerPoint - prog10.ppt

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

PowerPoint プレゼンテーション

I. java.awt.rectangle java.lang.math random Java TM API java.awt Rectangle Rectangle (x,y)... public int x Rectangle X public int y Rectangle Y public

Java プログラミング Ⅰ 3 回目変数 変数 変 数 一時的に値を記憶させておく機能型 ( データ型 ) と識別子をもつ 2 型 ( データ型 ) 変数の種類型に応じて記憶できる値の種類や範囲が決まる 型 値の種類 値の範囲 boolean 真偽値 true / false char 2バイト文

2

Microsoft PowerPoint ppt

ソフトウェア開発方法論2

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

GUIプログラムⅤ

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