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

Similar documents
Color frontcolor; // Color Graphics gc; // Graphics Frame window; // Frame Java 8-1 new ( ) ; Rectangle Java2 AWT window = new Frame( "Sample" ); rect

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

untitled

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

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

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

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

public static void main(... ) { Copyright by Tatsuo Minohara 2004 rev. Oct. 6 Macintosh Java Primer Chapter 3-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

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

< F2D82518E9F8AD CC95BD8D7388DA93AE2E6A7464>

< F2D82518E9F8AD CC834F CC8CFC82AB82C68D4C>

< F2D E E6A7464>

< F2D89BA8EE882C E6A7464>

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

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

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.

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

< F2D B825082CC96E291E82E6A7464>

< F2D A839382CC906A2E6A7464>

JAVA入門

< F2D A838B838D96402E6A7464>

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

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

Microsoft PowerPoint prog1_doc2.pptx

untitled

Microsoft PowerPoint prog1_doc2x.pptx

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

CONTENTS

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

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

< F2D82518CC282CC D2E6A7464>

アプレットⅠ

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

K227 Java 2

text_13.dvi

<4D F736F F F696E74202D AC C8899E D834F E >

< F2D834F838C A815B A CC>

< F2D B838A835882CC8CF68EAE2E6A7464>

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

Microsoft PowerPoint - prog10.ppt

2 1 Web Java Android Java 1.2 6) Java Java 7) 6) Java Java (Swing, JavaFX) (JDBC) 7) OS 1.3 Java Java

Microsoft PowerPoint - prog10.ppt

r3.dvi

< F2D825282CC947B909482CC A815B83682E6A>

r6.dvi

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;

< F2D82B682E182F182AF82F12E6A7464>

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

r2.dvi

6-1

< F2D92DE82E8914B82CC977088D32E6A7464>

アプレットⅤ

新・明解Java入門

text_08.dvi

< F2D8EA CE909482CC92EA82852E6A7464>

< F2D F B834E2E6A7464>

アプレットの作成

r2.dvi

Microsoft Word - keisankigairon.ch doc

Microsoft PowerPoint ppt

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

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

presen.gby

8 if switch for while do while 2

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

Microsoft PowerPoint ppt

untitled

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

untitled

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

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

JavaScript の使い方

: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言語 第1回

PowerPoint Presentation

< F2D BCA82CC978E89BA82CC8EC08CB12E6A7464>

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

web用広報1月号-Vol.178.indd

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回

新・明解Javaで学ぶアルゴリズムとデータ構造

r3.dvi

2

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

明解Java入門編

Java (7) Lesson = (1) 1 m 3 /s m 2 5 m 2 4 m 2 1 m 3 m 1 m 0.5 m 3 /ms 0.3 m 3 /ms 0.6 m 3 /ms 1 1 3

AJANコマンドリファレンス(GUIコマンド編)

web広報7月号-Vol.172.indd

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

10K

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

r4.dvi

新・明解Javaで学ぶアルゴリズムとデータ構造

住まい・まちづくり活動事例集

Object MenuComponent MenuBar MenuItem Menu CheckboxMenuItem

Transcription:

Template Instance Java new ; Frame Color AWT new Frame( "Sample" ); // Sample new Color( 244, 33, 111 ); // RGB 244, 33, 111 new Constructor ; Color frontcolor; // Color Graphics g; // Graphics Frame window; // Frame Java Copyright by Tatsuo Minohara 2004 Nov. 11th Macintosh Java Primer Chapter 11-1

-1 new ( ) ; Rectangle Java2 AWT window = new Frame( "Sample" ); rectangle = new Rectangle( 100, 50 ); // // = new ( ) ; Frame window = new Frame( "Sample", 400, 200 ); Graphics g = new Graphics( ); ( ) ; Frame Graphics window.show( ); // Frame show Copyright by Tatsuo Minohara 2004 Nov. 11th Macintosh Java Primer Chapter 11-2

