Äîêóìåíò âçÿò èç êýøà ïîèñêîâîé ìàøèíû. Àäðåñ îðèãèíàëüíîãî äîêóìåíòà : http://uneex.lorien.cs.msu.su/static/MethodBooks_Eclipse_Java/Eclipse_Java.pdf
Äàòà èçìåíåíèÿ: Mon Sep 26 12:35:44 2011
Äàòà èíäåêñèðîâàíèÿ: Tue Oct 2 12:32:49 2012
Êîäèðîâêà:

Ïîèñêîâûå ñëîâà: vallis


.. , .. Java- Eclipse ( - Java)



2008


.., .. 143 Java- Eclipse: ( - Java): . 2008. -- 77 .

Eclipse Java. Eclipse. , , , , Java.


.. , .. , Java- Eclipse


.......................................................................................4 .............................................................................................6 1. Eclipse...............................9 1.1. ...........................................................................................9 1.2. Eclipse....................................................................................................10 1.3. Eclipse....................................................................................................12 1.4. Eclipse.............................................................................................14 1.5. ......................................................................................18 1.6. ....................................................................................................25 1.7. ...................................................................................................27 1.8., , .....................................................33 2. ..............................37 3. ..................................................44 ..........................................................................................71 ..........................................................................77

3


.. , .. , Java- Eclipse


() . . Java, , Sun Green (Oak), 1990 . . Sun ( Java-). World Wide Web 1995 . Java. Java : Internet , , , . , Java : , , « ». Java - , , . , Java- : Linux, Solaris, Windows MacOS. Java , , , , . Java -- , -
4


.. , .. , Java- Eclipse

. , . Java - . Java , . Java : Eclipse (Eclipse Foundation), NetBeans (Sun), JBuilder (Inprise), Visual Age (IBM), VisualCafe (Symantec) . , : Java . , Java, , -- IT. , , . Eclipse , , , . Eclipse , , , . Java , . , - . , , , , . , . spo_method_support@armd.ru

5


.. , .. , Java- Eclipse


, Java, . Java, ( ) Java. (aplets). , , . Java, . , , . , (++, Delphi). Java HTML Web-. - Java- . , Web- . -- Just-In-Time compilation (JIT, «-)», . Java . , , Sun (http://java.sun.com/): JRE, JDK. JRE -- ( Java) Java Runtime Environment (JRE). -- JDK (Java Development Kit). , .. Java-: 1) Java 2 Platform, Standard Edition (J2SE); 2) Java 2 Platform, Enterprise Edition (J2EE); 3) Java 2 Platform, Micro Edition (J2ME). .
6


.. , .. , Java- Eclipse

J2SE (desktop) . J2EE (, jsp-, JavaBeans). (J2ME) ( , .), ( , .). , Java : JRE -- ; JDK (J2SE, J2EE, J2ME) -- ; . Java : , , (Java API), . Java Eclipse. Java , : , , , - . Eclipse , . , «».java. vi, kate, kwrite emacs. Eclipse , . , , Run . Java Java -, Java. , «».class. -, . . . Eclipse «».class 7


.. , .. , Java- Eclipse

. , . «».class : , . Java. Eclipse . , - - Java-. - HTML Java-. , . - Java, .. Java. Java, Eclipse , -, - . -. , , . Eclipse , -. , , . Java . , . Java. Eclipse , , , .

8


.. , .. , Java- Eclipse

1. Eclipse
Eclipse -- Java, . SDK Eclipse (IDE, Integrated Development Environment) . Eclipse , 2001 . . Object Technology International (OTI), IBM. 2001 . Eclipse 50 . Eclipse Eclipse Foundation Eclipse, http://www.eclipse.org. Eclipse Java : ( ), Ant. Eclipse (), , UML, . Eclipse -- , , , . Eclipse : C/C++, Html, Cobol, Perl, Php, Ruby . Eclipse.

1.1.
Eclipse , Linux, Microsoft Windows Mac OS. JVM (Java Virtual Machine) -- Java-, JDK (Java Development Kit) -- Java-. Java -- http://java.sun.com. ALT Linux «» . 1 Eclipse.

9


.. , .. , Java- Eclipse

1 Jva 1.4.0 128 - 300 533 1.6.0 1 1 1,5

1.2. Eclipse
IDE Eclipse . , : , , , . (workspace) -- , . , , . : /home/user/workspace. Eclipse Eclipse . , . , , (), JDT, .. (workbench) , Eclipse (. 6). . (perspective) -- , , . , . . 10


.. , .. , Java- Eclipse

. , . , Java, , : Debug, Java Browsing, Java. Eclipse . Window / Open Perspective. , (, , , .). , , , , . Window / Show View. . 2. 2 Debug Java Browsing Java Breakpoints, Debug, Variables, Expressions, Task, Outline, Console Projects, Packages, Types, Members Package Explorer, Hierarchy, Outline, Declaration Problems, Javadoc,

(project) . Java , : .java, .jsp, .xml. (plug-in) , Eclipse. JDT.

11


.. , .. , Java- Eclipse

-- , . Eclipse , , . , , , , .. (. 1).

. 1.

1.3. Eclipse
Eclipse, , JRE ( 1.3 ). JRE , : java -version Eclipse Linux, , DVD Linux «». Synaptic.
12


.. , .. , Java- Eclipse

KDE. «»/« ( Synaptic)». (). Eclipse, «» , , «Eclipse» (. 2).

. 2. Synaptic Eclipse , DVD Linux «». : apt-cdrom add . , , « ».

13


.. , .. , Java- Eclipse

1.4. Eclipse
, -- (workspace) (. 3).

. 3. , Java. , workspace, , . File / Switch Workspace. -- (.java, .jsp ), (.xml) Workspace. , «OK», (. 4), 5 : Overview -- , - eclipse; Tutorials -- , Java; What's new -- « », ; Samples -- , , , ; Workbench -- « » -- .

14


.. , .. , Java- Eclipse

. 4. , , «Workbench». (. 5).

. 5.
15


.. , .. , Java- Eclipse

Java. . 5 , . , , , , . Java. Java . 6 Eclipse Java.

. 6. Java . 7 , Java-. , .

16


.. , .. , Java- Eclipse

. 7. Java, Java Browsing, Debug Java. Java . ( 1, . 6). Eclipse ( ). (2, . 6). ( 7, . 6). , . ( 8, . 6). 4 : 1) Problems -- , ; 2) Javadoc -- ; 3) Declaration -- , ; 4) Console -- , . () ( 3, . 6) . : Java, Debug Java Browsing (. 7); (6, . 6) Java.
17


