text_13.dvi

Similar documents
text_12.dvi

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

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

text_10.dvi

< F2D82518E9F8AD CC834F CC8CFC82AB82C68D4C>

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

< F2D89BA8EE882C E6A7464>

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

< F2D82518CC282CC D2E6A7464>

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;

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

< F2D A839382CC906A2E6A7464>

Java言語 第1回

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

< F2D82518E9F8AD CC95BD8D7388DA93AE2E6A7464>

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

< F2D834F838C A815B A CC>

< F2D B838A835882CC8CF68EAE2E6A7464>

< F2D F B834E2E6A7464>

< F2D825282CC947B909482CC A815B83682E6A>

< F2D BCA82CC978E89BA82CC8EC08CB12E6A7464>

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

ガイダンス

< F2D A838B838D96402E6A7464>

ガイダンス

ガイダンス

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


< F2D82B682E182F182AF82F12E6A7464>

< F2D E E6A7464>

< F2D B825082CC96E291E82E6A7464>

r14.dvi

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

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

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

<4D F736F F F696E74202D AC C8899E D834F E >

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

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


Thread

Object MenuComponent MenuBar MenuItem Menu CheckboxMenuItem

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

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

awt の主要なクラスを下記に示す クラス Component Container Button Label Panel Frame 説明画面にユーザインターフェイス要素として表示し, ユーザとのやり取りを行うコンポーネントを表すすべてのコンポーネントのスーパークラスになる ほかのコンポーネントを含

< F2D92DE82E8914B82CC977088D32E6A7464>

< F2D8EA CE909482CC92EA82852E6A7464>

任意の加算プログラム

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.

Microsoft PowerPoint - prog11.ppt

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

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

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

r8.dvi

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

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

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

r6.dvi

Microsoft PowerPoint - prog11.ppt

Microsoft PowerPoint - prog12.ppt

LMNtal LMNtal LMNtal JAVA JAVA JAVA LMNtal LMNtal LMNtal

Java言語 第1回

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

Microsoft PowerPoint - OOP.pptx

アプレットの作成

問1

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

2

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

Prog1_12th

Microsoft PowerPoint prog1_doc2x.pptx

......() JButton

untitled

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

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

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

ガイダンス

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

Microsoft Word - Java4.DOC

: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

ガイダンス

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

自宅でJava言語の開発環境を作る方法

Microsoft PowerPoint - swing2.ppt

GUIプログラムⅣ

Prog1_12th

r2.dvi

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

Microsoft PowerPoint prog1_doc2.pptx

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

ソフトウェア基礎演習 課題

Transcription:

C 13 2000 7 9