gc.drawstring( "Hello!", 110, 45 ); // Graphics drawstring = ( ) ; Color c int red ; red = c.getred( ); -2 Graphics g myfont mycolor Font myfont; Color mycolor; myfont = g.getfont( ); mycolor = g.getcolor( ); // getfont // getcolor gc.setcolor( new Color( 12, 22, 33 ) ); gc.setfont( new Font( "Serif", Font.BOLD, 12 ) ); // // Color temporal; temporal = new Color( 12, 22, 33 ); gc.setcolor( temporal ); Copyright by Tatsuo Minohara 2004 Nov. 11th Macintosh Java Primer Chapter 11-3

. Color mycolor = gc.getcolor( ); int red = mycolor.getred( ); int red = (gc.getcolor( )).getred( ); // gc.getcolor( ).getred( ) Lisp, Smalltalk, Java, Visual Basic AppleScript Garbage Collect new Applet( ) Netscape Internet Explorer main AWT AWT Java RGB RGB Red Green Blue 0 255 256 2563 =1677 Copyright by Tatsuo Minohara 2004 Nov. 11th Macintosh Java Primer Chapter 11-4

-3 RGB RGB Name RGB Name RGB Color.white 255, 255, 255 Color.gray 128, 128, 128 Color.black 0, 0, 0 Color.darkGray 64, 64, 64 Color.lightGray 192, 192, 192 Color.red 255, 0, 0 Color.magenta 255, 0, 255 Color.green 0, 255, 0 Color.cyan 0, 255, 255 Color.blue 0, 0, 255 Color.pink 255, 175, 175 Color.yellow 255, 255, 0 Color.orange 255, 200, 0 new Color(,, ) 0 255 0.0f 1.0f Color Color = new Color(,, ); Color darkred = new Color( 189, 0, 0 ); // Color lightgreen = new Color( 1.0f, 0.2f, 0.2f ); // new Color(,,, ) 0 255 0.0f 1.0f Color darkred = new Color( 189, 0, 0, 232 ); // Color lightgreen = new Color( 1.0f, 0.2f, 0.2f, 0.1f ); // Copyright by Tatsuo Minohara 2004 Nov. 11th Macintosh Java Primer Chapter 11-5

Graphics setcolor setcolor( ); g Graphics Color mycolor = new Color( 140, 140, 200 ); // g.setcolor( mycolor ); // g.setcolor( new Color( 140, 140, 200 ) ); // Graphics getcolor Color RGB getred getgreen getblue Color mycolor = g.getcolor( ); int red = mycolor.getred( ); // red int green = mycolor.getgreen( ); // green int blue = mycolor.getblue( ); // blue int alpha = mycolor.getalpha( ); // 0 16 0 270 270 blue red x y import java.awt.*; import java.applet.*; public void paint( Graphics g ) { for ( int blue=0; blue<256 ; blue += 16 ) { for ( int red=0 ; red < 256 ; red += 16 ) { Color mycolor = new Color( red, 0, blue ); g.setcolor( mycolor ); g.fill3drect( blue+30, red+30, 14, 14, true ); } } } Copyright by Tatsuo Minohara 2004 Nov. 11th Macintosh Java Primer Chapter 11-6

-4 RGB Cyan Magenta Yellow black CMYK RGB RGB Font Typeface Java new Font(,, ) Xerox Alto Macintosh Unix Windows Font Family JDK1.0 JDK1.1 JDK1.1 Java2 JDK1.1 JDK1.0 JDK1.1 TimesRoman Serif ABCDEFGHIJKLMNabcdefghijklmn012345 Helvetica SansSerif ABCDEFGHIJKLMNabcdefghijklmn012345 Courier MonoSpaced ABCDEFGHIJKLMNabcdefghijklmn012345 Copyright by Tatsuo Minohara 2004 Nov. 11th Macintosh Java Primer Chapter 11-7

JDK1.0 JDK1.1 TimesRoman Helvetica Courier Serif -5 Sans without Courier Courier JDK1.1 MonoSpaced Courier Propotional Fixed MonoSpaced -6 Dialog DialogInput Symbol Java Font.PLAIN Typography Font.BOLD Typography Font.ITALIC Typography Font.BOLD+Font.ITALIC Typography 1/72 0.35mm Scalable 128 Copyright by Tatsuo Minohara 2004 Nov. 11th Macintosh Java Primer Chapter 11-8