.. , .. , Java- Eclipse

1.5.
, . Java. 3 File . , , ., , , , , , , : , , , , , , , , , : , , .. . (, ), , , . . , : , , , javadoc . , , , . .
18

Edit

Source

Refactor

Navigate Search

Project Run

Window


.. , .. , Java- Eclipse

Help

, Eclipse

Eclipse. . -- (, , , , .), File. -- , -- Run. -- , Java- (, , ) -- . , , , . , , . , , , . -- ( Problems); ( javadoc); ( declaration). , , Java, Debug, Java Browsing, C++ . « », , ( 9, . 6). (), , Ant, Problems, Search, Navigator .. - , Package Explorer, . , , . 19


.. , .. , Java- Eclipse

: , Package Explorer Hierarchy, , , . , , . , . . , , , . , , , -- . - , , , , . , . -- , . Java ( ), , Java. () , , . Problems () : , , . : (), . «» . - : , , , ,
20


.. , .. , Java- Eclipse

. Eclipse : , , .. , - . , -- , , , .. . , . Eclipse. . , . , . , Eclipse. , Eclipse « » : , , , .., . . . 1. ErrorTests.java : public class ErrorTests { public static void main(String[] args) { System.out.print(«Hello»); } } 2. , (. 8).

. 8.
21


.. , .. , Java- Eclipse

3. «». ( 9): Problems, . Package Explorer, Type, Hierarchy Outline Java, , . , , . , ,

. 9. 4. (. 10).

. 10.
22


.. , .. , Java- Eclipse

5. «» ("X") , . 6. Problems, . «Go To» (. 11). .

. 11. 7. . «Save». . 8. C System.out.print(«Hello»); System.out.print(«Hello»+x);. 9. , x, . , . 10. . , (. 12).

. 12.

23


.. , .. , Java- Eclipse

11. Ctrl+1

, Quick Fix Edit . . (. 13).

. 13. QuickFix 12. «Create field 'x'» . x , . 13. General/Editors/Text Editors/Annotations. Navigator () Navigator , . , , , Window/Show View/Navigator. src (source) .java -- . bin (binary) , - Java. .classpath .project . Outline () Outline Java, (, , ..), . , , 24


.. , .. , Java- Eclipse

, Window/Show View/Outline. , , , , . .

1.6.
. (. 14) , Window/Preferences.

. 14. Eclipse : . 25


.. , .. , Java- Eclipse

. , , , , . , . 4. 4 Eclipse General Ant Ant C/C++ Help ++ , , , Web- Eclipse, , Eclipse Java, , Java- Web. , Apache MySQL , . , , -- , .
26

,

Install/Update Java

PHPeclipse Web Development

Run/Debug Tea m


.. , .. , Java- Eclipse

. 4 Java General Java. .

1.7.
Java , JRE, , . . , IDE, . . Hello. (. 15) Java Project ( Java).

. 15. (. 16).

27


.. , .. , Java- Eclipse

. 16. Project name ( ) «Hello». Contents () Create new project in workspace ( ), , , Create project from existing source ( « »), , Eclipse. Create new project in workspace ( ). JRE (Java Runtime Environment) JRE
28


.. , .. , Java- Eclipse

, Use default JRE ( JRE ). Project layout ( ) : (Separate folders), (as root), . «Finish». « » , . 17.

. 17. « » Package explorer . : Class (. 18).

29


.. , .. , Java- Eclipse

. 18. (. 19).

