Application window programming in the J2SE environment (System class FrameInterface ActionListenerAWT class)

xiaoxiao2021-03-06  39

Application window programming in the J2SE environment (System class Frame / Interface ActionListener / AWT class)

Application window program design step in a jbuilder environment

Start JBUILDER

2. Establish an empty project

3. Create a new source java file

4. Join Application Basic Structure and Generate Window Code // A Notes ------------------ / * A Note * / / / B Pack Settings Part - ---------------------- Package SK2; // B Settings package // C imported package part ----------- ------------ Import java.awt. *; // with window design GUI package import java.awt.event. *; // message event class and interface // D function class Definition section ------------ (Inherited Class Implementation Interface) Class SK2C Extends Frame Implements ActionListener // D Class Definition {// Text Component TextField TF = New TextField ("text box"); // Button component button bt1 = new button); button bt2 = new button ("exit"); // Menu component MenuBar MB = new menubar (); menu m1 = new menu ("file"); menuitem I1 = New Menuitem ("CZ1"); Menuitem I2 = New Menuitem ("CZ2"); MenuItem I3 = New MenuItem ("CZ3"); Public SK2C () {this. Add (TF); this.Add (BT1); this .add (bt2); m1.Add (I2); m1.Add (i3); Mb.Add (m1); this.setmenubar (MB); bt1.addactionListener (this); ///////// Listening button Bt2.addActionListener (this); I1.AddActionListener (this); // Mathered submenu} public void actionPerformed (ActionEvent E) // interface method implementation message code {if (E.getsource () == bt1) {TF .SETTEXT ("Haha");} else if (E.Getsource () == bt2) {dispose (); system.exit (0);} else if (E.Getsource () == i1 ) {tf.settext ("coco");}}} // E function interface definition section -------------------- / * Interface SK1i // e Interface definition {public string str1 = "www"; // or default no private / protected public string getStr ();} * / // f Main test class definition section -------------- - Public class sk2 extends SK2C // Implements ActionListener ..... {Button Bt; Public SK2 () {bt = new button); this.add (bt);} public static void main (String Args []) {SK2 OBJ = New SK2 (); Obj.setLayout (new flowLayout ()); Obj.settsize (300, 200); Obj.SetTitle ("Using Application Structure Generating Window Programs"); Obj.show (); }} 5. Run Environment Setting A Settings Run Configuration Select Project B Select Run C in the Page Box (Server, etc.)

6. Compile connection operation

II Application Window Program Notes 1. Finishing the Window Design on the basis of the APP structure 2. The general structure requires 6 parts (there are fewer specific procedures)

3. The required class package (the import portion will be much as needed) (java.awt. * / Java.awt.event. * Et al - one aspect of mastering Java)

4. Composition of Functions (Writing Class Followed Four Features - Package, Inheritance, Polymorphism, Abstract) Member Variable (Object Property) Member Method (Function) (Object Behavior) By Inherited System Framework Frame Implementation Interface Design By implementing system event interface ActionListener's method completes message code

5. Composition of the function interface (reflecting the data structure type of abstraction, the means of completing multiple inheritance) Confinition method definition (to perform the implementation of the implementation) Consider the refinement without custom interface

6. Make a primary class attribute - defined a button object primary class Other method main method public static void main (String args []) {object definition and object method call} is mainly through the defined class to generate an object, and then call Method implementation GUI interface

7. Use of containers and layouts (setLayout ()) framework frame / panel Panel / web vessel Applet / window Window / dialog Dialog Mobile FlowLayout / Border BorderLayout / Raster GridLayout / Card Cardlayout

8. The use of the AWT component (add ()) P170-180 Button / TextField / Menu ....

9.AWT Event Interface Type (Define Event Class, Implement Event Interface, Listen "

Window Event Interface Windowlistener

10. Menu Design Requirements (Add () / setmenubar ()) Menu Bottom Main Menu

转载请注明原文地址:https://www.9cbs.com/read-77274.html

New Post(0)