-7 Graphics setfont g.setfont( ); Font myfont = new Font( "Serif", Font.ITALIC, 24 ); g.setfont( myfont ); g.setfont( new Font( "Serif", Font.ITALIC, 24 ) ); g.drawstring( "A big message for you", 10, 100 ); Graphics getfont Font getname getstyle getsize Font myfont = g.getfont( ); String fontname = myfont.getname( ); // int style = myfont.getstyle( ); // int size = myfont.getsize( ); // FontMetrics Copyright by Tatsuo Minohara 2004 Nov. 11th Macintosh Java Primer Chapter 11-9

-8 Baseline Ascent Descent Height Leading FontMetrics getascent( ) getdescent( ) getheight( ) getleading( ) stringwidth( ) FontMetrics Applet Graphics getfontmetrics getfontmetrics Applet getfontmetrics( ) getfontmetrics( ) Graphics Message width FontMetrics metrics = g.getfontmetrics( ); int width = metrics.stringwidth( "Message" ); Graphics gc FontMetrics getfontmetrics 12 SansSerif Helvetica height Font myfont = new Font( "SansSerif", Font.BOLD, 12 ); FontMetrics metrics = getfontmetrics( myfont ); int height = metrics.getheight( ); Font myfont = new Font( "SansSerif", Font.BOLD, 12 ); int height = (getfontmetrics( myfont )).getheight( ); Font Typeface Font Typeface Copyright by Tatsuo Minohara 2004 Nov. 11th Macintosh Java Primer Chapter 11-10

Adobe Type 1 Java2 Adobe Type 1 JDK 1.0 JDK 1.1 Netscape Internet Explorer Java Dialog Typography Oblique Calendar java.util Calendar Calendar cal Calendar cal = Calendar.getInstance( ); Calendar cal = new GregorianCalendar( TimeZone.getTimeZone("JST") ); GregorianCalendar Calendar BC 4,716 AD 5,000,000 UTC TimeZone TimeZone gettimezone JST Japan Standard Time Java1.1 Java2 GMT Greenwich Mean Time UTC Universal Time Coordinated (GMT) ECT Europe Central Time (GMT+01) EET Europe Eastern Time (GMT+02) ART Arabic Egypt Standard Time (GMT+02) EAT Eastern African Time (GMT+03) MET Middle East Time (GMT+03:30) NET Near East Time (GMT+04) PLT Pakistan Lahore Time (GMT+05) IST India Standard Time (GMT+05:30) BST Bangladesh Standard Time (GMT+06) VST Vietnam Standard Time (GMT+07) CTT China Taiwan Time (GMT+08) JST Japan Standard Time (GMT+09) ACT Australia Central Time (GMT+09:30) AET Australia Eastern Time (GMT+10) SST Solomon Standard Time (GMT+11) NST New Zealand Standard Time (GMT+12) MIT Midway Islands Time (GMT-11) HST Hawaiian Standard Time (GMT-10) Copyright by Tatsuo Minohara 2004 Nov. 11th Macintosh Java Primer Chapter 11-11