. 19. Source folder , Hello/src, ,
30


.. , .. , Java- Eclipse

Hello/src, Hello, src -- , . Package () , , , src. Name HelloWorld; , , Name , Finish . , - . , : public static void main(String[] args) -- main(); Constructor from superclass -- -; Inherited abstract methods -- . «Finish». HelloWorld (. 20), .

. 20.
31


.. , .. , Java- Eclipse

. Package Explorer , , «Project», «Close», , Package Explorer, «Close». java- JDK. javac, .class -- java. .java, , () : javac [options] _ [@argfiles] Options -- , «-». : -version -- ; -encoding -- ; -nowarn -- . : man javac _ -- , . , , /home/user. , .java-, . @argfiles -- , . , ( files), ( params). javac @params @files , . , . . /home/user/workspace/Hello/src/ErrorTests.java

32


.. , .. , Java- Eclipse

user, workspace Hello . (User -- , workspace -- , Hello -- Java-). : javac workspace/Hello/src/ErrorTests.java ErrorTests.class. : java [options] _.class [params] java workspace/Hello/src/ErrorTests.java «Hello».

1.8. , ,
Eclipse -- , , . (Help) Eclipse. Eclipse. , . , Edit/Add Bookmark. Bookmark . ( ) : Window/Reset Perspective. , .class Eclipse, , Clean Proect/Clean. , Build automatically, .
33


.. , .. , Java- Eclipse

, , .classpath, .project, metadata . , . Eclipse Eclipse, , Synaptic. . . 5 , Eclipse. 5 Ctrl+N Ctrl+M Ctrl+Shift+ Ctrl+Shift+M Ctrl+F Ctrl+H Ctrl+K Ctrl+/ Ctrl+F6 Ctrl+F8 Ctrl+F7 Tab Shift+Tab F12 F3 Alt+ , , . . .



34


.. , .. , Java- Eclipse


Eclipse 1. Eclipse -- http://www.eclipse.org/ 2. Eclipse -- http://www.eclipse.org/community/ 3. , Eclipse -- http://www.eclipse.org/artic 4. Eclipse -- http://www.eclipse.org/whitepapers/eclipse-overview.pdf 5. EclipseCon -- http://www.eclipsecon.org/ 6. Common Public License Version 1.0 -- http://www.eclipse.org/legal/cpl-v10.html 7. Eclipse -- http://www-128.ibm.com/developerworks/library/os-ecl-read/? S_TACT=105AGX01&S_CMP=LP 8. Eclipse -- http://www.ibm.com/developerworks/ru/opensource/topprojects/eclipse.html Ant Ant -- http://ant.apache.org/ Apache Web- Apache -- http://www.apache.org/ OpenOffice.org -- http://www.openoffice.org/ Java 1. Java. [ ] http://java.sun.com/docs/ 2. Java (Java Tutorial). [ ] -- http://java.sun.com/docs/books/tutorial/ 3. (FAQ). [ ] -- http://www.afu.com/javafaq.html 1. Java Comp.lang.java.programmer 2. Comp.lang.java.*

les

-- .

35


.. , .. , Java- Eclipse

1. , IDE Eclipse. 2. Outline. 3. , Java. 4. Eclipse , ? ? 5. Problems?

36


.. , .. , Java- Eclipse

2.
-- . , . , . . Debuging . public class Debuging { public static void main(String[] args){ for (int i=0;i<10;i++){ System.out.print(" "+i+"\n"); } } } . , . Package Explorer, () , , . . 21 , .

. 21.
37


.. , .. , Java- Eclipse

, , . . System.out.print(" "+i+"\n");. , , (. 22), Java Debug.

. 22. Java, , . , , «Yes», , . 23. , , Debug, , , .

38


.. , .. , Java- Eclipse

. 23. Debug Debug : Debug. , (. 24).

. 24. Debug . Variables , . ,


39


.. , .. , Java- Eclipse

. , . Breakpoints , . , (. 25). () , -- .

. 25. Outline, . . . , . . ,

. («Resume») F8 . . , , , , i=0, Variables (. 26).

40


.. , .. , Java- Eclipse

. 26. , i 1. Variables , (. 27).

. 27. , F8 , . , , , . Eclipse , . , (), . , i<10 , ++D, , ( boolean) . , . . Debug.

41


.. , .. , Java- Eclipse

c , . Eclipse, . , , , . , , Breakpoint Properties, (. 28 ). Enable Condition ( ) , . , (i%2)==0. «» , i 2 0, , i . , , , . -- , -- condition is 'true' value of condition changes. , , «», , , . Suspend Policy . Suspend Thread thread, Suspend VM -- Java.

42


.. , .. , Java- Eclipse

. 28

43


.. , .. , Java- Eclipse

3.
1 . Eclipse. . IDE Eclipse. . Eclipse. , . , .

1. : Java, Java Browsing, Debug. . 2. . Java : Problems, Members . Java Browsing : Debug, Display, Memory . 3. newProject1. : wnclass1, wnclass2, wnclass3. 4. , 3: fqrs1, fqrs2, fqrs3.
44


