1) to put it simply, applets are small programs embedded in Web pages, Java code.
2) to write applets, to inherit the JApplet class, and according to their own needs to overwrite the relevant methods (init, start, stop,destroy< optional >) can be.
3) Applet life cycle:
Initialization phase: Init method (automatically called to complete initialization and layout assignment of graphical components)
Execution phase: The Start method (executes the code when the applet's current window is activated)
Termination phase: Stop method (when the applet program is closed)
Freeing resources: Destroy method
4) Add controls to the applet--init
5) The event handling model of the applet ——— first registers the events that need to be captured, and then writes the appropriate processing logic.
Button.addactionlistener (this);//Register, this indicates the applet program itself
public void actionperformed (ActionEvent e) {if (E.getactioncommand (). Equals ("name")) {label.settext ("Hello" + Text.gettext ()); }}//processing Logic
6) Insert the applet program into the Web page
Insert code where needed in the Web page: <applet code= "Helloworld.class" width=200 height=100></applet>//tells the browser the size of the applet's graphical interface
Then put the Helloworld.class and helloworld.html files in the same directory, click the HTML file to run.
or run applets directly using the Appletviewer command provided by the JDK: type Appletviewer helloworld.html under the relevant path in the DOS environment.
- AWT (Abstract window Toolkit, Abstraction Windows Toolkit)
1) AWT provides graphical controls that are common to all OS, such as buttons, menus, text boxes, and so on.
2) But AWT is built on the OS, so most of the components contain native code. Although native code codes guarantee the compatibility of the control with the OS, it also loses the flexibility of the controls in AWT. Using AWT to develop a graphical interface, we cannot change the appearance of the component, unless we write the C native code, which is a fatal blow to cross-platform, and AWT is inefficient.
3) So, get to know her. There are three types of controls: components (Label, button, and so on), Containers (window, Panel, applets), Layout Manager (FlowLayout, GridLayout, and so on).
4) also to conduct event monitoring, event processing.
- Swing ——— AWT Improvements to make graphical interface development easier
1) Swing is a lightweight graphical development tool with no native code and no reliance on the operating system, and Java's cross-platform has been greatly demonstrated on swing.
2) Three types of containers:
Top-level containers (JFrame, JApplet, JDialog, JWindow): Not lightweight and require native code because they need to communicate with the OS. Top-level containers cannot be added directly to components such as JButton, and other containers must be used.
Middle-tier containers (JPanel, JScrollPane, JSplitPane, JToolBar, etc.): lightweight containers.
Special containers (JInternalFrame, JLayeredPane, etc.): lightweight.
3) A rich set of components: The AWT has a component of swing, but just before the name of the J, are lightweight components.
4) Five layout managers: BorderLayout, FlowLayout, GridLayout, CardLayout, GridBagLayout.
5) Event monitoring and event handling mechanism: Like AWT, the delegate event mode, that is, to delegate event source events to different event listener classes for listening and processing, and only need to delegate the events of interest to the corresponding event listener class, instead of worrying about unwanted events.
6) do a little program to play it ...