AST Alaska Standard Time (GMT-09) PST Pacific Standard Time (GMT-08) PNT Phoenix Standard Time (GMT-07) MST Mountain Standard Time (GMT-07) CST Central Standard Time (GMT-06) EST Eastern Standard Time (GMT-05) IET Indiana Eastern Standard Time (GMT-05) PRT Puerto Rico Time (GMT-04) CNT Canada Newfoundland Time (GMT-03:30) AGT Argentina Standard Time (GMT-03) BET Brazil Eastern Time (GMT-03) CAT Central African Time (GMT-1) Java JDK1.3 GMT [ ] hh mm GMT[+ -]hh[:mm] GMT12 GMT-04 GMT+09:00 Calendar cal get int year = cal.get( Calendar.YEAR ); // int month = cal.get( Calendar.MONTH ) + 1; // 0 11 +1 int weekofyear = cal.get( Calendar.WEEK_OF_YEAR ); // int weekofmonth = cal.get( Calendar.WEEK_OF_MONTH ); // 1 int dayofyear = cal.get( Calendar.DAY_OF_YEAR ); // 1 int day = cal.get( Calendar.DATE ); // 1 int dayofweek = cal.get( Calendar.DAY_OF_WEEK ); // 1 7 int ampm = cal.get( Calendar.AM_PM ); // 0 1 int hour = cal.get( Calendar.HOUR ); // 0 12 int dayhour = cal.get( Calendar.HOUR_OF_DAY ); // 0 23 int minute = cal.get( Calendar.MINUTE ); // 0 59 int second = cal.get( Calendar.SECOND ); // 0 59 int millisecond = cal.get( Calendar.MILLISECOND ); // 0 999 Calendar.DATE Calendar.DAY_OF_MONTH Calendar java.util import import java.util.*; // java.util public class CurrentDisplay { public static void main( String [ ] args ) { Calendar cal = new GregorianCalendar( TimeZone.getTimeZone("JST") ); System.out.println( "Year: " + cal.get( Calendar.YEAR ) + " Month: " + ( cal.get( Calendar.MONTH )+1 ) + " Day: " + cal.get( Calendar.DATE ) ); int weekday = cal.get( Calendar.DAY_OF_WEEK ) ; if ( weekday == 1 ) { System.out.println( "Sunday" ); } else if ( weekday == 2 ) { System.out.println( "Monday" ); } else if ( weekday == 3 ) { System.out.println( "Tuesday" ); } else if ( weekday == 4 ) { System.out.println( "Wednesday" ); } else if ( weekday == 5 ) { System.out.println( "Thursday" ); } else if ( weekday == 6 ) { System.out.println( "Friday" ); } else { System.out.println( "Saturday" ); } if ( cal.get( Calendar.AM_PM ) == 0 ) { System.out.print( "AM " ); } else { System.out.print( "PM " ); } System.out.println( cal.get( Calendar.HOUR ) + ":" + cal.get( Calendar.MINUTE ) Copyright by Tatsuo Minohara 2004 Nov. 11th Macintosh Java Primer Chapter 11-12

} } + ":" + cal.get( Calendar.SECOND ) ); Calendar clear set 0 23 set(,, ) set(,,,, ) set(,,,,, ) 9 0 10 Calendar cal = new GregorianCalendar( TimeZone.getTimeZone("JST") ); cal.clear( ); // cal.set( 2000, 9, 1 ); cal.set( 2000, 9, 1, 14, 12 ); cal.set( 2000, 9, 1, 14, 12, 45 ); Date // 2000 10 1 // 2000 10 1 14 12 // 2000 10 1 14 12 45 Calendar Data gettime Date caldate = cal.gettime( ); Data System.out.println( caldate.tostring( ) ); System.out.println( caldate ); Data 1970 gettime long Calendar gettime Date gettime 1000 60 60 long millisecond = cal.gettime( ).gettime( ); // Date gettime Copyright by Tatsuo Minohara 2004 Nov. 11th Macintosh Java Primer Chapter 11-13

Date caldate = cal.gettime( ); long millisecond = caldate.gettime( ); start now 1000 second do while do while import java.util.*; public class WaitMinute { public static void main( String [ ] args ) { Calendar origin = new GregorianCalendar( TimeZone.getTimeZone("JST") ); long start = origin.gettime( ).gettime( ); long second = 0; } do { Calendar current = new GregorianCalendar( TimeZone.getTimeZone("JST") ); long now = current.gettime( ).gettime( ); if ( (now - start) / 1000 > second ) { // second = (now - start)/1000; System.out.println( second + " seconds" ); } second = (now - start)/1000; } while ( second < 60 ) ; // Active Waiting 100,000 11-1. 0 255 11-2. 9 36 FontListing 11-3. 18 HetroFont This is a TimesRoman, and Helvetica and Courier. 11-4. 24 30 CurrentTime Copyright by Tatsuo Minohara 2004 Nov. 11th Macintosh Java Primer Chapter 11-14