.. , .. , Java- Eclipse

5. New. 6. 3. 7. Eclipse c newClock JDKX.X.X./Demo/Clock. 2 . Java. . Java. . , Java. 1 . . 01 public class Hello { public static void main(String[] args) { 02 System.out.print(" Java!"); 03 04 } 05 } : , Eclipse. ( ). Hello (01), main()(02). . , , , , , System.out print. println . 2 . . 01 public class Hello2 { 02 // Java main public static void main(String[] args) { 03 System.out.println("\n \n \n Java!"); 04 05 } // main 06 } // Hello2

45


.. , .. , Java- Eclipse

Escape : \n- , \t , \r- , \\- , \» - . 1. : =1, c=a+1 m=2, n=3 b=6, d=b*2-1 p=4, g=5 2. : 1 123 12345 1234567 3 . Java. . Java. . , For, While . 1 . 10 . 01 public class ForCycle { public static void main(String[] args) { 02 int tmp = 0; 03 long tmp2 = 1; 04 System.out.print("\t\t \n"); 05 for(int i=0;i<10;i++){ 06 tmp += (int)Math.round(Math.random()*10); 07 08 tmp2 = tmp2*tmp; System.out.print(tmp+"\t\t"+tmp2+"\n"); 09 } 10 11 } 12 } 02 main(). tmp int (tmp=0, tmp 03). tmp 10 . tmp2 long, (04). FOR (06-10) .
46


.. , .. , Java- Eclipse

Math.random(), 0 1. 10 Math.round() 09. 2 . . 01 public class Sqrt { static void sqrt(long a){ 02 double b=a; 03 int i=0; 04 while ((b*b>a)&&(i<200)){ 05 b=(b+a/b)/2; 06 07 i++; 08 } System.out.print(b); 09 10 } public static void main(String[] args) { 11 sqrt(45); 12 13 } 14 } X
n 1

1 a = X n . 2 Xn

while ((b*b>a)&&(i<200)). 02 sqrt() a long. b double (b=a, b 03). b , b=(b+a/b)/2. i int 0. . While (05-08) ((b*b>a)&&(i<200)). : b a 200, 200 . Xn, b (06). b , . i 1 07. b .
47


.. , .. , Java- Eclipse

main() sqrt(45). (45), a. (, - , static, , ). 1. 2n. 2. n<10. 3. . , . . 4. h. . 5. (b), (c) (a). . 4 . Java. . Java. . , . . 1 . . 01 public class Pi { static double pi; 02 static void leibnic(){ 04 for(double i=1;i<100000000;i+=1){ 05 if (i%2==0){ 06 pi-=1/(2*i-1); 07 }else{ 09 pi+=1/(2*i-1); 10 } 12 13 } pi*=4; 14 15 16 17 18 19
System.out.print("\n , : "+pi); } static void vallis(){ double pi1=1, pi2=1; for(double i=2;i<100000000;i+=2){
48


.. , .. , Java- Eclipse

20 21 22 23 24 25 26 27 28 29 30

pi1*=i/(i+1); pi2*=i/(i-1);
pi=pi1*pi2*2; System.out.print("\n , : "+pi); } public static void main(String[] args) { leibnic(); vallis();

}

}

} : ( ) ( ). 02 03 static pi double. 27 leibnic(). 28 vallis(). : 11111 - + - + ... = 13579 4 , i%2==0, , pi+=1/(2*i-1), , . , , pi 4 . 22446688 ... = 13355779 2 -. pi1 pi2 double 18, , -- , pi . 2 . A3 B3C3= ABC 01 02 03 04 05 06 07 08 09
public class Sol { public static void work(){ long x=0; for(int i=1;i<10;i++){ for (int j=0;j<10;j++){ for (int k=0;k<10;k++){

x=i*100+j*10+k;
if (x==(Math.pow(i,3)+Math.pow(j, 3) + Math.pow(k,3))){ System.out.println(i+"^3+"+j+"^3+"+k+"^3+"+" = "+x);
49


.. , .. , Java- Eclipse

} } A, B C, , . , , , 07-09 (10x10x10). x, , , , . x , x. pow() Math, , Math.pow(i,3). i*i*i, j*j*j k*k*k. 1. , , n a bn= cn ( ) 1 100 n>2. , n=2, . 111 1 1 - 2. 1 - + - + ... + , 234 9999 10000 . 5 . Java. . Java. . , , . 1 . . 01 public class Trans { public static String fromdectobin(int x){ 02 String res=""; 03
50

10 11 12 13 14 15 16 17 18

} } } } }
public static void main(String[] args) { work();


.. , .. , Java- Eclipse

04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51

short q = 0; while(x>0){ q=(short)(x%2);

x/=2; res=q+res; } }
return res; public static String fromdectohex(float x){

String res="";

short q = 0; int c = 2; while(c>0){ q=(short)(16*(x/16-Math.floor(x/16))); c=(int) Math.floor(x/16);

x=c;

if(q<10){ }else{ switch(q){ case 10: break; case 11: break; case 12: break; case 13: break; case 14: break; case 15: break;

res=q+res;

res="A"+res; res="B"+res; res="C"+res; res="D"+res; res="E"+res; res="F"+res;

} } } }
return res; public static void main(String[] args) { System.out.println(fromdectobin(90367)); System.out.println(fromdectohex(90367)); }

}

51


.. , .. , Java- Eclipse

, , -- . -- 2 , res (08). while(), 2, 2 . , , . , 16, -- floor(), . . , , 0 9 A-F. , switch(), . , ( 23-42). fromdectobin, fromdectohex String, print() ( 48, 49). , . 1. 0 9 . , 9 «».

52


.. , .. , Java- Eclipse

6 . . . Java. . : , . 1 . public class Arrays { 01 public static short minX(){ 02 short x=0; 03 short[] array = new short[10]; 04 System.out.print(" : "); 05 for (int i=0;i<10;i++){ 06 array[i]=(short)Math.round(50*Math.random()); 07 System.out.print(array[i]+", "); 08 09 } 10 x=array[0]; for(int i=1;i<10;i++){ 11 if(x>array[i]){ 12 13 x=array[i]; 14 } 15 } return x; 16 17 } public static void sort(){ 18 short temp; 19 short[] array = new short[10]; 20 System.out.print("\n : "); 21 for (int i=0;i<10;i++){ 22 array[i]=(short)Math.round(50*Math.random()); 23 System.out.print(array[i]+", "); 24 } 25 System.out.print("\n : "); 26 for(int i=0;i<9;i++){ 27 for(int j=9;j>i;j--){ 28 if(array[j-1]>array[j]){ 29 30 temp=array[j]; 31 array[j]=array[j-1]; 32 array[j-1]=temp; 33 } 34 } System.out.print(array[i]+", "); 35 36 } 37 } 38 public static void main(String[] args) { 39 System.out.print("\n : "+minX()); 40 sort(); 41 }
53


.. , .. , Java- Eclipse

} -- minX() sort(). , (04, 20). Math.random() (06-09, 22-25). (short) double short (7,23). , , . minX() (11-15). (27-34) . (35). main() minX() sort(). minX() , System.out.print(). 2 . 01 public class Strings { public static String compare(String s1, String s2){ 02 03 String s3=""; if (s1.equals(s2)){ 04 s3=" \""+s1+"\" \""+s2+"\" "; 05 } else { 06 07 s3=" \""+s1+"\" \""+s2+"\" "; } 08 return s3; 09 10 } public static String add(String s1, String s2){ 11 12 13 14 15 16 17 18 19 20 21
System.out.print("\n \""+s1+"\" "+"\""+s2+"\": "); s1+=" "+s2; return s1;

42

}
public static void main(String[] args) { System.out.println(compare("","")); System.out.print(compare("","")); System.out.print(add("Hello","World")); }

} , . compare() . equals() (04). , true. ( 54


.. , .. , Java- Eclipse

), (05), (07). s3 (05, 07) Escape-, 2. «+»(13). 1. A(n), n=1,25. . 2. B(n), n=1,25. . 3. (n), n=1,20. . 4. D(n), n=1,30. . 5. , 35 (a(i,j)< 10). 6. 1 , ( , maxX()). 7. 5 s1, s2, s3, s4 s5, : s4 s5, s1 s2, s1 s3. 7 . - . . - Java. . , - . 1 . . public class Encapsulate { 01 public int field1 = 100; 02 protected int field2 = 150; 03 int field3 = 200; 04 private int field4 = 250; 05 public int getField4(){ 06 return this.field4; 07
55


.. , .. , Java- Eclipse

08 09 10 11 12 13 14 15 16 17 18 19 20

} } }

