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

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

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

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

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

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

Color.cyan, Color.yellow, Color.pink, Color.orange, Color.white, Color.black, Color.gray, Color.darkGray, Color.lightGray ; Button barray [ ] = new Bu

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

Microsoft PowerPoint prog1_doc2x.pptx

Microsoft PowerPoint prog1_doc2.pptx

Chapter 19. init paint actionperformed init if Subroutine Function init paint ( ) { } ( ) void public void init( ) { } init void void public Copyright

(Microsoft PowerPoint - \223\306\217KJAVA\221\346\202R\224\ ppt)

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

AWT setcolor, drawstring Java AWT Abstract Window Toolkit Graphics AWT import import java.awt.* ; // AWT Graphics import java.awt.graphics; // AWT Gra

AWT setcolor, drawstring Java AWT Abstract Window Toolkit Graphics AWT import import java.awt.* ; // AWT Graphics import java.awt.graphics; // AWT Gra

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 (

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

: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 2 - Lesson01

< F2D82518E9F8AD CC834F CC8CFC82AB82C68D4C>

以下に java.awt.graphics クラスの主なメソッドを示す (Graphics クラスの ) メソッド drawline(int x1, int y1, int x2, int y2) drawrect(int x, int y, int width, int height) fillr

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

: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

2008 e-learning T050050

< F2D89BA8EE882C E6A7464>

< F2D82518E9F8AD CC95BD8D7388DA93AE2E6A7464>

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

< F2D82518CC282CC D2E6A7464>

アプレットⅣ

< F2D A839382CC906A2E6A7464>

< F2D F B834E2E6A7464>

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

Microsoft PowerPoint - prog11.ppt


r3.dvi


: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

text_13.dvi

Java言語 第1回

untitled

: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

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

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

text_12.dvi

< F2D A838B838D96402E6A7464>


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

Animals サンプル Step3 張り付けた動物の上をクリックすると それぞれの鳴き声で鳴く その鳴く間 一定時間 ( ここでは 1 秒間 ) 画像が別のものに変わる <アニメーションの基礎 : タイマーについて> アニメーションは アプリケーションが指定する間 一定間隔でどんどん画像をおきかえ

< F2D BCA82CC978E89BA82CC8EC08CB12E6A7464>

< F2D825282CC947B909482CC A815B83682E6A>

Assignment_.java /////////////////////////////////////////////////////////////////////// // 課題 星の画像がマウスカーソルを追従するコードを作成しなさい 次 ///////////////////

Microsoft PowerPoint - prog11.ppt

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

< F2D834F838C A815B A CC>

< F2D E E6A7464>

< F2D B838A835882CC8CF68EAE2E6A7464>

r2.dvi

r14.dvi

アプレットの作成

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

< F2D B825082CC96E291E82E6A7464>

PowerPoint Presentation

r14.dvi

入門Java解答.doc

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

Cir

Microsoft PowerPoint - prog10.ppt

Microsoft PowerPoint - prog10.ppt

Animals サンプル Step 1 動物の種類を指定しておいて クリックした場所に画像を貼り付ける < レイアウトについて > 前回は ラベルやボタンの位置を座標で設定した Absolute Layout を選んだためである レイアウトは どのようにボタンなどのコンポーネントを配置するかを決定す

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

r3.dvi

Java講座

< F2D82B682E182F182AF82F12E6A7464>

ブロック崩し Step1 矢印キーで左右に動かせるパドルを描画する < パドルの表現方法 > パドルは java.awt パッケージの Rectangle という Java が用意しているクラスを使う これは四角形を表すクラスで 左上の点の座標と幅 高さをもっている (x, y) Rectangle

public static void main(... ) { Copyright by Tatsuo Minohara 2004 rev. Oct. 6 Macintosh Java Primer Chapter 3-2

< F2D8EA CE909482CC92EA82852E6A7464>

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

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

Alien Skin Software, LLC

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

r6.dvi

JAVA入門

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.

dynabookガイド

手書認識 グラフ描画 Step2-2 手書認識 : 認識結果を PaintPanel で描画する < 属性付き文字列 AttributedString> 標準出力では分かりにくいうえに認識結果を使えないので 認識するごとに PaintPanel に文字を描画することにする ここで 数式はただの文字列

< F2D92DE82E8914B82CC977088D32E6A7464>

問1


r4.dvi

r2.dvi

Thread

Microsoft Word 年度情報コミュニケーション実験II(Ver0.9)c.docx

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

Java3D

Microsoft Word - BouncingBall.doc

-1 new ( ) ; Rectangle Java2 AWT window = new Frame( "Sample" ); rectangle = new Rectangle( 100, 50 ); // // = new ( ) ; Frame window = new Frame( "Sa

Animals サンプル Step 2 張り付けた動物の上をクリックすると それぞれの鳴き声で鳴く < 例外について > エラーや 通常の処理の中では起こってはいけない事象のことを例外といい 例外が起こる可能性がある場合はその対応処理を記述しなければならない 一般に java.lang パッケージの

Microsoft Word - Java3.DOC

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

Transcription:

KeyListener keypressed(keyevent e) keyreleased(keyevent e) keytyped(keyevent e) MouseListener mouseclicked(mouseevent e) mousepressed(mouseevent e) mousereleased(mouseevent e) mouseentered(mouseevent e) mouseexited(mouseevent e) MouseMotionListener mousedragged(mouseevent e) mousemoved(mouseevent e) 15-1 Copyright by Tatsuo Minohara 2004 Rev. B Dec. 9th Macintosh Java Primer Chapter 15-1

KeyListener init addkeylistener addactionlistener addkeylistener addkeylistener( this ); this.addkeylistener( this ); KeyListener public void keytyped( KeyEvent e ) { public void keypressed( KeyEvent e ) { public void keyreleased( KeyEvent e ) { KEY_PRESSED keypressed KEY_RELEASED keyreleased KEY_TYPED keytyped m KEY_TYPED KEY_RELEASED Copyright by Tatsuo Minohara 2004 Rev. B Dec. 9th Macintosh Java Primer Chapter 15-2

15-1 KEY_TYPED KEY_PRESSED SHIFT SHIFT KEY_PRESSED a KEY_ PRESSED a KEY_RELEASED KEY_TYPED A public void keytyped( KeyEvent e ) { public void keypressed( KeyEvent e ) { public void keyreleased( KeyEvent e ) { getkeychar char c = e.getkeychar( ); keytyped public void keytyped( KeyEvent e ) { char c = e.getkeychar( ); System.out.println( "Input Character: " + c ); KEY_PRESSED KEY_RELEASED getkeycode int keycode = e.getkeycode( ); KeyEvent http://www.javasoft.com KeyEvent.VK_HOME KeyEvent.VK_END KeyEvent.VK_PAGE_UP KeyEvent.VK_PAGE_DOWN KeyEvent.VK_UP KeyEvent.VK_DOWN KeyEvent.VK_LEFT KeyEvent.VK_RIGHT KeyEvent.VK_CONTROL Home End Page Up Page Down Control Copyright by Tatsuo Minohara 2004 Rev. B Dec. 9th Macintosh Java Primer Chapter 15-3

KeyEvent.VK_SHIFT KeyEvent.VK_ALT KeyEvent.VK_META Shift Alt Option Meta Return Enter Backspace TAB Escape Java getkeychar Home if public void keypressed( KeyEvent e ) { int keycode = e.getkeycode( ); if ( keycode == KeyEvent.VK_HOME ) { MVC MVC paint keytyped paint keytyped keypressed, keyreleased c paint keytyped java.awt.*; java.awt.event.*; java.applet.*; public class KeyIn extends Applet implements KeyListener { char c; public void init( ) { addkeylistener( this ); c = 'A'; A g.drawstring( "Key In: " + c, 100, 100 ); public void keytyped( KeyEvent e ) { c = e.getkeychar( ); public void keypressed( KeyEvent e ) { public void keyreleased( KeyEvent e ) { Copyright by Tatsuo Minohara 2004 Rev. B Dec. 9th Macintosh Java Primer Chapter 15-4

15-2 MVC Web TAB MouseListener init addmouselistener addmouselistener( this ); // this.addmouselistener( this ); this. addmouselistener Component Applet Component Applet MouseListener public void mouseclicked( MouseEvent e ) { public void mousepressed( MouseEvent e ) { public void mousereleased( MouseEvent e ) { public void mouseentered( MouseEvent e ) { public void mouseexited( MouseEvent e ) { Copyright by Tatsuo Minohara 2004 Rev. B Dec. 9th Macintosh Java Primer Chapter 15-5

mouseclicked public void mouseclicked( MouseEvent e ) { mousepressed public void mousepressed( MouseEvent e ) { MOUSE_PRESSED MOUSE_RELEASED MOUSE_CLICKED mousepressed mousereleased mouseclicked 15-3 public void mouseclicked( MouseEvent e ) { public void mousepressed( MouseEvent e ) { public void mousereleased( MouseEvent e ) { public void mouseentered( MouseEvent e ) { public void mouseexited( MouseEvent e ) { getx gety e x y int x = e.getx( ), y = e.gety( ) ; checked true Copyright by Tatsuo Minohara 2004 Rev. B Dec. 9th Macintosh Java Primer Chapter 15-6

mouseclicked (10, 120 ) ( 40, 140 ) public void mouseclicked( MouseEvent e ) { int x = e.getx( ), y = e.gety( ); if ( x >= 10 && x <= 40 && y >= 120 && y <= 140 ) { checked = true ; else { checked = false ; x y currentx currenty paint java.awt.*; java.awt.event.*; java.applet.*; public class MouseIn extends Applet implements MouseListener { int currentx, currenty; // x y public void init( ) { addmouselistener( this ); currentx=0; currenty=0; ( 0, 0 ) g.drawstring( "Mouse Clicked At x:" + currentx + " y:" + currenty, 50, 100 ); public void mouseclicked( MouseEvent e ) { currentx = e.getx( ); currenty = e.gety( ); public void mousepressed( MouseEvent e ) { public void mousereleased( MouseEvent e ) { public void mouseentered( MouseEvent e ) { public void mouseexited( MouseEvent e ) { 15-4 MVC Copyright by Tatsuo Minohara 2004 Rev. B Dec. 9th Macintosh Java Primer Chapter 15-7

currentx currenty keypressed mouseclicked repaint mycolor mouseentered, mouseexited java.awt.*; java.applet.*; java.awt.event.*; public class BoxMover extends Applet implements KeyListener, MouseListener { int currentx, currenty; Color mycolor; public void init( ) { addkeylistener( this ); addmouselistener( this ); currentx = 100; currenty=100; mycolor = Color.red; // g.setcolor( mycolor ); g.fillrect( currentx, currenty, 50, 50 ); public void keypressed( KeyEvent e ) { switch ( e.getkeycode() ) { case KeyEvent.VK_UP: case KeyEvent.VK_DOWN: currenty -= 5; break; currenty += 5; break; currentx += 5; break; case KeyEvent.VK_RIGHT: case KeyEvent.VK_LEFT: currentx -= 5; break; default: break; public void mouseclicked(mouseevent e) { currentx = e.getx( ); currenty = e.gety( ); public void mouseentered(mouseevent e) { mycolor = Color.red; public void mouseexited(mouseevent e) { mycolor = Color.blue; public void keytyped( KeyEvent e ) { public void keyreleased( KeyEvent e ) { public void mousepressed( MouseEvent e ) { public void mousereleased( MouseEvent e ) { MouseMotionListener init addmousemotionlistener addmousemotionlistener( this ); // MouseMotionListener Copyright by Tatsuo Minohara 2004 Rev. B Dec. 9th Macintosh Java Primer Chapter 15-8

public void mousedragged( MouseEvent e ) { public void mousemoved( MouseEvent e ) { public void mousedragged( MouseEvent e ) { public void mousemoved( MouseEvent e ) { mousepressed startx starty MOUSE_CLICKED mouseclicked MOUSE_PRESSED mousepressed mousedragged endx endy java.awt.*; java.awt.event.*; java.applet.*; public class LineDraw extends Applet implements MouseListener, MouseMotionListener { int startx, starty, endx, endy; x,y public void init( ) { addmouselistener( this ); addmousemotionlistener( this ); startx=0; starty=0; endx=0; endy=0; g.drawline( startx, starty, endx, endy ); // 0 // public void mousepressed( MouseEvent e ) { startx = e.getx( ); starty = e.gety( ); endx = e.getx( ); endy = e.gety( ); Copyright by Tatsuo Minohara 2004 Rev. B Dec. 9th Macintosh Java Primer Chapter 15-9

public void mousedragged( MouseEvent e ) { endx = e.getx( ); endy = e.gety( ); public void mouseclicked( MouseEvent e ) { public void mousereleased( MouseEvent e ) { public void mouseentered( MouseEvent e ) { public void mouseexited( MouseEvent e ) { public void mousemoved( MouseEvent e ) { 15-5 MVC paint drawrect if else if x y endx endy endx starty startx endy startx starty (startx, starty) 15-6 (endx, endy) Copyright by Tatsuo Minohara 2004 Rev. B Dec. 9th Macintosh Java Primer Chapter 15-10

paint LineDraw if ( startx>endx && starty>endy ) { // g.drawrect( endx, endy, startx - endx, starty - endy ); else if ( startx>endx ) { // g.drawrect( endx, starty, startx - endx, endy - starty ); else if ( starty>endy ) { // else { g.drawrect( startx, endy, endx - startx, starty - endy ); // g.drawrect( startx, starty, endx - startx, endy - starty ); 10 startx starty endx endy x y current paint 10 current 0 java.awt.*; java.awt.event.*; java.applet.*; public class LineDrawer extends Applet implements MouseListener, MouseMotionListener { int startx [] = new int[ 10 ], starty [] = new int[ 10 ]; int endx [] = new int[ 10 ], endy[] = new int[ 10 ]; int current = 0; public void init( ) { addmouselistener( this ) ; addmousemotionlistener( this ); for ( int i=0; i<current; i++ ) { g.drawline( startx[ i ], starty[ i ], endx[ i ], endy[ i ] ); public void mousepressed( MouseEvent e ) { if ( current >= startx.length ) { current = 0; startx[ current ] = e.getx( ); starty[ current ] = e.gety( ); endx[ current ] = e.getx( ); endy[ current ] = e.gety( ); current++; repaint(); public void mousedragged( MouseEvent e ) { endx[ current-1 ] = e.getx( ); endy[ current-1 ] = e.gety( ); repaint(); public void mouseclicked( MouseEvent e ) { public void mousereleased( MouseEvent e ) { public void mouseentered( MouseEvent e ) { public void mouseexited( MouseEvent e ) { Copyright by Tatsuo Minohara 2004 Rev. B Dec. 9th Macintosh Java Primer Chapter 15-11

public void mousemoved( MouseEvent e ) { 15-7 10 Modifier Key Meta ALT Shift Control Ctrl Left/Right Macintosh Command Windows Macintosh Option InputEvent isshiftdown( ) iscontroldown( ) ismetadown( ) isaltdown( ) ALT true false if if if ( e.isshiftdown( ) == true ) {... if ( e.isshiftdown( ) ) {... shape int shape ; // Copyright by Tatsuo Minohara 2004 Rev. B Dec. 9th Macintosh Java Primer Chapter 15-12

paint shape paint if ( startx>endx && starty>endy ) { // if ( shape == 1 ) { g.drawrect( endx, endy, startx - endx, starty - endy ); else if ( shape == 2 ) { g.fill3drect( endx, endy, startx - endx, starty - endy, true ); else if ( shape == 3 ) { g.drawoval( endx, endy, startx - endx, starty - endy ); else { g.drawline( startx, starty, endx, endy ); else if ( startx>endx ) {... mousepressed shape shape public void mousepressed( MouseEvent e ) { currentx = e.getx( ); currenty = e.gety( ); shape = ( e.isshiftdown( ) )? 1 : ( e.iscontroldown( ) )? 2 : ( e.ismetadown( ) )? 3 : 4; Macintosh Macintosh Macintosh Web getclickcount public void mouseclicked( MouseEvent e ) { int count = e.getclickcount( ); if ( count == 1 ) { System.out.println( "Single Clicked" ); else if ( count == 2 ) { System.out.println( "Double Clicked" ); Copyright by Tatsuo Minohara 2004 Rev. B Dec. 9th Macintosh Java Primer Chapter 15-13

java.awt.*; java.awt.event.*; java.applet.*; public class KeyIn extends Applet implements KeyListener, ActionListener { Button button; int size = 10; char c = 'A'; public void init( ) { button = new JButton( "Large" ); button.addactionlistener( this ); add( button ); addkeylistener( this ); requestfocus( ); g.setfont( new Font( "Serif", Font.PLAIN, size ) ); g.drawstring( "Key In: " + c, 50, 50 ); public void actionperformed( ActionEvent e ) { size = ( size - 10 + 2 ) % 100 + 10; // 10 requestfocus( ); // public void keytyped( KeyEvent e ) { c = e.getkeychar( ); public void keypressed( KeyEvent e ) { public void keyreleased( KeyEvent e ) { 15-1 switch 200 15-2 RGB Red: 255 Green: 255 Blue: 255 Copyright by Tatsuo Minohara 2004 Rev. B Dec. 9th Macintosh Java Primer Chapter 15-14

15-3 ShapeDrawer 15-4 PolylineDrawer 15-5 BezierDrawer 15-6 15-7 SplineDrawer Copyright by Tatsuo Minohara 2004 Rev. B Dec. 9th Macintosh Java Primer Chapter 15-15