Application Window Program Design in j2se environment (system class frame/interface actionlistener/AWT class)

Source: Internet
Author: User

Application Window Program Design in J2SE environment (system class Frame/interface ActionListener/AWT class)

Step 1: Design the application window program in Jbuilder Environment

1. Start Jbuilder

2. Create an empty project for the application

3. Create a source java File

4. Add the basic structure of the application and the Code for generating the window.
// A comments section --------------------
/*
A comment
*/
// Set part of Package B -----------------------
Package sk2; // B sets the class package
// C Import class package section -----------------------
Import java. awt. *; // GUI class package related to Window Design
Import java. awt. event. *; // message event class and Interface
// D function class definition section ------------ (inherited class implementation Interface)
Class sk2c extends Frame implements ActionListener // class D Definition
{
// Text Component
TextField tf = new TextField ("text box ");
// Button component
Button bt1 = new Button ("click ");
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 (i1 );
M1.add (i2 );
M1.add (i3 );
Mb. add (m1 );
This. setMenuBar (mb );
Bt1.addActionListener (this); // listener button
Bt2.addActionListener (this );
I1.addActionListener (this); // listens to sub-menus
}
Public void actionreceivmed (ActionEvent e) // The message code of the interface method.
{
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 ("main Button ");
This. add (bt );
}
Public static void main (String args [])
{
Sk2 obj = new sk2 ();
Obj. setLayout (new FlowLayout ());
Obj. setSize (300,200 );
Obj. setTitle ("generate a window program using the application structure ");
Obj. show ();
}
}

5. Set the runtime environment
A. Set the running configuration and select project.
B. Select Run in the page.
C Other settings (servers, etc)

6. Compile the connection to run

2. Notes for the application window
1. Design a window based on the app Structure

2. The general structure requires six parts (depending on the specific program situation)

3. Required class packages (there will be many import packages as needed)
(Java. awt. */java. awt. event. *, etc.-proficient in one aspect of java)

4. Composition of function classes (compiling classes follow four object-oriented features-encapsulation, inheritance, polymorphism, abstraction)
Member variables (Object Attributes)
Member method (function) (object behavior)
Implement interface design by Inheriting System Frame-like Frame
Complete the message code by implementing the System Event interface ActionListener

5. Composition of functional interfaces (reflecting abstract data structure types and completing multiple inheritance Measures)
Constant
Method definition (to complete implementation in the implemented class)
No custom interface for refined Training

6. Composition of the main class
Main class property-defines a Button Object
Other primary methods
Main method public static void main (string ARGs []) {object definition and object method call}
It is mainly to generate an object through the defined class and then call the method to implement the GUI.

7. Use of the container and layout class (setlayout ())
Frame frame/panel/Webpage container applet/window/dialog box Dialog
Flow flowlayout/Boundary borderlayout/GRID gridlayout/card cardlayout

8. Use of the AWT component class (add ())
P170-180
Button/textfield/menu ....

9. Use the AWT event interface type (define the event class, implement the event interface, listen to the trigger component, and implement the event method code)
Actionlistener
Adjustmentlistener
Project event interface itelistener
Mouse event interface mouselistener
Keyboard event interface keylistener

Window event interface windowlistener

10. Menu design requirements (add ()/setMenuBar ())
Menu Bar
Main Menu
Sub-menu

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.