public static void main(String[] args) { new Class2().method1();

class Class2 extends Encapsulate { public void method1(){ System.out.println(" public - field1: "+this.field1); System.out.println(" protected - field2: "+this.field2); System.out.println(" - field3: "+this.field3); System.out.println(" private - field4: "+getField4()); }

} - : . Encapsulate (01-12), filed1, filed2, filed3 filed4. , : public, protected, private. Class2, Encapsulate extends. , , , . , Class2 , Encapsulate, getField4(). main() Encapsulate, method1() Class2 , 10. , filed4, private, , . 18, getField4() this.filed4. Eclipse , , Encapsulate.field4 . (, ). 2 . . 01 public class Polymorph { void method1(){ 02 System.out.println(" 03
56


.. , .. , Java- Eclipse

04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20

Polymorph"); } public static void main(String[] args) { new NewClass1().method1(); new NewClass2().method1();

} }
class NewClass1 extends Polymorph { void method1(){ System.out.println(" NewClass1"); }

}
class NewClass2 extends Polymorph { void method1(){ System.out.println(" NewClass2");

} } . Polymorph, NewClass1, NewClass2, Polymorph NewClass1, NewClass2. Polymorph method1() (02), . NewClass1, NewClass2 (override), . main() . , - . , , , «». 1. , : fclass1, fclass2, fclass3. fclass1 main(). fclass3 fclass1, fclass2 -- fclass3. 2. , : fclass1, fclass2. fclass1 main(). fclass2 fclass1.

57


.. , .. , Java- Eclipse

8 . . . . . . . , . , . , , (, Eclipse, ). , Package explorer, (. 15), «Folder». «MyGraph». : «Graphic» -- , main(). «Sinus» -- . «Cosinus» -- . «X2» -- . , public, protected private, , . , , . 1 . . Graphic 01 package MyGraph; 02 import java.awt.*; 03 import java.awt.event.*; 04 import javax.swing.*; 05 public class Graphic extends JFrame{ Graphic(String s){ 06 super(s); 07 setLayout(null); 08 setSize(120,200); 09 setVisible(true); 10 this.setDefaultCloseOperation(EXIT_ON_CLOSE); 11 this.setResizable(false); 12 Button sin = new Button("Sin"); 13 sin.setBounds(5, 20, 100, 25); 14
58


.. , .. , Java- Eclipse

15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41

add(sin); Button cos = new Button("Cos"); cos.setBounds(5, 70, 100, 25); add(cos); Button x2 = new Button(""); x2.setBounds(5, 120, 100, 25); add(x2); sin.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent event){ new Sinus(""); } }); cos.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent event){ new Cosinus(""); } }); x2.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent event){ new X2(""); } }); } public static void main(String[] args) { new Graphic(""); } }

