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

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

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

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

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

: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

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

: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

: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

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 (

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;

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

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

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

Thread

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

r14.dvi

r2.dvi

新・明解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 B

ガイダンス

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

ガイダンス

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

Microsoft PowerPoint prog1_doc2x.pptx

次の演習課題(1),(2)のプログラムを完成させよ

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

ÿþ˜u#u·0¹0Æ0à0

text_12.dvi

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

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

text_13.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

アプレットの作成

r4.dvi

2

Microsoft PowerPoint prog1_doc2.pptx

r3.dvi

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

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

public class Kadai _02 { public static void main(string[] args) { MyFrame frame = new MyFrame("Kadai _02"); (2) フレームのクラス名は MyFrame とし 以下

K227 Java 2

IT プロジェクト

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

r3.dvi

r2.dvi

解きながら学ぶJava入門編

< F2D834F838C A815B A CC>

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

アジェンダ 1 グラフィカルなインタフェース GUI(Graphical User Interface) の基礎 2 Swing を利用する Swing の基礎知識 2

< F2D B838A835882CC8CF68EAE2E6A7464>

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

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

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

B 10 : N ip2003f10.tex B : 9/12/ :02 p.1/71

r1.dvi


Java 2 - Lesson01

< F2D82518CC282CC D2E6A7464>

< F2D825282CC947B909482CC A815B83682E6A>

< F2D F B834E2E6A7464>

ALG ppt

< F2D82B682E182F182AF82F12E6A7464>

ガイダンス

untitled

ガイダンス

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

ガイダンス

< F2D92DE82E8914B82CC977088D32E6A7464>

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

3 Java 3.1 Hello World! Hello World public class HelloWorld { public static void main(string[] args) { System.out.println("Hello World");

明解Javaによるアルゴリズムとデータ構造

public class MyFrame { private JPanel panel1; private JPanel panel2; private JPanel panel3; private JPanel panel4; private JLabel label1; private JTex

untitled

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

< F2D8EA CE909482CC92EA82852E6A7464>

226

r8.dvi

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

JavaプログラミングⅠ

Microsoft Word - keisankigairon.ch doc

2

Java学習教材

Microsoft PowerPoint ppt

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

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

< F2D BCA82CC978E89BA82CC8EC08CB12E6A7464>

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

: : : TSTank 2

PowerPoint Presentation

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

Cir

class IntCell { private int value ; int getvalue() {return value; private IntCell next; IntCell next() {return next; IntCell(int value) {this.value =

Microsoft PowerPoint - OOP.pptx

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

GUIプログラムⅤ

Object MenuComponent MenuBar MenuItem Menu CheckboxMenuItem

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


Transcription:

2017 07 28 10:30 12:00 I. I V II. III. IV. ( a d) V. VI. 80 100 60 : A ActionListener aa addactionlistener AE ActionEvent K KeyListener ak addkeylistener KE KeyEvent M MouseListener am addmouselistener ME MouseEvent pl System.out.println pf System.out.printf KeyTest.java, LeftRightButton2.java, Left- RightButton4.java, Guruguru.java, Point.java, ColorPoint.java 1

I. (i) Java? (A). UTF-8 (B). ShiftJIS (C). EUC_JP (D). 8859_1 (ii)? (A). Java (B). Web Java JavaScript (C). Java (D). Java (iii)? (A). Java (B). Haskell (C). C (D). Prolog 2

II. java.math.biginteger Java TM API java.math BigInteger... public static final BigInteger ZERO BigInteger 0 public static final BigInteger ONE BigInteger 1 public BigInteger multiply(biginteger val) (this * val) BigInteger : val - BigInteger : this * val public BigInteger subtract(biginteger val) (this - val) BigInteger : val - BigInteger : this - val public boolean equals(object x) BigInteger Object : x - BigInteger Object : Object BigInteger BigInteger true public static BigInteger valueof(long val) long BigInteger... : : val - BigInteger BigInteger 3

java.math.biginteger int 22 BigInteger int long 0 123 * - == BigInteger : BigFactorial.java import java.math.biginteger; import java.util.scanner; public class BigFactorial { static BigInteger factorial(biginteger n) { if ( (i) ) { return (ii) ; else { return (iii) ; public static void main(string[] args) { System.err.print("Please input a non-negative integer: "); long i = new Scanner(System.in).nextLong(); System.out.printf("Its factorial is %s.%n", factorial( (iv) )); long (i) Please input a non-negative integer: 50 Its factorial is 30414093201713378043612608166064768844377641568960512000000000000. (i) (i) n BigInteger 0 (ii) (ii) BigInteger 1 (iii) (iii) (iv) (iv) long i BigInteger 4

III. CalculatorTest GUI digits 0 1 0 0 C 0 1 0 : CalculatorTest.java 1 import java.awt.*; 2 import java.awt.event.*; 3 4 import javax.swing.*; 5 6 public class CalculatorTest extends JPanel { 7 JLabel digits; 8 9 private class NumAction (i) { 10 String num; 11 12 NumAction(String n) { 13 num = n; 14 15 16 public void actionperformed(actionevent e) { 17 String current = digits.gettext(); 18 if (current.equals("0")) { 19 digits.settext(num); 20 else { 21 digits.settext(current + num); 22 23 24 25 26 public CalculatorTest() { 27 setpreferredsize(new Dimension(240, 80)); 5

28 digits = new JLabel("0"); 29 30 JButton bt0 = new JButton("0"); 31 bt0.addactionlistener( (ii) ); 32 JButton bt1 = new JButton("1"); 33 bt1.addactionlistener( (iii) ); 34 JButton clear = new JButton("C"); 35 clear.addactionlistener( (iv) ); 36 add(digits); add(bt0); add(bt1); add(clear); 37 38 39 public static void main(string[] args) { 40 SwingUtilities.invokeLater(() -> { 41 JFrame frame = new JFrame("Calculator Test!"); 42 frame.add(new CalculatorTest()); 43 frame.pack(); 44 frame.setvisible(true); 45 frame.setdefaultcloseoperation(jframe.exit_on_close); 46 ); 47 48 (i) NumAction (i) NumAction (ii) (ii), (iii) NumAction (iii) (iv) digits 0 6

IV. basic.gamecharacter material.material basic.gamecharacter material.stone material.material animal.animal basic.gamecharacter animal.cat animal.mouse animal.animal basic.gamecharacter exp getname info rankup animal.animal growth setgrowth cry : basic/gamecharacter.java 1 package basic; 2 3 public class GameCharacter { 4 protected String getname() { return ""; 5 (i) int exp; 6 public String info() { 7 return getname(); 8 9 public void rankup() { /* do nothing */ 10 : material/material.java 1 package material; 2 3 import basic.gamecharacter; 4 5 public class Material (ii) { 6 @Override 7 public String info() { 8 return getname() + ": " + exp; // 9 10 : material/stone.java 1 package material; 2 3 public class Stone (iii) { 4 public Stone() { 5 exp = 2000; // 6 7 8 @Override 9 protected String getname() { 10 return "Stone"; 7

11 12 : animal/animal.java 1 package animal; 2 3 import basic.gamecharacter; 4 5 public class Animal (ii) { 6 (iv) int growth; 7 8 protected void setgrowth(int g) { 9 if (g > 0) { 10 growth = g; 11 else { 12 growth = 0; 13 14 15 16 protected String cry() { 17 return ""; 18 19 20 @Override 21 public void rankup() { 22 exp += growth; // 23 24 25 @Override 26 public String info() { 27 return getname() + ": " + exp + " " + cry(); // 28 29 : animal/cat.java 1 package animal; 2 3 public class Cat (v) { 4 public Cat() { 5 exp = 100; // 6 setgrowth(20); 7 8 9 @Override 10 protected String getname() { 11 return "Cat"; 12 13 8

14 @Override 15 protected String cry() { 16 if (exp < 128) { // 17 return "Myuu"; 18 else { 19 return "Nyaa"; 20 21 22 : animal/mouse.java 1 package animal; 2 3 public class Mouse (v) { 4 public Mouse() { 5 exp = 0; // 6 // growth = -20; // 7 setgrowth(50); 8 9 10 @Override 11 protected String getname() { 12 return "Mouse"; 13 14 15 @Override 16 protected String cry() { 17 return "Chuu"; 18 19 main : test/main.java : test/main.java 1 package test; 2 3 import animal.*; 4 import basic.*; 5 import material.*; 6 7 public class Main { 8 public static void main(string[] args) { 9 GameCharacter[] characters = { 10 new Stone(), new Mouse(), new Cat() 11 ; 12 13 for (int i = 0; i < 3; i++) { 14 for (GameCharacter c: characters) { 15 c.rankup(); 9

16 // c.exp = 0; // 17 System.out.println(c.info()); 18 19 20 21 (i) (v) (i), (iv) (A) (D) (A) public (B) private (C) protected (D) (vii) test.main main 10

V. Java GUI 30 : TypingAnimation.java 1 import java.awt.*; 2 import java.awt.event.*; 3 4 import javax.swing.*; 5 6 public class TypingAnimation extends JPanel (i) { 7 private static final long serialversionuid = 1L; 8 9 private String text = "Please type in! "; 10 private float t = 0; 11 private Thread mythrd; 12 13 public void startthread() { 14 if (mythrd == null) { // 15 mythrd = new Thread(this); 16 mythrd.start(); 17 18 19 20 public void stopthread() { 21 mythrd = null; 22 23 24 public TypingAnimation() { 25 setpreferredsize(new Dimension(250, 50)); 26 setfocusable(true); 27 addkeylistener(new KeyListener() { 28 public void keypressed(keyevent e) { 29 public void keyreleased(keyevent e) { 30 public void keytyped(keyevent e) { 31 char c = e.getkeychar(); 32 text += c; 33 if (text.length() > 30) { 34 text = text.substring(text.length() - 30); 35 36 if (c == ) { 37 repaint(); 38 stopthread(); 39 else { 40 startthread(); 41 42 11

43 ); 44 startthread(); 45 46 47 @Override 48 public void paintcomponent(graphics g) { 49 super.paintcomponent(g); 50 g.setcolor(color.gethsbcolor(t, (float)1.0, (float)1.0)); 51 g.drawstring(text, 20, 20); 52 53 54 public void run() { 55 Thread me = Thread.currentThread(); 56 while ( (ii) ) { 57 repaint(); // paintcomponent 58 try { 59 Thread.sleep(200); // 200 60 catch (InterruptedException e) { 61 t += 0.01; 62 63 64 65 public static void main(string[] args) { 66 SwingUtilities.invokeLater(() -> { 67 JFrame frame = new JFrame("Typing Animation"); 68 frame.add(new TypingAnimation()); 69 frame.pack(); 70 frame.setvisible(true); 71 frame.setdefaultcloseoperation(jframe.exit_on_close); 72 ); 73 74 (i) (ii) 12

KeyTest.java, LeftRightButton2.java, LeftRightButton4.java, Guruguru.java, Point.java, ColorPoint.java KeyTest.java import javax.swing.*; import java.awt.*; import java.awt.event.*; public class KeyTest extends JPanel implements KeyListener { private int x = 50, y = 20; public KeyTest() { setpreferredsize(new Dimension(150, 150)); setfocusable(true); addkeylistener(this); @Override public void paintcomponent(graphics g) { super.paintcomponent(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; System.err.printf("key = %d%n", k); repaint(); public void keyreleased(keyevent e) { public void keypressed(keyevent e) { public static void main(string[] args) { SwingUtilities.invokeLater(() -> { JFrame frame = new JFrame("Key Test"); frame.add(new KeyTest()); frame.pack(); frame.setvisible(true); frame.setdefaultcloseoperation(jframe.exit_on_close); ); LeftRightButton2.java import javax.swing.*; import java.awt.*; import java.awt.event.*; public class LeftRightButton2 extends JPanel { private int x = 20; public LeftRightButton2() { setpreferredsize(new Dimension(200, 70)); JButton lbtn = new JButton("Left"); JButton rbtn = new JButton("Right"); lbtn.addactionlistener(new LeftListener()); rbtn.addactionlistener(new RightListener()); setlayout(new FlowLayout()); add(lbtn); add(rbtn); 13

private class LeftListener implements ActionListener { public void actionperformed(actionevent e) { x -= 10; repaint(); private class RightListener implements ActionListener { public void actionperformed(actionevent e) { x += 10; repaint(); @Override public void paintcomponent(graphics g) { super.paintcomponent(g); g.drawstring("hello WORLD!", x, 55); public static void main(string[] args) { SwingUtilities.invokeLater(() -> { JFrame frame = new JFrame(" "); frame.add(new LeftRightButton2()); frame.pack(); frame.setvisible(true);; frame.setdefaultcloseoperation(jframe.exit_on_close); ); LeftRightButton4.java import javax.swing.*; import java.awt.*; public class LeftRightButton4 extends JPanel { private int x = 20; public LeftRightButton4() { setpreferredsize(new Dimension(200, 70)); JButton lbtn = new JButton("Left"); JButton rbtn = new JButton("Right"); lbtn.addactionlistener(e -> { x -= 10; repaint(); ); rbtn.addactionlistener(e -> { x += 10; repaint(); ); setlayout(new FlowLayout()); add(lbtn); add(rbtn); @Override public void paintcomponent(graphics g) { super.paintcomponent(g); g.drawstring("hello WORLD!", x, 55); public static void main(string[] args) { SwingUtilities.invokeLater(() -> { JFrame frame = new JFrame(" "); frame.add(new LeftRightButton4()); frame.pack(); frame.setvisible(true);; frame.setdefaultcloseoperation(jframe.exit_on_close); ); 14

Guruguru.java import java.awt.*; import javax.swing.*; public class Guruguru extends JPanel implements Runnable { private int r = 50, x = 110, y = 70; private double theta = 0; // private volatile Thread thread = null; public Guruguru() { setpreferredsize(new Dimension(200, 180)); JButton startbtn = new JButton("start"); startbtn.addactionlistener(e -> startthread()); JButton stopbtn = new JButton("stop"); stopbtn.addactionlistener(e -> stopthread()); setlayout(new FlowLayout()); add(startbtn); add(stopbtn); startthread(); private void startthread() { if (thread == null) { thread = new Thread(this); thread.start(); private void stopthread() { thread = null; @Override public void paintcomponent(graphics g) { super.paintcomponent(g); // paintcomponent // g.drawstring("hello, World!", x, y); public void run() { Thread thisthread = Thread.currentThread(); for (; thread == thisthread; theta += 0.02) { x = 60 + (int)(r * Math.cos(theta)); y = 100 - (int)(r * Math.sin(theta)); repaint(); // paintcomponent try { Thread.sleep(30); // 30 catch (InterruptedException e) { public static void main(string[] args) { SwingUtilities.invokeLater(() -> { JFrame frame = new JFrame("!"); frame.add(new Guruguru()); frame.pack(); frame.setvisible(true); frame.setdefaultcloseoperation(jframe.exit_on_close); ); Point.java 15

public class Point { public int x, y; public void move(int dx, int dy) { x += dx; y += dy; public double distance() { return Math.sqrt(x * x + y * y); 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",..., "white"; private String color; @Override 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 = c; return; // public ColorPoint(int x, int y, String c) { super(x, y); setcolor(c); if (color == null) color = "black"; public String getcolor() { return color; 16

2017 07 28 I. 3 3 (i). (ii). (iii). II. III. IV. (i). (ii). (iii). (iv). (i). (ii). (iii). (iv). (i). (iii). (v). (ii). (iv). 6 4 4 4 4, 3, 3, 4, 3, 6

(vi). V. 4, 4 (i). (ii).