13 Java(8) { Swing(2)(, ) 1 13.1 13 : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : 1 13.2 : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : 1 13.2.1 : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : 1 13.2.2 : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : 1 13.2.3 : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : 3 13.2.4 : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : 4 13.3 : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : 7 13.3.1 : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : 7 13.3.2 : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : 10 13.4 : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : 14 {i{

13 Java(8) { Swing(2)(, ) 13.1 13 12 Swing 13 13.2 Swing 13.2.1 (label) JLabel JLabel 1 public JLabel() public JLabel( String text ) public JLabel( String text, int alignment ) text alignment JLabel.LEFT JLabel.CENTER JLabel.RIGHT // // // 13.2.2 (button) JButton JButton 1 1

2 public JButton() public JButton( String text ) 1 2 text JButton ActionEvent // ButtonAction.java import javax.swing.* import java.awt.* public class ButtonAction extends JFrame { ButtonAction() { super( "Button Action" ) Container mycontainer = getcontentpane() JButton mybutton = new JButton( "Button" ) mycontainer.add( mybutton ) setsize( 150, 100 ) setvisible( true ) // // // // // // mybutton.addactionlistener( new ActListener2( mybutton ) ) // addwindowlistener( new WinAdapter() ) // // main public static void main( String [] args ) { ButtonAction buttonaction = new ButtonAction() // WinAdapter.java // import java.awt.event.* public class WinAdapter extends WindowAdapter { public void windowclosing( WindowEvent we ) { System.exit( 0 ) // 2 2

// ActListener2.java import javax.swing.* import java.awt.event.* public class ActListener2 implements ActionListener { JButton button // boolean fbutton = true // ActListener2( JButton button ) { this.button = button // public void actionperformed( ActionEvent ae ) { if( fbutton ) { button.settext( "Press" ) // fbutton = false // else { button.settext( "Button" ) // fbutton = true // 12 MyActionEvent.java 12 settext JComponent Swing JComponent 13.2.3 (check box) 3 public JCheckBox() public JCheckBox( String text ) public JCheckBox( String text, boolean selected ) text selected true JCheckBox setselected( boolean selected ) JCheckBox ItemEvent ItemListener itemstatechanged 3 JLabel JButton 3

13.2.4 (text eld) 1 public JTextField() public JTextField( String text ) public JTextField( int column ) public JTextField( String text, int column ) text column JTextField Return ( Enter ) ActionEvent 12 MyActionEvent.java ActionListener actionperformed 12 MyChoice.java // TextCheckEvent.java import javax.swing.* import java.awt.* import java.awt.event.* public class TextCheckEvent extends JFrame implements ItemListener, ActionListener { JCheckBox c1, c2 JLabel l4 TextCheckEvent() { super( "TextCheckEvent" ) Container mycontainer = getcontentpane() mycontainer.setlayout( new BorderLayout() ) // p1 JPanel p1 = new JPanel( new FlowLayout() ) JLabel l1 = new JLabel( "Your name please." ) JTextField t = new JTextField( 20 ) p1.add( l1 ) p1.add( t ) // p2 JPanel p2 = new JPanel( new BorderLayout() ) JLabel l2 = new JLabel( "Make sure your choice." ) c1 = new JCheckBox( "OxfordAdvanced Learner's Dictionary" ) c2 = new JCheckBox( "Longman Language Activator" ) p2.add( l2, BorderLayout.NORTH ) p2.add( c1, BorderLayout.CENTER ) p2.add( c2, BorderLayout.SOUTH ) // p3 ( p4 l4) JPanel p3 = new JPanel( new BorderLayout() ) // p4 JPanel p4 = new JPanel( new FlowLayout() ) ( ) 4

JLabel l3 = new JLabel( "Are you sure?" ) JButton b1 = new JButton( "Yes, I am." ) JButton b2 = new JButton( "No, I'm not." ) p4.add( l3 ) p4.add( b1 ) p4.add( b2 ) // l4 l4 = new JLabel( " " ) p3.add( p4, BorderLayout.NORTH ) p3.add( l4, BorderLayout.SOUTH ) // p4 // l4 mycontainer.add( p1, BorderLayout.NORTH ) mycontainer.add( p2, BorderLayout.CENTER ) mycontainer.add( p3, BorderLayout.SOUTH ) // p1 // p2 // p3 pack() setvisible( true ) // // t.addactionlistener( this ) c1.additemlistener( this ) c2.additemlistener( this ) // addwindowlistener( new WinAdapter() ) // public void actionperformed( ActionEvent ae ) { l4.settext( ae.getactioncommand() ) // public void itemstatechanged( ItemEvent ie ) { if( ie.getitemselectable() == c1 ) { if( c1.isselected() ) l4.settext( "You checked Oxford." ) else l4.settext( "You checked Oxford off." ) else { if( c2.isselected() ) l4.settext( "You checked Longman." ) else l4.settext( "You checked Longman off." ) // main public static void main( String [] args ) { TextCheckEvent textcheckevent = new TextCheckEvent() 12 MyChoice.java ItemEvent ActionEvent TextCheckEvent JFrame ItemListener ActionListener this t c1 c2 5

l4 ActionEvent getactioncommand 4 l4 ItemEvent getitemselectable isselected getactioncommand JTextField gettext 13-1 TextCheckEvent.java \Yes, I am." <name> selects <dic> <name> <dic> \No, I'm not." 13-2 JTextField 13.1 5 13.1: 4 5 4 1 100 1 400 1 6

13.3 13.3.1 Swing JComponent JComponent Swing paintcomponent Graphics void setcolor( Color c ) c void drawstring( String text, int x, int y ) text (x, y) void drawline( int x1, int y1, int x2, int y2 ) (x1, y1) (x2, y2) void drawrect( int x, int y, int w, int h ) (x, y) w h void fillrect( int x, int y, int w, int h ) void clearrect( int x, int y, int w, int h ) void drawoval( int x, int y, int w, int h ) (x, y) w h ( ) void filloval( int x, int y, int w, int h ) ( ) void drawarc( int x, int y, int w, int h, int deg0, int deg1 ) (x, y) w h deg0 deg1 void fillarc( int x, int y, int w, int h, int deg0, int deg1 ) void drawpolygon( int [] x, int [] y, int n ) x y n void fillpolygon( int [] x, int [] y, int n ) void drawpolyline( int [] x, int [] y, int n ) x y n 7

Color Color public Color( int red, int green, int blue ) public Color( int rgb ) public Color( float r, float g, float b ) (red) (green) (blue) 0 255 int 2 rgb 23 16 15 8 7 0 16 3 (r) (g) (b) 0.0f 1.0f float Color 13.1 13.1: Color black yellow white orange red pink gree darkgray blue gray cyan lightgray magenta // MyDraw.java import javax.swing.* import java.awt.* public class MyDraw extends JComponent { MyDraw() { setpreferredsize( new Dimension( 300, 300 ) ) // paintcomponent public void paintcomponent( Graphics g ) { super.paintcomponent( g ) g.setcolor( Color.blue ) g.drawstring( "Graphics objects.", 50, 50 ) g.setcolor( Color.yellow ) g.drawoval( 10, 70, 80, 80 ) g.setcolor( Color.green ) g.fillrect( 100, 100, 150, 50 ) g.setcolor( Color.red ) g.fillarc( 50, 150, 200, 200, 0, 60 ) // // // // // // // 8

// DrawTest.java import javax.swing.* import java.awt.* import java.awt.event.* public class DrawTest extends JFrame { public DrawTest() { // super( "DrawTest" ) Container mycontainer = getcontentpane() MyDraw mydraw = new MyDraw() mycontainer.add( mydraw ) // // addwindowlistener( new WinAdapter() ) pack() setvisible( true ) // main public static void main( String [] args ) { DrawTest DrawTest = new DrawTest() DrawTest 13.2 13.2: DrawTest MyDraw JComponent MyDraw 6 6 (component) 9

setpreferredsize setpreferredsize Dimension Dimension paintcomponent Graphics super.paintcomponent( g ) paintcomponent paintcomponent paintcomponent paintcomponent paintcomponent DrawTest MyDraw 13.3.2 // DrawSine.java import javax.swing.* import java.awt.* public class DrawSine extends JComponent { int startx DrawSine() { startx = 0 setpreferredsize( new Dimension( 360, 200 ) ) // // paintcomponent public void paintcomponent( Graphics g ) { super.paintcomponent( g ) // g.drawline( 0, 100, 360, 100 ) // // int [] xpoints = new int [37] int [] ypoints = new int [37] // for( int i = 0 i < xpoints.length i++ ) { xpoints[i] = i * 10 ypoints[i] = (int)(100-100*math.sin( 2*Math.PI*(startX+i)/36 )) // g.setcolor( Color.red ) g.drawpolyline( xpoints, ypoints, xpoints.length ) ( ) 10

// void move() { Graphics g = getgraphics() // Graphics for( int i = 0 i < 20 i++ ) { // g.clearrect( 0, 0, getwidth(), getheight() ) startx-- update( g ) // // // try { Thread.sleep( 50 ) catch( Exception e ) { e.printstacktrace() // void reset() { startx = 0 // startx repaint() // // DrawAction.java import javax.swing.* import java.awt.* import java.awt.event.* public class DrawAction extends JFrame implements ActionListener { DrawSine drawsine // public DrawAction() { super( "DrawAction" ) Container mycontainer = getcontentpane() // drawsine = new DrawSine() // JPanel panel = new JPanel( new FlowLayout() ) JButton move = new JButton( "MOVE" ) JButton reset = new JButton( "RESET" ) JButton exit = new JButton( "EXIT" ) panel.add( move ) panel.add( reset ) panel.add( exit ) ( ) 11

// mycontainer.add( drawsine, BorderLayout.NORTH ) mycontainer.add( panel, BorderLayout.SOUTH ) // move.addactionlistener( this ) reset.addactionlistener( this ) exit.addactionlistener( this ) addwindowlistener( new WinAdapter() ) pack() setvisible( true ) // public void actionperformed( ActionEvent ae ) { if( ae.getactioncommand().equals( "MOVE" ) ) drawsine.move() else if( ae.getactioncommand().equals( "RESET" ) ) drawsine.reset() else System.exit( 0 ) // main public static void main( String [] args ) { DrawAction drawaction = new DrawAction() MOVE RESET EXIT 3 MOVE RESET EXIT DrawSine startx paintcomponent startx MOVE DrawSine move Graphics getgraphics paintcomponent startx update JComponent update reset startx repaint 12

13-3 JTextField 3 2x Physical = sin 23 2x Sympathy = sin 28 2x Intellectual = sin 33 x 13.3 13.3: 13

13.4 2 1. TextCheckEvent.java \Yes, I am." <name> selects <dic> <name> <dic> \No, I'm not." ( 13-1) 2. JTextField 13.1 ( 13-2) 3. JTextField 3 2x Physical = sin 23 2x Sympathy = sin 28 2x Intellectual = sin 33 x 13.3 ( 13-3) 2 1. Swing 2. /usr/local4/doc/softabc_2001/softc_psfiles/data/hatena.class 3. DrawSine.java DrawSine.java 4. 1) 3 Java,, 14

2) JAVA,, Patrick Niemeyer & Joshua Peck, 3) Java,, Paul Tyma, Gabriel Torok, & Troy Downing, 4) Java,, 5) JAVA,, David Flanagan, 6) JAVA,, Nathan Gurewich & Ori Gurewich, 7) Internet Language Java,, 8) Java,, Laura Lemay, & Charles L. Perkins,, &, & 9) JAVA2,, 10) Java,, Joseph O'Neil, 11) Java Swing,, Satyaraj Pantham, 12) Swing Java GUI,, 13) Swing Java GUI II,, 14) Swing Java GUI III,, 15) Java Swing Black Book,, Steven Holzner & 16) JBuilder Java,, 15