Sinus 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20
package MyGraph; import java.awt.Color; import java.awt.Graphics; import javax.swing.JFrame; public class Sinus extends JFrame{ Sinus(String s){ super(s); setLayout(null); setSize(600,300); setVisible(true); this.setDefaultCloseOperation(DISPOSE_ON_CLOSE); this.setResizable(false); this.setLocation(100, 100); } public void paint(Graphics gr){ int y; int j=0; int k=0; gr.setColor(Color.WHITE); gr.fillRect(0, 0, 600, 300); gr.setColor(Color.lightGray); while(j<600){
59


.. , .. , Java- Eclipse

21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43

gr.drawLine(j, 0, j, 300); j+=30; } while(k<300){ gr.drawLine(0, k, 600, k); k+=30; } gr.setColor(Color.BLACK); gr.drawLine(300, 0, 300, 300); gr.drawLine(0, 150, 600, 150); gr.drawLine(120, 140, 120, 160); gr.drawLine(480, 140, 480, 160); gr.drawString("0", 305, 165); gr.drawString("-"+"\u03c0", 125, 140); gr.drawString("\u03c0", 485, 140); gr.setColor(Color.RED); for(double i=0;i<1000;i++){ y=(int)(80*Math.sin(Math.PI*i/180)); gr.drawLine((int)i-240, y+150, (int)i-240, y+150); } gr.dispose(); } }

Cosinus 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
package MyGraph; import java.awt.Color; import java.awt.Graphics; import javax.swing.JFrame; public class Cosinus extends JFrame{ Cosinus(String s){ super(s); setLayout(null); setSize(600,300); setVisible(true); this.setDefaultCloseOperation(DISPOSE_ON_CLOSE); this.setResizable(false); this.setLocation(200, 200); } public void paint(Graphics gr){ int y; int j=0; int k=0; gr.setColor(Color.WHITE); gr.fillRect(0, 0, 600, 300); gr.setColor(Color.lightGray); while(j<600){ gr.drawLine(j, 0, j, 300); j+=30; } while(k<300){
60


.. , .. , Java- Eclipse

25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43

gr.drawLine(0, k, 600, k); k+=30; } gr.setColor(Color.BLACK); gr.drawLine(300, 0, 300, 300); gr.drawLine(0, 150, 600, 150); gr.drawLine(120, 140, 120, 160); gr.drawLine(480, 140, 480, 160); gr.drawString("0", 305, 165); gr.drawString("-"+"\u03c0", 125, 140); gr.drawString("\u03c0", 485, 140); gr.setColor(Color.RED); for(double i=0;i<1000;i++){ y=(int)(80*Math.cos(Math.PI*i/180)); gr.drawLine((int)i-240, y+150, (int)i-240, y+150); } gr.dispose(); } }

X2 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
package MyGraph; import java.awt.Color; import java.awt.Graphics; import javax.swing.JFrame; public class X2 extends JFrame{ X2(String s){ super(s); setLayout(null); setSize(600,300); setVisible(true); this.setDefaultCloseOperation(DISPOSE_ON_CLOSE); this.setResizable(false); this.setLocation(300, 300); } public void paint(Graphics gr){ int y; int j=0; int k=0; gr.setColor(Color.WHITE); gr.fillRect(0, 0, 600, 300); gr.setColor(Color.lightGray); while(j<600){ gr.drawLine(j, 0, j, 300); j+=50; } while(k<300){ gr.drawLine(0, k, 600, k); k+=50; } gr.setColor(Color.BLACK);
61


.. , .. , Java- Eclipse

29 30 31 32 33 34 35 36 37 38 39 40

gr.drawLine(300, 0, 300, 300); gr.drawLine(0, 150, 600, 150); gr.drawString("0", 305, 165); gr.setColor(Color.RED); for(double i=0;i<1000;i++){ y=-(int)(i*i/300)+150; gr.drawLine((int)i+300, y, (int)i+300, y); gr.drawLine(-(int)i+300, y, -(int)i+300, y); } gr.dispose(); } }

