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

Similar documents
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

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

: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

: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

: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 actionperforme

I. (i) Java? (A). Foo_Bar (B). G day (C). 999 (D). Golgo13 (ii)? (A). Java public (B). Java (C). Java JavaScript (D). Java C Java C (iii)? (A). Java (

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

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

I 4 p.2 4 GUI java.awt.event.* import /* 1 */ import mouseclicked MouseListener implement /* 2 */ init addmouselistener(this) this /* 3 */ this mousec

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

5 p Point int Java p Point Point p; p = new Point(); Point instance, p Point int 2 Point Point p = new Point(); p.x = 1; p.y = 2;

55 7 Java C Java TCP/IP TCP/IP TCP TCP_RO.java import java.net.*; import java.io.*; public class TCP_RO { public static void main(string[] a

I. (i) Foo public (A). javac Foo.java java Foo.class (C). javac Foo java Foo (ii)? (B). javac Foo.java java Foo (D). javac Foo java Foo.class (A). Jav

Thread

Microsoft PowerPoint prog1_doc2x.pptx

アプレットの作成

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

r1.dvi

新・明解Java入門

text_13.dvi

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

r3.dvi

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

r14.dvi

r2.dvi

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

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

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

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


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

2

r8.dvi

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

untitled

K227 Java 2

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.

Chapter 20. [ ] ; [ ] = new [ ] ; Color colors [ ] = new Color[ 20 ]; // 20 Button operations [ ] = new Button[ 10 ]; // 10 colors[ 3 ] = new Color( 1

4 p.2 4 GUI return; public void mousepressed(mouseevent e) { /* 5 */ public void mousereleased(mouseevent e) { /* 5 */ public void mouseentered(mousee

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 +=

< F2D82518CC282CC D2E6A7464>

< F2D834F838C A815B A CC>

< F2D B838A835882CC8CF68EAE2E6A7464>

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

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

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

IE6 2 BMI chapter1 Java 6 chapter2 Java 7 chapter3 for if 8 chapter4 : BMI 9 chapter5 Java GUI 10 chapter6 11 chapter7 BMI 12 chap

< F2D82B682E182F182AF82F12E6A7464>

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

Java (9) 1 Lesson Java System.out.println() 1 Java API 1 Java Java 1

< F2D825282CC947B909482CC A815B83682E6A>

< F2D F B834E2E6A7464>

2

r4.dvi

データ構造とアルゴリズム論

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

< F2D92DE82E8914B82CC977088D32E6A7464>

目 次 Java GUI 3 1 概要 クラス構成 ソースコード例 課題...7 i

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

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

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

Programming-C-9.key

r3.dvi

2 static final int DO NOTHING ON CLOSE static final int HIDE ON CLOSE static final int DISPOSE ON CLOSE static final int EXIT ON CLOSE void setvisible

< F2D8EA CE909482CC92EA82852E6A7464>

Java言語 第1回

text_10.dvi

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

226

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

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

1 Java Java GUI , 2 2 jlabel1 jlabel2 jlabel3 jtextfield1 jtextfield2 jtextfield3 jbutton1 jtextfield1 jtextfield2 jtextfield3

r2.dvi

JavaプログラミングⅠ

Microsoft PowerPoint - OOP.pptx

GUIプログラムⅤ

アプレットⅤ

Microsoft PowerPoint - prog10.ppt

4 p.2 4 GUI public void mousepressed(mouseevent e) { /* 5 */ public void mousereleased(mouseevent e) { /* 5 */ public void mouseentered(mouseevent e)

Java学習教材

ガイダンス

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

Microsoft PowerPoint - prog10.ppt

I java A

r6.dvi

text_12.dvi

: : : TSTank 2

r14.dvi

< F2D89BA8EE882C E6A7464>

PowerPoint プレゼンテーション

untitled

/ ( ) 8/7/ :21 p.2/64

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

ガイダンス

Javaセキュアコーディングセミナー2013東京第1回 演習の解説

解きながら学ぶJava入門編

例外(exception)とは何か

Transcription:

II Java 10 2 12 10:30 12:00 I. I III II. III. IV. ( a d) V. : this==null, T == N A ActionListener C class D actionperformed G getsource I implements K KeyListener J JApplet L addmouselistener M MouseListener N null P public Q equals R Runnable S System.out.println T this V private W new X extends KeyTest.java, UpDownButton3.java, ( I), BubbleSort1.java, BubbleSort2.java, Point.java, ColorPoint.java 1

I. 8765 2 HTML HashMap (i) (ii) :.java import java.net.*; import java.io.*; import java.util.hashmap; public class SimpleStopWatch { public static void main(string args[]) { // ServerSocket servsock = null; try { servsock = new ServerSocket( (i) ); catch (Exception e) { e.printstacktrace(); System.exit(1); (ii) map = new (ii) (); while(true) { try { Socket sock = servsock.accept(); // BufferedReader in = new BufferedReader( new InputStreamReader(sock.getInputStream())); PrintStream out = new PrintStream(sock.getOutputStream()); String host = sock.getinetaddress().gethostname(); int i ; for(i=0; i<2; i++) { // 2 in.readline(); out.println("<html>"); out.println("<head><title>test</title></head>"); out.println("<body>"); Long prev = map.get(host); long now = System.currentTimeMillis(); // if (prev==null) { out.printf("%s %n", host); else { out.printf("%s %d %n", host, (now-prev)/1000); out.println("</body>"); out.println("</html>"); sock.close(); map.put(host, now); catch (IOException e) { e.printstacktrace(); 2

IP 192.168.0.1 java SimpleStopWatch IP 192.168.0.2 Web http://192.168.0.1:8765/ URL ( ) 1 192.168.0.2 2 192.168.0.2 12 Java int char double boolean Integer Character Double Boolean currenttimemillis API java.lang System public static long currenttimemillis()... : UTC 1970 1 1 0 3

II. Creature 3 Snake, Frog, Lizard : Creature.java public class Creature { public int age; public Creature() { // 1 age = 0; public void grow() { age++; public String getname() { return " "; public int getnumlegs() { return 8; public void selfintroduce() { System.out.printf(" %s %d %n", getname(), getnumlegs()); : Snake.java public class Snake (i) { public Snake() { // 1 super(); public String getname() { return " "; public int getnumlegs() { return 0; // 01 // 02 // 03 // 04 // 05 // 06 // 07 // 08 // 09 // 10 // 11 // 12 // 13 // 14 // 15 // 16 // 17 // 18 // 19 // 20 // 21 // 22 // 23 // 24 4

: Frog.java public class Frog (i) { public Frog() { // 1 super(); public String getname() { if (age<=1) { return " "; else { return " "; public int getnumlegs() { if (age==0) { return 0; else if (age==1) { return 2; else { return 4; : Lizard.java public class Lizard (i) { public Lizard() { // 1 super(); public String getname() { return " "; public int getnumlegs() { return 4; 1: 5

CreatureTest main : CreatureTest.java public class CreatureTest { public static void main(string[] args) { int i, j; Creature[] creatures = new Creature[3]; creatures[0] = new Snake(); creatures[1] = new Frog(); creatures[2] = new Lizard(); creatures[0].age = 100; for (i=0; i<3; i++) { for (j=0; j<3; j++) { creatures[j].selfintroduce(); creatures[j].grow(); // 01 // 02 // 03 // 04 // 05 // 06 // 07 // 08 // 09 // 10 // 11 // 12 // 13 // 14 // 15 // 16 // 17 // 18 (i) 3 (ii) Creature age CreatureTest 9 Creature (iii) CreatureTest 9 main 6

III. Java : ColorAnimation.java import java.awt.*; import java.awt.event.*; import javax.swing.*; public class ColorAnimation (i) { String text = ""; float f = 0; Thread you; public void start() { if (you == null) { // you = new Thread(this); you.start(); public void stop() { you = null; public void init() { addkeylistener( (ii) { public void keypressed(keyevent e) { public void keyreleased(keyevent e) { public void keytyped(keyevent e) { text += e.getkeychar(); (iii) ); public void paint(graphics g) { super.paint(g); g.setcolor(color.gethsbcolor(f, 1, 1)); g.drawstring(text, 20, 20); public void run() { Thread me = Thread.currentThread(); for(; you == me; f+=0.02) { repaint(); // paint try { Thread.sleep(200); // 200 catch (InterruptedException e) { 7

gethsbcolor API java.awt Color public static Color gethsbcolor(float h, float s, float b) HSB Color s b 0 1 (0.0 1.0 ) h... : h - s - b - : Color (1) Hello, (2) world! (i) (ii) (iii) 20 My name is Duke. ld! My name is Duke. (iii) 8

String java.lang String public int length()... : public String substring(int beginindex) : "unhappy".substring(2) returns "happy" "Harbison".substring(3) returns "bison" "emptiness".substring(9) returns "" (an empty string) : beginindex - ( ) : 9

KeyTest.java, UpDownButton3.java ( I), BubbleSort1.java, BubbleSort2.java, Point.java, ColorPoint.java KeyTest.java import javax.swing.*; import java.awt.*; import java.awt.event.*; public class KeyTest extends JApplet implements KeyListener { int x=50, y=20; public void init() { addkeylistener(this); public void paint(graphics g) { super.paint(g); g.drawstring("hello WORLD!", x, y); public void keytyped(keyevent e) { int k = e.getkeychar(); if (k== u ) { y-=10; else if (k== d ) { y+=10; repaint(); public void keyreleased(keyevent e) { public void keypressed(keyevent e) { 10

UpDownButton3.java import javax.swing.*; import java.awt.*; import java.awt.event.*; public class UpDownButton3 extends JApplet { int x=20; public void init() { JButton left = new JButton("Left"); JButton right = new JButton("Right"); left.addactionlistener(new ActionListener() { public void actionperformed(actionevent e) { x-=10; repaint(); ); right.addactionlistener(new ActionListener() { public void actionperformed(actionevent e) { x+=10; repaint(); ); setlayout(new FlowLayout()); add(left); add(right); public void paint(graphics g) { super.paint(g); g.drawstring("hello WORLD!", x, 55); 11

BubbleSort1.java import javax.swing.*; import java.awt.*; public class BubbleSort1 extends JApplet implements Runnable { int[] args = {10, 3, 46, 7, 23, 34, 8, 12, 4, 45, 44, 52; Color[] cs ={Color.RED, Color.ORANGE, Color.GREEN, Color.BLUE; Thread thread=null; public void start() { if (thread == null) { thread = new Thread(this); thread.start(); public void stop() { thread = null; public void paint(graphics g) { int i; super.paint(g); for(i=0; i<args.length; i++) { g.setcolor(cs[args[i]%cs.length]); g.fillrect(0, i*10, args[i]*5, 10); public void run() { int i, j; Thread thisthread = Thread.currentThread(); for (i=0; i<args.length-1; i++) { for (j=args.length-1; thread == thisthread && j>i; j--) { if (args[j-1]>args[j]) { // int tmp=args[j-1]; args[j-1]=args[j]; args[j]=tmp; repaint(); try { // repaint Thread.sleep(500); catch (InterruptedException e) { 12

BubbleSort2.java import javax.swing.*; import java.awt.*; import java.awt.event.*; public class BubbleSort2 extends JApplet implements Runnable, ActionListener { int[] args = { 10, 3, 46, 7, 23, 34, 8, 12, 4, 45, 44, 52; Color[] cs ={Color.RED, Color.ORANGE, Color.GREEN, Color.BLUE; Thread thread=null; private boolean threadsuspended=true; public void init() { JButton step = new JButton("Step"); step.addactionlistener(this); setlayout(new FlowLayout()); add(step); // start, stop, paint BubbleSort1.java public synchronized void actionperformed(actionevent e) { threadsuspended=false; notify(); public void run() { int i, j; for (i=0; i<args.length-1; i++) { for (j=args.length-1; j>i; j--) { if (args[j-1]>args[j]) { // int tmp=args[j-1]; args[j-1]=args[j]; args[j]=tmp; repaint(); try { // repaint synchronized(this) { while (threadsuspended) { wait(); threadsuspended=true; catch (InterruptedException e) { 13

Point.java public class Point { public int x, y; public void move(int dx, int dy) { x += dx; y += dy; public void print() { System.out.printf("(%d, %d)", x, y); public void moveandprint(int dx, int dy) { print(); move(dx, dy); print(); public Point(int x0, int y0) { x = x0; y = y0; ColorPoint.java public class ColorPoint extends Point { private String[] cs = {"black", "red", "green", "yellow", "blue", "magenta", "cyan", "white"; private int color; // 0-1- 2-3- 4-5- 6-7- public void print() { System.out.printf("<font color= %s >", getcolor()); super.print(); System.out.print("</font>"); public void setcolor(string c) { int i; for (i=0; i<cs.length; i++) { if (c.equals(cs[i])) { color = i; return; // public ColorPoint(int x, int y, String c) { super(x, y); setcolor(c); public String getcolor() { return cs[color]; // // 14

II Java ( 10 2 12 ) I. 5 2 (i). (ii). II. 5 3 (i). III. (ii). (iii). 5 3 (i). (ii). (iii). 1

2