1 Java Java Java2 Java 1000 Java C Java C C C Java C 14 Java Java2 Java RMI Java 15 Java C++ C++ C C Java Java P. Naughton H. Schildt



Similar documents
Object MenuComponent MenuBar MenuItem Menu CheckboxMenuItem

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

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

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

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

text_12.dvi

新・明解Java入門

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

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 HTML HashMap (i) (ii) :.java import java.net.*; import java.io.*; import java.util.hashmap; public class SimpleStopWatch { public static voi

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.

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

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

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

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

Microsoft Word - Java3.DOC

アプレットの作成

JAVA入門

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

untitled

GUIプログラムⅤ

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

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

K227 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

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

text_13.dvi

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

r4.dvi

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

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

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

r1.dvi

< F2D82518CC282CC D2E6A7464>

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

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

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

r2.dvi

2008 e-learning T050050

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

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

アプレットⅣ

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

Microsoft PowerPoint ppt

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

Microsoft PowerPoint - prog11.ppt

< F2D E E6A7464>

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

< F2D825282CC947B909482CC A815B83682E6A>

< F2D F B834E2E6A7464>

Microsoft PowerPoint prog1_doc2x.pptx

< F2D82B682E182F182AF82F12E6A7464>

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

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

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

< F2D BCA82CC978E89BA82CC8EC08CB12E6A7464>

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

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

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

Microsoft PowerPoint - prog11.ppt

< F2D92DE82E8914B82CC977088D32E6A7464>

Microsoft PowerPoint - prog10.ppt

r3.dvi

Microsoft PowerPoint - prog10.ppt

解きながら学ぶJava入門編

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 (

Thread

< F2D834F838C A815B A CC>

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

2

< F2D B838A835882CC8CF68EAE2E6A7464>

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

Java言語 第1回

Microsoft PowerPoint prog1_doc2.pptx

< F2D B825082CC96E291E82E6A7464>

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

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

Vector Vector Vector Vector() Vector(int n) n Vector(int n,int delta) n delta

Java言語 第1回


r2.dvi

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

< F2D82518E9F8AD CC834F CC8CFC82AB82C68D4C>

GUIプログラムⅣ

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

PowerPoint Presentation

: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

Microsoft PowerPoint - OOP.pptx

Java updated

Microsoft PowerPoint ppt

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;

r8.dvi

PowerPoint プレゼンテーション

Transcription:

Java 16 2

1 Java Java Java2 Java 1000 Java C Java C C C Java C 14 Java Java2 Java2 10 11 12 RMI 13 14 Java 15 Java C++ C++ C C Java Java P. Naughton H. Schildt Java: The Complete Reference Java2: The Complete Reference

2 Swing Java2 Java AWT(Abstract Window Toolkit) Swing AWT CPU Java Bean BDK(Bean Developer Kit) Servlet Web JSDK(Java Server Development Kit) Java Java2 Java 16 2

i 1 Java 1 1.1 Java............................................ 1 1.2 Java................................................ 1 1.3 Java............................................... 2 1.4 Java...................................... 3 1.5............................................. 3 1.6............................................. 4 1.6.1......................................... 4 1.6.2.......................... 4 1.6.3......................................... 4 1.6.4 appletviewer...................................... 5 1.6.5........................................... 5 1.6.6....................................... 5 1.6.7.................................. 6 1.6.8.................................... 6 1.6.9............................................ 6 1.6.10................................................ 7 1.6.11.............................................. 7 2 9 2.1.................................................. 9 2.2................................................... 10 2.3................................................... 11 2.4............................................. 11 2.5............................................. 11 2.6.................................................... 13 2.6.1............................................ 13 2.6.2............................................ 13 2.6.3............................................... 13 2.7................................................... 14 2.7.1 String........................................... 14 2.7.2 String...................................... 14 2.7.3 StringBuffer....................................... 15 2.8......................................... 16 2.9................................................... 16 2.9.1.............................................. 16 2.9.2.............................................. 17 2.9.3................................................ 17

ii 2.9.4............................................ 17 3 18 3.1......................................... 18 3.2............................................... 18 3.3............................................. 18 3.4................................................ 19 3.5............................................... 19 3.6.......................................... 20 3.7....................................... 20 3.8........................................... 21 3.9.................................................... 21 3.9.1.............................................. 21 3.9.2.................................... 21 3.9.3 abstract abstract............................... 22 3.9.4............................................ 22 3.9.5 Object........................................... 23 3.10 this super................................................ 23 3.11............................................. 23 3.12.............................................. 24 3.13.................................. 25 3.14................................................... 25 4 26 4.1 Java......................................... 26 4.2........................................... 27 5 29 5.1.......................................... 29 5.2.............................................. 29 5.3.................................................. 30 5.4.............................................. 30 5.4.1.......................................... 31 5.4.2....................................... 31 5.5.............................................. 32 5.5.1....................................... 32 5.5.2....................................... 32 5.6.................................................. 33 5.6.1....................................... 33 5.6.2....................................... 33 5.6.3..................................... 33 5.6.4......................................... 34 5.6.5......................................... 35 5.7.............................................. 35 5.7.1.......................................... 35 5.7.2.......................................... 35 5.8.............................................. 36

iii 5.8.1........................................... 36 5.8.2........................................... 37 5.9.................................................. 37 5.9.1......................................... 37 5.9.2......................................... 38 5.10.............................................. 38 5.10.1.................................... 38 5.10.2.................................... 38 5.11.............................................. 38 5.11.1..................................... 38 5.11.2..................................... 38 5.11.3....................................... 39 5.11.4....................................... 39 5.11.5....................................... 39 5.11.6....................................... 39 6 40 6.1................................................... 40 6.1.1............................................... 40 6.1.2....................................... 40 6.1.3.......................................... 41 6.1.4............................................ 41 6.1.5......................................... 42 6.1.6.................................... 42 6.1.7.......................................... 43 6.1.8............................................... 44 6.1.9.......................................... 44 6.1.10.................................... 45 6.1.11....................................... 49 6.1.12....................................... 49 6.2 Canvas................................................... 50 6.3................................................ 50 6.3.1 FlowLayout............................................ 50 6.3.2 BorderLayout........................................... 51 6.3.3 GridLayout............................................ 51 6.3.4 CardLayout............................................ 51 7 52 7.1.............................................. 52 7.2 Frame............................................. 53 7.3.................................................... 53 7.4.......................................... 55 7.5 (Image)............................................. 56 7.5.1 Image.................................... 56 7.5.2 Image.......................................... 57 7.5.3 (ImageObserver).............................. 58

iv 7.5.4 (MediaTracker).............................. 58 7.5.5 (ImageProducer)............................ 59 7.5.6 (ImageConsumer)............................ 60 7.5.7 (ImageFilter)................................ 60 8 62 8.1 File................................................ 62 8.2................................................ 63 8.3............................................. 64 8.4 InputStream................................................ 64 8.5 OutputStream.............................................. 64 8.6 FileInputStream............................................. 64 8.7 FileOutputStream............................................ 65 8.8 Reader................................................... 66 8.9 Writer................................................... 67 8.10 InputStreamReader............................................ 67 8.11 OutputStreamWriter........................................... 67 8.12 FileReader................................................. 67 8.13 FileWriter................................................. 68 8.14 BufferedReader.............................................. 68 8.14.1.......................................... 69 8.14.2...................................... 69 8.15 BufferedWriter.............................................. 70 8.16 PrintWriter................................................ 70 8.17 StreamTokenizer............................................. 70 8.18 Serialization................................................ 71 9 73 9.1..................................... 73 9.1.1 Collection................................... 73 9.1.2 List...................................... 74 9.1.3 Set....................................... 74 9.1.4 SortedSet................................... 74 9.2........................................... 74 9.2.1 ArrayList......................................... 75 9.2.2 LinkedList........................................ 75 9.2.3 HashSet.......................................... 76 9.2.4 TreeSet.......................................... 76 9.3......................................... 76 9.4 Iterator........................................ 77 9.5 Map.................................................... 79 9.5.1 Map..................................... 79 9.5.2 Map........................................... 79 9.5.3 HashMap......................................... 79 9.5.4 TreeMap......................................... 80 9.6 Comparator...................................... 80

v 9.7......................................... 81 9.8 Arrays............................................... 81 9.9 Enumeration..................................... 82 9.10 Vector............................................... 82 9.11 Stack................................................ 83 9.12 Dictionary............................................. 84 9.13 Hashtable............................................. 84 9.14 Properties............................................. 85 10 87 10.1.............................................. 87 10.1.1 Thread................................. 87 10.1.2 Runnable............................. 89 10.2..................................... 89 10.2.1....................................... 90 10.2.2....................................... 91 10.2.3.................................. 92 10.2.4.......................................... 94 10.2.5......................................... 95 10.2.6........................................... 97 11 98 11.1........................................... 98 11.1.1.......................................... 98 11.1.2 Socket............................................... 99 11.1.3 ServerSocket........................................... 100 11.2 UDP...................................... 101 11.3 URL........................................... 103 11.3.1 URL............................................ 103 11.3.2 URLConnection..................................... 104 11.4................................................... 104 11.4.1......................................... 104 12 RMI 106 12.1 RMI................................................ 106 12.2 RMI.................................. 106 12.2.1 1:......................... 106 12.2.2........................... 108 12.2.3................................. 109 12.2.4 RMI............................. 109 12.2.5.................................... 109 12.2.6................................ 109 12.3.................................................... 110

vi 13 111 13.1 Java...................................... 112 13.2 (1)................................... 113 13.3 (2)................................... 114 14 115 14.1................................................ 115 14.2............................................. 115 15 Java C++ 116 15.1 Java........................................... 116 15.2 C++ Java......................................... 116 15.3................................ 116

1 1 Java 1.1 Java Java Java Java. Java 1. Java (a) (b) (c) Java Java Web Java 2. 1.2 Java Java C C++ 1. C++ 2. 3. 4. 5. 6. #define 7.

1 Java 2 8. 1.3 Java Java HTML Java Java,Java Sun Microsystems, inc. JDK(Java Developer s Kit) *.java java DOS javac *.class *.class. DOS java HTML Netscape comunnicator Internet Explorer java HTML appletviewer -1 DOS appletviewer HTML appletviewer <HTML-file.html> appletviewer applet appletviewer -2 java appletviewer appletviewer <java-source.java> /* <applet code = "SimpleTest.java" width = 300 height = 250 > </applet> */ Java JDK javac java jdb javap appletviewer javadoc HTML javah

1 Java 3 sun http://java.sun.com/ http://www.javasoft.com/ http://sunsite.sut.ac.jp/java/ 1.4 Java Java Java x JDK 1.0.x Java Java2D JAI( ) JDK 1.0.2 JDK 1.1.x Java 2 JDK1.1.8 Java2D JAI Java 2 Java 3 JDK 1.2 JDK 2 Java 2 JDK 1.5 Java 2 3 J2SE (Java 2 standard Edition): JDK(Java Development kit) J2ME (Java 2 Micro Edition): J2EE (Java 2 Enterprise Edition): Java 2 Java 2D JAI Java 2D AWT(Abstract Windowing Toolkit) JAI(Java Advanced Imaging) JDK 1.1 Java2 Java 1.5 JDK java.applet java.awt GUI java.awt.image java.io java.lang java import java.net java.rmi RMI java.util. import java.awt.*;

1 Java 4 1.6 Java 1. (application) Java Java 2. HTML Java WWW.java.class 1.6.1 1. package default package package java.applet; 2. import java.lang import java.applet.applet; 3. public class extends implements 1.6.2 C main() main() class Calc { public static void main (String args[])... argw[] 1.6.3 Java HTML main() init(), paint(), actionperformed() init() paint() Applet repaint() actionperformed() HTML HTML

1 Java 5 1.6.4 appletviewer HTML appletviewer HTML /* <applet code = "SimpleTest" width = 300 height = 250 > </applet> */ 1.6.5 26 $ - 1 1.6.6 javadoc HTML /** * This is the description part * * @tag comment for the trag */ HTML HTML &lt, &gt & &amp * @author @see <reference> <reference> @version %I%, %G% 1.39, 02/28/97 @since JDK1.4 @param <name> <description> javadoc

1 Java 6 javadoc [options] [packagenames] [sourcefiles] [@files] [options] [packagenames] [sourcefiles] [@files] @ javadoc -d C:\java\test\doc TestJava.java javadoc -d C:\java\test\doc @dfiles -d <dir> HTML <dir> dfiles javadoc 1.6.7 java public public package package 1.6.8 1. *.class jar cvf jar-file.jar *.class sub-directory jar-file.jar sub-directory 2. *.class jar tvf jar-file.jar 3. jar xvf jar-file.jar 1.6.9 javac [options] sourcefile.java

1 Java 7 options -classpath <cpath> : CLASSPATH -sourcepath <spath> : -d <directory> : class -deprecation : sourcefile.java file @ @file 1.6.10 1. java [-classpath jar-file.jar] class-file [arguments] -classpath jar class-file [arguments] main() 2. javac appletviewer HTML HTML Intenet Explorer Netscape java java http://java.sun.com/products/plugin/ 1.6.11 1. System.err.println(String str) System.err.print(String str) // // 2. (a) javac -Xstdout (b) main() System.setErr(System.out)

1 Java 8 (c) java -Djava.pipe.output=true

9 2 2.1 4 3 8 byte 8bit 2 [-128,128] short 16bit 2 [-32768,32767] int 32bit 2 long 64bit 2 10 16 8 16 0x 0X 0-9,a-f,A-F 8 0 long l( ) L( ) float 32bit 1, 8 23 double 64bit 1 11 52 float f F double d D double NaN char 16bit(Unicode ), (0 65,535) ( ) ( ), ( ), (\) ( \ ) char char C,C++ integer java Unicode 16 boolean 1bit, {true, false false.

2 10 [ ] 1. compatible( ) int byte byte int char boolean compatible 2. (target-type)value 2.2 ==,<,<=,>,>= +,,,/,%( ) + String String tostring() << ( ),>> ( ), >>> ( ) << >> >> >>> >> 1 >>> Java 8 byte 16 short 32 int, ++x, x ++, x, x &(and), (or), ˆ (ex-or), (not) ( ) =, +=, =, =,/=, %=,&=, =, ˆ =, <<=,>>=, >>>= ==,! = (not equal), &&, a? b : c (a b, c), k = i < 0? -i : i ( ) cast char a = (char) (x y); () []. --- ++ -- ~! * / % + - >> >>> << > >= < <= ==!= & ^

2 11 &&?: = [ ]= --- 2.3 if if, else, else if, switch switch, case, default. switch String char, byte, short, int while, do-while, for, (while(condition){, do{ while(condition)) break, continue, return, throw( ) break : 2.4 Java. new., 2.5 ( ) Java java.lang abstract Number byte, short, int, long, float, double Byte, Short, Integer, Long, Float, Double

2 12 Byte(byte num) Byte(String str) throws NumberFormatException Short(byte num) Short(String str) throws NumberFormatException Integer(byte num) Integer(String str) throws NumberFormatException Number byte bytevalue() short shortvalue() int intvalue() long longvalue() float floatvalue() double doublevalue() : byte : short Byte, Short, Integer, Long, Float, Double String tostring() String tostring() String static String tostring(num) byte, short num String Byte, Short, Integer, Long, Float, Double parsebyte(), parseshort() [18] BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); // System.in int sum = 0; String str; System.out.println("Enter numbers, 0 to quit."); do { str = br.readline(); // try { int i = Integer.parseInt(str); // int catch(numberformatexception e) { System.out.println("Invalid format"); i = 0; sum += i; while(i!= 0) char, boolean Character, Boolean

2 13 2.6 2.6.1 Java C malloc Java new, 9 2 int, double new new import java.util.*; int table[]= new int[30]; int[] table = new int[30]; int two[][] = new int[20][30]; int[][] two = new int[20][30]; int cards[][] = new int[20][30]; 2 3 int three[][][] = new int[10][20][30]; new int[] table = {1, 3, 6, 8; int[][] cards = {{1,2,3,{2,1,3; class Node { double x, y;... ; // Node nodes[] = new Node[100]; // 2.6.2 Java int two[][] = new int[][]; two[0] = new int[3]; two[1] = new int[3]; 2 2.6.3 table.length clone()

2 14 String[] second = (String[]) first.clone(); 2.7 2.7.1 String String new String s1 = new String("abc"); char chars[] = { a, b, c ; String s2 = new String(chars); // chars String s3 = "abc"; String + "abc" + "cd" -> "abcd", "abc" + 123 -> "abc123" int length() char charat(int i) (i+1) 0 int indexof(int s) s. int lastindex(int s) String substring(int start, int end) start-end void getchars(int start, int end, char chars[], int target) 2 target boolean s1.equals(string s2) s1, s2 int s1.compareto(string s2) s1, s2 s1 s2 static String valueof(double num) double String long, Object, char chars[] String tostring() 2.7.2 String String Byte, Short, Integer, Long parseshort(), parseint(), parselong() byte, short, int, long int Integer.parseInt(String str); // String int Integer, Double, Float, Long String valuof() intvalue(), doublevalue(), floatvalue() String int Integer.valueOf(String str).intvalue(); // String int int Double.valueOf(String str).intvalue(); // String int double Double.valueOf(String s).doublevalue(); float Float.valueOf(String s).floatvalue();

2 15 String Byte, Short, Integer, Long tostring() String String Integer.toString(int num); // int String 2.7.3 StringBuffer String StringBuffer new StringBuffer sb = new StringBuffer("abc"); StringBuffer() StringBuffer(int size) int length() int capacity() void ensurecapacity(int capacity) void setlength(int len) char charat(int where) where void setcharat(int where, char ch) where ch. void getchars(int start, int end, char target[], int targetstart) target. StringBuffer append(string str) str StringBuffer append(int num) StringBuffer append(object obj) StringBuffer insert(int index, String str) str index StringBuffer insert(int index, Char ch) StringBuffer insert(int index, Object obj) StringBuffer reverse() StringBuffer delete(int start, int end) StringBuffer deletecharat(int loc) StringBuffer replace(int start, int end, String str) str String substring(int start) start String substring(int start, int end) String tostring() append() [18] class appenddemo{ public static void main(string args) { String s; int a 42; StringBuffer sb = new StringBuffer(40); s = sb.append(a"=").append(a).append("/").tostring(); System.out.println(s);

2 16 2.8 StringTokenizer ( ) HTML StringTokenizer(String str) : str StringTokenizer(String str, String delimitters) : delimitters delimitter ",;:" StringTokenizer(String str, String delimitters, boolean delimastoken) : delimastoken true int counttokens() : boolean hasmoreelements(): true boolean hasmoretokens() : true Object nextelement() : Object String nexttoken() : String nexttoken(string delimitters) : delimitters. imprt java.util.*; class Demo { public static void main(string args[]) { String str = "123/avc/21.3/XYZ"; StringTokenizer st = new StringTokenizer(str, "/"); while(st.hasmoretokens) { String s = st.nexttoken(); System.out.println(s); 2.9 2.9.1 3 1 // ( ) C /* ( ) */ javadoc HTML * *

2 17 /** ( * 2 ) * < > * < > */ 2.9.2 Math (java.lang ) 2.9.3 java.util import java.util.*; Random r = new Random(); // Random(long seed) double val = r.nextgaussian(); double nextdouble(); double 0.1-1.0 float nextfloat(); float int nextint(); int nextint(int n); double nextgaussian(); 0.0, 1.0 long nextlong(); long void setseed(long newseed); 2.9.4 Date Date() : Date(long msec) : 1970 1 1 0 boolean gettime() : void settime(long msec) : msec String tostring() :

18 3 3.1 Java 3.2 < > class < > extends < > implements < > { < > < > < > < > extends Java extends implements 3.3 public abstract new. abstract abstract abstract abstract final final. () Integer, Math.

3 19 3.4 static public int ; final protected long ; volatile private double ;... static static final volatile public protected private transient 3.5 < > < ( )> { void public, protected, private, static, asbstract, final, native, synchronized public protected private private public static static static static this super

3 20 main() static abstract abstract final native C, C++ synchronized void finalize() {... ; main() Java static main(string args[]){ length 1 C 1 3.6 new super super( ) this void public 3.7 static static{ ( ) static

3 21 3.8 new String str = new String(); Date d1 = new Date(); int[] temp = new int[20]; Circle myclass; myclass = new Circle(); Circle yourclass = new Circle(); 3.9 Java 3.9.1 Java 3.9.2 private ( override) static Java (dynamic method dispatch) [18] class A { void callme() { class B extends A { void callme() { // A // B A

3 22 class C extends A { void callme() { // C A class Dispatch { A a = new A(); // A B b = new B(); // B C c = new C(); A r; // A r = a; r.callme(); // A callme() r = b; r.callme(); // B callme() r = c; r.callme(); // C callme() 3.9.3 abstract abstract abstract abastract public abstract class Graphics{ : public abstract void drawline(int x1, int y1, int x2, int 2); : abstract abstract abstract, abstract abstract Graphics abstract 3.9.4 final final final

3 23 3.9.5 Object Object (java.lang.object) Object Object clone() : boolean equals(object ob) : void finalize() : Class getclass() : int hashcode() : void notify() : wait() void notifyall() : wait() String tostring() : Object println() void wait() : void wait(long millisec) : void wait(long millisec, int nanosec) : 3.10 this super. this. this.var this this this( ) super super.var super( ) 3.11 java interface interface (extends ){

3 24 ( ); = ; implements. implements extends public abstract abstract abstract static, final (dynamic method resolution at run time) 3.12 (nested class) static non-static (inner class) (anonymous inner class) [18] class Outer { int outer_x = 100; void test() { for(int i=0; i<19, i++) { class Inner { // void display() { System.out.println("outer_x = " + outer_x); Inner inner = new Inner(); // inner.display(); class Demo { public static void main(string args[]) { Outer outer = new Outer(); outer.test();

3 25 3.13.. (override) ( ) super. (call-by-value) (call-by-reference) 3.14 1. import import. 2. { code block

26 4 WWW(World Wide Web) HTML(Hyper Text Markup Language) Java 1. Java java 2. ( class) 3. HTML 4.1 Java main() init() start() init() actionperformed(actionevent ev) paint(graphics g) paint() Applet repaint() update(graphics g) paint() update() update() Applet repaint() update() paint() paint() update() stop() start() destroy() import java.awt.*; import java.applet.*; /* */ public class extends Applet implements ActionListener{ // ActionListener //

4 27 size() size().width size() size().height size() SetFont(Font) Font SetColor(Color) Color drawrect(x1, y1, x2, y2) (x1, y1)(x2, y2) drawstring(string, x, y) (x, y) String 7 java HTML HTML appletviewer sourcefile.java /* <applet code = "SimpleTest" width = 300 height = 250 > </applet> */ 4.2 HTML Java HTM < applet code = " file.class " width = 200 height = 50 > < /applet > width height Java applet /applet Java code, width, height codebase( URL), alt( ), name( ) HTML init() 1. HTML applet /applet <param name = font value = "TimesRoman" > <param name = size value = "36"> name value. 2. getparameter( ) value String thefontname=getparameter( font );

4 28 int thesize; String s = getparameter("size"); // 36 if (s==null) thesize = 12; // default value else thesize = Integer.parseInt(s); // 36

29 5 Java java.awt.* java.awt.event.* java.applet.* import 5.1 Java Ver.1.1 (delegation event model) (source) (listener) (Adapter) (Anonymous Inner Class) 5.2 EventObject java.util EventObject(Object obj) Object getsource() String tostring() EventObject AWTEvent java.awt AWT int getid() AWTEvent java.awt.event ( ) ActionEvent ActionListener

5 30 AdjustmentEvent AdjustmentListener ComponentEvent ComponentListener ContainerEvent ContainerListener FocusEvent FocusListener InputEvent ItemEvent choice ItemListener KeyEvent KeyListener MouseEvent MouseListener( ) Mouse- MotionListener( ) TextEvent TextListener WindowEvent WindowListener add public void add< >(< > el); add implements extends 5.3 implements 5.4 implements implements extends add ()

5 31 ComponentListener ComponentAdapter ContainerListener ContainerAdapter FocusListener FocusAdapter KeyListener KeyAdapter MouseListener MouseAdapter MouseMotionListener MouseMotionAdapter WindowListener WindowAdapter [18] import java.applet.*; import java.awt.event.*; public class AdapterDemo extends Applet { public init() { addmouselistener(new MyMouseAdapter(this)); // ( ) class MyMouseAdapter extends MouseAdapter { // AdapterDemo adapterdemo; public MyMouseAdapter(AdapterDemo adapterdemo) { // this.adapterdemo = adapterdemo; public void mouseclicked(mouseevent me) { // adapterdemo.showstatus("mouse clicked"); // showstatus Applet // status window 5.4.1 public class AdapterDemo extends Applet { public init() { addmouselistener(new MyMouseAdapter()); // class MyMouseAdapter extends MouseAdapter { // public void mouseclicked(mouseevent me) { showstatus("mouse clicked"); 5.4.2

5 32 public class AdapterDemo extends Applet { public init() { addmouselistener(new MouseAdapter() { // public void mouseclicked(mouseevent me) { showstatus("mouse clicked"); ); 5.5 5.5.1 WINDOW_ACTIVATED WINDOW_CLOSED WINDOW_CLOSING WINDOW_DEACTIVATED WINDOW_DEICONIFIED WINDOW_ICONFIED WINDOW_OPENED WindowEvent ComponentEvent WindowEvent(Window src, int type); src type getwindow Window Window getwindow() 5.5.2 windowlistener addwindowlistener(windowlistener wl); void windowopened(windowevent ev){ void windowclosing(windowevent ev){ void windowclosed(windowevent ev){ void windowactivated(windowevent ev){ void windowdeactivated(windowevent ev){ void windowiconified(windowevent ev){ void windowdeiconified(windowevent ev){

5 33 5.6 ActionEvent ItemEvent 5.6.1 ActionEvent ActionEvent(Object src, int type, String cmd ) ActionEvent(Object src, int type, String cmd, int modifier ) type cmd modifier modifier key (ALT, CTRL, META, SHIFT). ActionEvent ( ) String getactioncommand() 5.6.2 ActionListener void actionperformed(actionevent ae) 5.6.3 (Button) Go Stop ActionListener implements Button addactionlistener(this) actionperformed(actionevent e) getactioncommand() public class ButtonTest1 extends Applet implements ActionListener { // ActionListener implements public void init() { // init() Panel panel= new Panel(); // Button... Button gobutton = new Button("Go"); // Button Button stopbutton = new Button("Stop"); //... panel.add(gobutton); // gobutton panel.add(stopbutton); // StoButton... gobutton.addactionlistener(this); // gobutton stopbutton.addactionlistener(this); // stopbutton

5 34 public void actionperformed(actionevent e) { // String cmd = e.getactioncommand(); // if(cmd.equals("go")) {... // Go if(cmd.equals("stop")) {... // Stop... (Button) Frame actionperformed() init() class Sampleframe extends Frame implements ActionListener { public Sampleframe() { // super(); // Frame Panel panel= new Panel(); // Button... panel.add(gobutton); // gobutton... Button gobutton = new Button("Go"); // Button... gobutton.addactionlistener(new ActionListener() { // public void actionperformed(actionevent ae) {... // ); public class ButtonTest2 { public static main(spring[] args) { Frame w = new frame(); w.show(); // Frame // 5.6.4 ItemEvent ItemEvent(ItemSelectable src, int type, Object entry, int state) src type entry state Object getitem() ItemSelectable getitemselectable() SelectableItem int getstatechange() (SELECTED DESELECTED)

5 35 5.6.5 ItemListener void itemstatechanged(itemevent ie) 5.7 5.7.1 MouseEvent MOUSE_CLICKED MOUSE_DRAGGED MOUSE_ENTERED MOUSE_EXITED MOUSE_MOVED MOUSE_PRESSED MOUSE_RELEASED MouseEvent(Component src, int type, long when, int modifiers, int x, int y, int clicks, boolean triggermenu) src type when modifiers x,y clicks triggermenu int getx() : X int gety() : Y Point getpoint() : void translatepoint(int x, int y) : int getclickcount() : boolean ispopuptrigger() : 5.7.2 1. MouseListener void mouseclicked(mouseevent me): void mouseentered(mouseevent me): void mouseexited(mouseevent me): void mousepressed(mouseevent me): void mousereleased(mouseevent me): 2. MouseMotionListener

5 36 void mousedragged(mouseevent me): void mousemoved(mouseevent me): 1 import java.awt.*; import jawa.awt.event.*; import java.applet.*; public class MouseEvents extends Applet implements MouseListener, MouseMotionListener { String msg = ""; int mousex = 0; mousey = 0; public void init() { addmouselistener(this); addmousemotionlistener(this); // public void mouseclicked(mouseevent me) { // mousex = 0; mousey = 10; msg = "Mouse Clicked."; repaint(); public void mousepressed(muouseevent me) { // mousex = me.getx(); // X mousey = me.gety(); // Y msg = "Down"; repaint();. //. public void paint(graphics g) { g.drawstring(msg, mousex, mousey); // 5.8 5.8.1 KeyEvent KeyEvent(Component src, int type, long when, int modifiers, int code) : src type when modifiers code

5 37 KeyEvent(Component src, int type, long when, int modifiers, int code, char ch) char getkeychar() int getkeycode() 5.8.2 KeyListener void keypressed(keyevent ke): void keyreleased(keyevent ke): void keytyped(keyevent ke): import java.awt.*; import jawa.awt.event.*; import java.applet.*; public class Simplkey extends Applet implements KeyListener { String msg = ""; int X = 10, Y = 20; public void init() { addkeylistener(this); // requestfocus(); // public void keypressed(keyevent ke) { // showstatus("key down"); // public void keytyped(keyevent ke) { // msg += ke.getkeychar(); // repaint(); //. //. public void paint(graphics g) { g.drawstring(msg, X, Y); // msg 5.9 5.9.1 TextEvent

5 38 TextEvent(Object src, int type) : src type 5.9.2 void textchanged(textevent te) : 5.10 5.10.1 AdjustmentEvent AdjustmentEvent(Adjustable src, int id, int type, int data) : src id type data. Adjustable getadjustable() : int getadjustmenttype() : int getvalue() : 5.10.2 AdjustmentListener. void adjustmentvaluechaned(adjustmentevent ae) : 5.11 ComponentEvent, ContainerEvent FocusEvent,. 5.11.1 ComponentEvent ComponentEvent(Component src, int type) :, src,type. Component getcomponent() :. 5.11.2 ComponentListener.

5 39 void componentresized(componentevent ce) void componentmoved(componentevent ce) void componentshown(componentevent ce) void componenthidden(componentevent ce) 5.11.3 ContainerEvent Component ContainerEvent(Component src, int type, Component comp) void getcontainer() void getchild() 5.11.4 ContainerListener void componentadded(container ce) void componentremoved(containerevent ce) 5.11.5 FocusEvent.. FocusEvent(Component src, int type) :, src,type FocusEvent(Component src, int type, boolean flag) :, flag true. boolean istemporary() : true. 5.11.6 FocusListener. void focusgained(focusevent fe) : void focuslost(focusevent fe) :

40 6 AWT 5 6.1 6.1.1 Label Label(), Label(String str), Label(String str, int how) how Label.LEFT, Label.RIGHT, Label.CENTER Label.LEFT Label one = new Label("one", Label.RIGHT); // one add(one); // String gettext() : void settext(string label): label 6.1.2 Textfield TextFiled(), TextField(int numchar), TextField(String str), TextField(String str, int numchars) str numchars Label namep = new Label("Name", Label.RIGHT); // Textfield name = new TextField("Sato",12); // Sato add(namep); // add(name); // p = new Panel(); p.add(new Label("Data", Label.RIGHT)); //

6 41 p.add(textfield data = new TextField("10",8)); Double buffer = Double.ValueOf(data.getText()); // Double int x = (int)buffer.doublevalue(); // TextField void addactionlistener(actionlistener al) String gettext() String getselectedtext() void selectall() boolean iseditable() true void seteditable(boolean t) t false 6.1.3 TextArea ( ) TextArea(), TextArea(int numlines, int numchars) TextArea(String str) TextArea(String str, int numlines, int numchars) TextArea() TextArea text = TextArea("Hello world", 3, 40); add(text); TextArea TextComponent void append(string str) void insert(string str, int pos) pos viod replace(string str, int start, int end) start end seteditable(boolean t) t false 6.1.4 Button Button(), Button(String str) str

6 42 Button yes = new Button("Yes"); yes.addactionlistener(this); add(yes); // Yes // // Button void addactionlistener(actionlistener al) String getactioncommand() String getlabel() void setactioncommand(string cmd) cmd void setlabel(string str) str 6.1.5 Checkbox Checkbox() Checkbox(String label) str. Checkbox(String label, CheckboxGroup cbgroup, boolean on) on Checkbox win95 = new Checkbox("Window 95", null, true); // win95.additemlistener(this); // add(win95); // Checkbox void additemlistener(itemlistener il) CheckboxGroup getcheckboxgroup() String getlabel() void setlabel(string label) label. boolean getstate() void setstate(boolean state) 6.1.6 CheckboxGroup CheckboxGroup()

6 43 cbg = new CheckboxGroup(); Checkbox win95 = new Checkbox("Window 95", cbg, true); // Checkbox unix = new Checkbox("Unix", cbg, false); // add(win95); // add(unix); CheckboxGroup void additemlistener(itemlistener il) CheckboxGroup getcheckboxgroup() String getlabel() void setlabel(string lb) lb boolean getstate() void setstate(boolean st) 6.1.7 Choice Choice() additem(string name) getselecteditem(), getselectedindex() Choice os = new Choice(); os.additem("window 95"); os.additem("unix"); os.select("unix"); add(os); String msg = os.getselecteditem(); int index = cs.getselectedindex(); // Unix // // void additemlistener(itemlistener il) void add(string name) String getselecteditem() int getselectedindex(). int getitemcount() String getitem(int index) index int getselectedindex() String getselecteditem() void select(string name) name void select(int index) index.

6 44 6.1.8 List List() List(int numrows, boolean multipleselect) numrows multipleselect true false additem() getselecteditem(), getselectedindex() getselecteditems(), getselectedindexes() Choice os = new List(3, true); os.additem("window 95"); os.additem("window 95"); os.additem("unix"); os.select("unix"); // Unix add(os); // int[] idx = os.getselectedindexes(); // void addactionlistener(actionlistener al) void add(string name) name. void add(string name, int index) index name int getitemcount() String getitem(int index) index String getselecteditem() int getselectedindex() ). String[] getselecteditems(). int[] getselectedindexes() boolean isindexselected(int pos) pos void select(int pos) pos 6.1.9 Scrollbar Scrollbar() Scrollbar(int Style) Style Scrollbar.VERTICAL Scrollbar.HORIZONTAL

6 45 Scrollbar(int style, int initval, int thumbsize, int min, int max) initval thumbsize scroll thum ( ) min, max setvalues() int getvalue() int width = Integer.parseInt(getParameter("width"); // int height = Integer.parseInt(getParameter("height"); // Scrollbar versb = Scrollbar(Scrollbar.VERTICAL, 0, 1, 0, height); Scrollbar horsb = Scrollbar(Scrollbar.HORIZONTAL, 0, 1, 0, width); versb.addadjustmentlistener(this); // horsb.addadjustmentlistener(this); // add(versb); add(horsb); AdjustmentListener implements void addadjustmentlistener(adjustmentlistener al) void setvalues(int initval, int thumbsize, int min, int max) initval thumbsize scroll thum ( ) min, max int getvalue() void setvalue(int newval) newval getminimum() getmaximum() setunitincrement(int newinc) newinc setblockincrement(int newinc) 6.1.10 MenuBar Menu MenuItem Menubar() void setmenubar(menubar mb) (Frame ) Menu add(menu mn) mn Menu() Menu(String name) menu

6 46 Menu(String name, boolean removable) removable true MenuItem add(menuitem mi) mi void add(string label) label MenuItem getitem(int index) index int getitemcount() void insert(string label, int index) label index MenuItem() MenuItem(String item) item MenuItem(String item, MenuShortcut ms) item ms void addactionlistener(actionlistener al) al void setenabled(boolean flag) true boolean isenabled() true void setlabel(string name) name String getlabel() String getactioncommand() CheckboxMenuItem() CheckboxMenuItem(String name) name void additemlistener(actionlistener al) CheckboxMenuItem(String name, booleam on) on true boolean getstate() void setstate(boolean checked) checked true [18] 1. MenuFrame (a) File New, Old Special First

6 47 (b) Debug 2. MyWindowAdapter 3. MyMenuHnadler New Old 4. MenuDemo (a) init() HTML width height (b) start() (c) stop() import java.awt.*; import java.awt.event.*; import java.applet.*; class MenuFrame extends Frame{ String msg = ""; // MenuFrame(String) { super(titel); // MenuBar mbar = new MenuBar(); setmenubar(mbar); // // Frame Menu mn = new Menu("File"); // MenuItem item1, item2; // mn.add(item1 = new MenuItem("New")); // mn.add(item2 = new MenuItem("Old")); Menu sub = new Menu("Special"); // MenuItem item3; sub.add(item3 =new MenuItem("First")); mn.add(sub); // CheckboxMenuItem debug; // mn.add(debug = new CheckboxMenuItem("Debug")); // MyMenuHandler handler = new MyMenuHandler(this); // item1.addactionlistener(handler); // item2.addactionlistener(handler); // item3.addactionlistener(handler); // debug.additemlistener(handler); // MyWindowAdapter adapter = new MyWindowAdapter(this);

6 48 // addwindowlistener(adapter); // public void paint(graphics g) { g.drawstring(msg, 10, 200); if(debug.getstate()) g.drawstring("debug is on.", 10, 220); // // // class MyWindowAdapter extends WindowAdapter { // MenuFrame menuframe; public MyWindowAdapter (MenuFrame menuframe) { // this.menuframe = menuframe; // menuframe public void windowclosing(windowevent we) { // menuframe.setvisible(false); class MyMenuHnadler implements ActionListener, ItemListener { // MenuFrame menuframe; public MyMenuHnadler(MenuFrame menuframe) { // this.menuframe = menuframe; public void actionperformed(actionevent ae) { // String msg = "You selected "; String arg = (String)ae.getActionCommand(); if(arg.equals("new")) msg += "New")); if(arg.equals("old")) msg += "Old")); menuframe.msg = msg; menuframe.repaint(); // public void itemstatechanged(itemevent ie) { // menuframe.repaint(); public class MenuDemo extends Applet { Frame f; // public void init() { // f = new MenuFrame("Menu Demo"); // int width = Integer.parseInt(getParameter("width")); // HTML HTML // <param name=width vale=100> int height = Integer.parseInt(getParameter("height")); setsize(new Dimension(width, height));

6 49 f.setsize(width, height); // f.setvisible(true); // public void start() {f.setvisible(true); // public void stop() {f.setvisible(fales); // 6.1.11 Dialog Dialog(Frame parent, boolean mode) parent mode true Dialog(Frame parent, String title, boolean mode) title void show() void hide() void dispose() String gettitle() void settitle(string title) title 6.1.12 FileDialog FileDialog(Frame parent, String name) parent name FileDialog(Frame parent, String name, int how) how FileDiaLog.LOAD FileDiaLog.SAVE FileDialog(Frame parent) String getdirectory()

6 50 String getfile() void setfile(string file) file SampleFrame() Frame f = new SampleFrame("File Dialog Demo"); f.setvisible(true); f.setsize(100, 100); FileDialog fd = new FileDialog(f, "FileDialog"); fd.setvisible(true); label.settext("you chose " + fd.getfile()); // // // 6.2 Canvas Canvas Canvas Button TextArea Canvas paint() Graphics paint() repaint() class MyCanvas extends Canvas{ public void paint(graphics g){ g.drawstring("canvas", 0, 10); -------------- public boolean mousedown(event evt, int x, int y){ -------------- 6.3 LayoutManager implements setlayout() LayoutManager add() setlayout() void setlayout(layoutmanager layoutobj) FlowLayout, BorderLayout, GridLayout CardLayout 6.3.1 FlowLayout FlowLayout add() FlowLayout()

6 51 FlowLayout(int how) how FlowLayout.LEFT, FlowLayout.CENTER, FlowLayout.RIGHT FlowLayout.LEFT. FlowLayout(in how, int hor, int ver) hor, ver setlayout(new FlowLayout(FlowLayout.LEFT)); Checkbox win95 = new Checkbox("Windows 95", null, true); Checkbox unix = new Checkbox("Unix", null, true); add(win95); add(unix); 6.3.2 BorderLayout BorderLayout BorderLayout() BorderLayout(int hor, int ver) hor, ver Component add(string name, Compnent compobj) name East, West, North, South, Center setlayout(new BorderLayout()); add("north", new Button("Upper")); add("south", new Button("Lower"));... 6.3.3 GridLayout GridLayout add() GridLayout(int numrows, int numcolls), GridLayout(int numrows, int numcolls, int hor, int ver) hor, ver setlayout(new GridLayout(4, 4); for(int i = 0; i < 4; i++) { for(int j = 0; j < 4; j++) { int k = i * 4 + j; if (K > 0) add(new Button("" + k)); // // 6.3.4 CardLayout CardLayout next(), previous(), first(), last(), show()

52 7 AWT(Abstract Window Toolkit) java.awt 3 GUI AWT GUI java.awt AWT Swing AWT Swing Java Swing AWT AWT 7.1 7.1 AWT Component Canvas Container Window Frame Frame Container Panel Applet 1. Frame Window Frame 2. Applet 3. Panel Container Panel Panel Applet Panel Panel Panel add() move(), resize(), reshape()

7 53 7.1: 4. Canvas 5. Dialog 7.2 Frame Frame() Frame(String title) resize() size() size() width, height void resize(int width, int height) void resize(dimension size) Dimension size() show(), hide() settitle(string title) Frame init() show() resize() 7.3 AWT Component Graphics update() paint() Graphics Graphics. drawline(int X1, int Y1, int X1, int Y1) drawline(int X1, int Y1, int X2, int Y2) drawrect(int top, int left, int width, int height) fillrect(int top, int left, int width, int height)

7 54 drawroundrect(int top, int left, int width, int height, int xdia, int ydia) fillroundrect(int top, int left, int width, int height, int xdia, int ydia) drawoval(int top, int left, int width, int height) filloval(int top, int left, int width, int height) drawarc(int top, int left, int width, int height, int startangle, sweepangle) fillarc(int top, int left, int width, int height, int startangle, sweepangle) drawpolygon(int x[], int y[], int numpoints) fillpolygon(int x[], int y[], int numpoints) drawstring(string str, int x, int y) dimension size() resize() void setcolor(color newcolor) Color getcolor() public class Demo extends Applet { public void paint(graphics g) { Color c1 = new Color(255,100,100); g.setcolor(c1); -- -- R,G,B Color(int red, int green, int blue) 0 255 Color.red black, white, red, green, blue, cyan, yellow, magenta, orange, pink, gray, darkgray, lightgray. void setfont(font fontobj) Font getfont() Graphics Color Font public void paint(graphics g){ g.setfont(new Font("TimesRoman", Font.PLAIN, 10); g.setcolor(color.lightgray); g.drawstring("total", 5, 10);

7 55 7.4 Java update() repaint() Image offscreen; // Dimension offscreensize; // Graphics offgraphics; // public synchronized void update (Graphics g) { Dimension d = getsize(); // if((offscreen == null) (d.width!= offscreensize.width) (d.height!= offscreensize.height)) { offscreen = createimage(d.width, d.height);// offscreensize = d; // offgraphics = offscreen.getgraphics(); // graphics offgraphics.setfont(getfont()); // offgraphics.setcolor(getbackground()); // --- // offgraphics.drawline(), offgraphics.setcolor --- g.drawimage(offscreen, 0, 0, null); // update(graphics g) paint(graphics g) update(graphics g) paint(g) ( 10 ) import java.awt.*; import java.applet.applet; public class DrawBuffer extends Applet implements Runnable { Image offscreen; // Thread thread; // int w, h; // public void init() { Dimension d = getsize(); w = d.width; h = d.height; offscreen = createimage(w, h); // // //

7 56 public void start() { thread = new Thread(this); thread.start(); // // // -run() public void run() { // while(true) { // repaint(); // paint() try { Thread.sleep(100); // catch(interruptedexception e) { // public void paint(graphics) { // --- // offscreen.setcolor(), offscreen.drawline() g.drawimage(offscreen, 0, 0, this); // 7.5 (Image) Image Java Image java.awt.image GIF JPEG 2 *.gif, *.jpg) 7.5.1 Image Image width, height createimage(int width, int height) createimage() Component Canvas c = new Canvas(); Image test = c.createimage(200, 100); Canvas ImageProducer Image createimage(imageproducer imageprod) ImageProducer() Applet getimage(url url, String name) HTML. getdocumentbase() URL import java.applet.*; import java.awt.*; import java.awt.image.*; Image im;

7 57 public void init(){ im = getimage(getdocumentbase(), "sample.gif"); : HTML /* * <applet code=sample.class width=400 height=300> * <param name=img value=sample2.jpg> * </applet> */ : public void init(){ im = getimage(getdocumentbase(), getparameter("img"); : 7.5.2 Image Image getgraphics() Graphics Canvas c = new Canvas(); // Canvas Image test = c.createimage(200, 100); // Canvas Graphics g = test.getgraphics(); // Graphics g.setcolor(color.red); // g.fillrect(0, 0, 200, 100); // drawimage(image img, int x, int y, ImageObserver observer) g.drawimage(gc, 0, 0, null); g paint(graphics g) g drawimage() ImageObserver null boolean drawimage(image object, int x, int y, ImageObserver imgob) drawimage() boolean drawimage(image object, int x, int y, width, height, ImageObserver imgob) x,y width, height Canvas(iava.awt.Canvas) Applet Frame paint(graphics g) g.drawimage()

7 58 7.5.3 (ImageObserver) ImageObserver ImageObserver imageupdate() [18] Applet ImageObserver imageupdate() repaint() public boolean imageupdate(image img, int flags, int x, int y, int w, int h) { if((flags & SOMEBITS)!= 0) { repaint(x, y, w, h); else if((flags & ABORT)!= 0){ error = true; repaint(); return (flags & (ALLBITS ABORT)) == 0; SOMEBITS ImageObserver SOMEBITS ALLBITS ABORT 7.5.4 (MediaTracker) MediaTracker ImageObserver (null MediaTracker addimage() checkid() addimage() void addimage(image img, int id) void addimage(image img, int id, int width, int height) id 2 width, height checkid() id boolean checkid(int id) // true [18] MediaTracker tracker; int tracked; Image img[] = new Image[10]; : public void init() { //

7 59 tacker = new MediaTracker(this); : while(...) { // img[tracked] = getimage(getdocumentbase(), name[tracked] + ".jpg"); // tracker.addimage(img[tracked], tracked); // tracked++; // : public void paint(graphics g) { // for(...) { if(tracker.checkid(i)) {... // 1 [11] public init() { MediaTracker tracker = new MediaTracker(this); Image img = getimage(getdocumentbase(), "image.jpg"); tracker.addimage(img, 0); try { tracker.waitforall(); // catch(interruptedexception e) { 7.5.5 (ImageProducer) ImageProducer integer byte java.awt.image MemoryImageSource FilteredImageSource MemoryImageSource MemoryImageSource(int width, int height, int pixel[], int offset, int scanwidth) width, height pixcel[] 4 32 Alpha, Red, Green, Blue (0xAARRGGBB) Alpha 0 255 1 offset scanwidth width MemoryImageSource createimage Image img = createimage(new MemoryImageSource(w, h, pixels, 0, w));

7 60 7.5.6 (ImageConsumer) ImageConsumer ImageProducer PixelGrabber MemoryImageSource PixelGrabber 1 PixelGrabber(Image img, int x, int y, int width, int height, int pixel[], int offset, int scanwidth) img pixel[] x,y width, height offset pixel[] scanwidth width grabpixels() [18] init() Image = img; int pixels[]; public init() { : try { Image img = getimage(getdocumentbase(), getparameter("img")); MediaTracker t = new MediaTracker(this); t.addimage(img, 0); // 0 t.waitforid(0); // 0 int w = img.getwidth(null); int h = img.getheight(null); pixels = new int{w * h]; PixelGrabber pg = new PixelGrabber(img, 0, 0, w, h, pixels, 0, w); pg.grabpixels(); // catch(interruptedexception e) {; pixels[] 7.5.7 (ImageFilter) ImageFilter java.awt.image AreaAveragingScaleFiler, CropImageFilter, ReplicateScaleFilter, RGBImageFilter CropImageFilter CropImageFilter f; FilteredImageSource fis; t = new MediaTracker(this); for(int y=0; y<4; y++) { for(int x=0; x<4; x++) { f = new CropImageFilter(tw*x, th*y, tw, th); // tw, th 1/4.

7 61 fis = new FilteredImageSource(img.getSource(), f); // ImageProducer // img int i = y*4 + x; cell[i] = createimage(fis); // cell[] Image t.addimage(cell[i], i); // t.waitforall(); // 4 1 tw, th Image cell[] CropImageFilter img FilteredImageSource createimage

62 8 java.io Java GUI Java 8.1 File File File File(String directorypath) File(String directorypath, String filename) File(File dirobj, String filename) File f1 = new File("/") : File f2 = new File("/", "sample.txt") : sample.txt File f1 = new FIle(f1, "sample.txt") : File File boolean canread() : boolean canwrite() : boolean delete() : boolean exists() : String getabsolutepath() : String getname() : String getpath() : boolean isdirectory() : boolean isfile() : long lastmodified() : long length() : String[] list() : String[] list(filenamefilter filter) : [18]

8 63 import java.io.*; class FileDemo { static void p(string s) { System.out.println(s); // s public static void main(string args[]) { File f = new File("/sample.txt"); p("file name: " + f1.getname()); p(f1.exists()? "exist" : "does not exist"); 8.2 Java (Byte stream) Java1.1 (Character stream) Unicode Java InputStream, OutputStream : FileInputStream, FileOutputStream : ByteArrayInputStream, ByteArrayOutputStream : BufferedInputStream, BufferedOutputStream : PrintStream : print(), println() RandomAccessFile : Unicode Reader,Writer : InputStreamReader,OutputStreamWriter : FileReader, FileWriter : CharArrayReader, CharArrayWriter : BufferedReader, BufferedWriter : StringReader, StringWriter : PushbackReader : PrintWriter : print(), println() System.in, System.out, System.err java.lang System java.lang import