Graphics 120200, . () , ActionEvent. , (22-26, 27-31, 32-36). addActionListener() (22, 27, 32). , ActionListener actionPerformed(), , ( ). , , 20-27 - , . 37-40 ( ) 33-37 ( ) . : y drawString() «» . y double int, 80*Math.cos(Math.PI*i/180). , . . 2 . . 01 import java.awt.*; 02 import java.awt.event.*; 03 import javax.swing.*; 04 public class ExtEventHandler extends JFrame {
62


.. , .. , Java- Eclipse

} } ExtEventHandler (04-24) : 100x200 : (12-14) (15-17). , , Handler (25-38), ActionListener. ActionListener , ExtEventHandler, , . 26, 27, (30, 31). , (18, 19), .
63

05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38

ExtEventHandler(String s){
super(s); setLayout(null);

setSize(100,200);

setVisible(true); setResizable(false); setDefaultCloseOperation(EXIT_ON_CLOSE); Button b1 = new Button(" ");

b1.setBounds(2, 5, 96, 22); add(b1);

Button b2 = new Button(" ");

b2.setBounds(2, 100, 96, 22); add(b2); } } }

b1.addActionListener(new Handler(b1, b2)); b2.addActionListener(new Handler(b1, b2)); public static void main(String[] args) { new ExtEventHandler("");

class Handler implements ActionListener{ private Button ba; private Button bb;

String temp; Handler(Button b1, Button b2){
this.ba=b1; this.bb=b2;

}

public void actionPerformed(ActionEvent e) {

temp = ba.getLabel(); ba.setLabel(bb.getLabel());
bb.setLabel(temp);


.. , .. , Java- Eclipse

, (34-36). 1. 500500 . 2. . , 200150. «». , , . 9 . . . Java-. . . 1 . . 01 02 03 04 05 06 07
import java.awt.*; import java.applet.*; public class My_Applet extends Applet{ public void paint(Graphics g){ g.drawString("Hello, World!", 5, 30);

} } -

Java-, (05) drawString(). Eclipse AppletViewer. 2 . . 01 import java.awt.*; 02 import java.awt.event.ActionEvent; 03 import java.awt.event.ActionListener; 04 import java.applet.*; 05 public class My_Applet extends Applet{ public void init(){ 06 setLayout(null); 07 final TextField tf1 = new TextField(15); 08 09 tf1.setBounds(1, 1, 100, 20); 10 add(tf1); final TextField tf2 = new TextField(15); 11 12 tf2.setBounds(1, 25, 100, 20); 13 add(tf2);
64


.. , .. , Java- Eclipse

14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30

final TextField tf3 = new TextField(15);

tf3.setBounds(1, 50, 100, 20); add(tf3); b1.setBounds(1, 100, 100, 20); add(b1);

Button b1 = new Button(" 1");

b1.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent event){ try{ tf3.setText(String.valueOf((Long.valueOf(tf1.getText()) +Long.valueOf(tf2.getText())))); }catch(Exception e){

tf3.setText(" "); } } });

} } , . ( 8). Java, , init(). 1. 1 8 . 2. , 33. drawString(). 10 . «». . Java. . . . 1 . . import java.awt.*; // awt 01 import java.awt.event.*; // 02 import javax.swing.*; // swing 03 04 05 06 07
public class Calc extends JFrame{ // Calc, . JFrame double temp = 0; // temp double Char op = ''; // op char Calc(String s){ // Calc
65


.. , .. , Java- Eclipse

08 09 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53

super(s); // (JFrame) setLayout(null); // setSize(250,250); // setVisible(true); // this.setDefaultCloseOperation(EXIT_ON_CLOSE); // final TextField display = new TextField(""); // TextField display ( ) display.setEditable(false); // display.setBounds(2, 2, 238, 22);// add(display); //

Button b1 = new Button("1");
b1.setBounds(2,30,40,40); add(b1); Button b2 = new Button("2");

b2.setBounds(52,30,40,40); add(b2); Button b3 = new Button("3"); b3.setBounds(102,30,40,40); add(b3); Button b4 = new Button("4"); b4.setBounds(2,80,40,40); add(b4); Button b5 = new Button("5"); b5.setBounds(52,80,40,40); add(b5); Button b6 = new Button("6"); b6.setBounds(102,80,40,40); add(b6); Button b7 = new Button("7"); b7.setBounds(2,130,40,40); add(b7); Button b8 = new Button("8"); b8.setBounds(52,130,40,40); add(b8); Button b9 = new Button("9"); b9.setBounds(102,130,40,40); add(b9); Button b0 = new Button("0"); b0.setBounds(2,180,40,40); add(b0); Button beq = new Button("="); beq.setBounds(52,180,90,40); add(beq); Button bplus = new Button("+"); bplus.setBounds(152,30,80,40); add(bplus); Button bminus = new
66

17-61 15 : 10 , 4 . . .


.. , .. , Java- Eclipse

Button("-"); 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 { public void actionPerformed(ActionEvent event) { display.setText(display.getText()+"1"); } }); b2.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { display.setText(display.getText()+"2"); } }); b3.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { display.setText(display.getText()+"3"); } }); b4.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { display.setText(display.getText()+"4"); } }); b5.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { display.setText(display.getText()+"5"); } }); b6.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { display.setText(display.getText()+"6");
67

bminus.setBounds(152,80,80,40); add(bminus); Button bmul = new Button("*"); bmul.setBounds(152,130,80,40); add(bmul); Button bdiv = new Button("/"); bdiv.setBounds(152,180,80,40); add(bdiv); b1.addActionListener(new ActionListener()

62-140 . -- , -- «» op , temp display , .


.. , .. , Java- Eclipse

90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 {

} }); b7.addActionListener(new ActionListener() public void actionPerformed(ActionEvent event) { display.setText(display.getText()+"7"); } }); b8.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { display.setText(display.getText()+"8"); } }); b9.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { display.setText(display.getText()+"9"); } }); b0.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { display.setText(display.getText()+"0"); } }); bplus.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { op = '+'; temp = Double.valueOf(display.getText()); display.setText(""); } }); bminus.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { op = '-'; temp = Double.valueOf(display.getText()); display.setText(""); } }); bdiv.addActionListener(new ActionListener() {
68


.. , .. , Java- Eclipse

128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156

public void actionPerformed(ActionEvent event) { op = '/'; temp = Double.valueOf(display.getText()); display.setText(""); } }); bmul.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { op = '*'; temp = Double.valueOf(display.getText()); display.setText(""); } }); beq.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { switch(op){ case '+': display.setText(String.valueOf(temp+Double.v alueOf(display.getText()))); break; case '-': display.setText(String.valueOf(tempDouble.valueOf(display.getText()))); break; case '*': display.setText(String.valueOf(temp*Double.v alueOf(display.getText()))); break; case '/': display.setText(String.valueOf(temp/Double.v alueOf(display.getText()))); break; } } });

141-151 «=». op, , temp , .

} // Calc public static void main(String[] args) { // main() new Calc("Calculator"); // Calc } // main() } // Calc

1. , , NumberFormatException.

69


.. , .. , Java- Eclipse

2. -- «» « », , , .

70


.. , .. , Java- Eclipse


AWT -- Abstract Windowing Toolkit -- () . -- , . (abstract class) -- , , . , , . (abstract method) -- , . -- , . Array () -- . . - (bytecode) -- - , Java- Java-. (byte) -- . Java byte. JAVA -- " ", - Java ( ). (return) -- . -- , , . GUI -- . . -- -- AWT SWING.

71


.. , .. , Java- Eclipse

-- , , , . -- . -- , . Event -- . . -- . , , . , , , , , , , . . . -- , . Inheritable -- . . -- , , ( ), , . , . Java, , Object. -- - - , . -- , . -- , ( ). , implements.
72


.. , .. , Java- Eclipse

-- , «» , «». -- , «» . -- , , , throw. , . -- , , . -- Java, . , . -- AWT SWING. -- . -- , ( JAVA //), . -- , , . final. -- , , . , . -- , , , . -- , . / . -- ,
73

-- , .


.. , .. , Java- Eclipse

-- , . -- , . static. (array) -- , ( ). -- - , , , , , . -- , . , . . -- , , static. -- - , . -- , , . Name -- . . -- - . ( ) ( ). - -- , . -- , , . -- , .
74


.. , .. , Java- Eclipse

-- , . -- . -- , , . -- , . -- , . -- . , . -- , , , . -- , . -- , . -- Event. -- , , . -- , . -- , . Object . -- , .

75


.. , .. , Java- Eclipse

-- , , , - . , , . -- , . -- , . , , . -- , , . -- , .

76


.. , .. , Java- Eclipse


: 1. . Eclipse IDE : . . -- .:-, 2006. -- 160 . 2. . . Java 2. -- .: -, 2007. -- 720 . 3. . Java. -- .: , 2007. -- 1040 . 4. ., . Java 2. -- C:, BV--, 2008. -- 1072 . 5. .. , Sun Microsystems Teaching Grants 2006 -- « Java». , 2006. 6. - http://ru.sun.com : 7. . Java. . -- .: , 2008. -- 224 . 8. . Java Spring, Hibernate Eclipse. -- .: , 2008. -- 352 . 9. . . Java 2. -- .: -, 2007. -- 720 . 10. . Swing. . -- .: , 2007. -- 704 . 11. . Eclipse IDE : . . -- .:-, 2006. -- 160 .

77