Getting started by Java Applet 11

zhaozj2021-02-11  183

Getting started with Java Applet

YY435

Pacific Network Academy

Third day

2. Single selection button (CheckboxGroup)

What is the above example uses Java? Its syntax is as follows:

Import java.awt. *;

Import java.applet. *;

Import java.awt.event. *;

Public Class Danxuan Extends Applet Implements ItemListener

{

Public void init ()

{

CheckboxGroup CBG = New CheckboxGroup ();

Checkbox One = New Checkbox ("Correct", False, CBG);

Checkbox TWO = New Checkbox ("incorrect", False, CBG);

CheckBox Three = New Checkbox ("I don't know", true, cbg);

One.Additemlistener (this);

Two.additemlistener (this);

Three.Additemlistener (this);

Add (one);

Add (TWO);

Add (three);

}

Public Void ItemStateChanged (ItemEvent E)

{

}

}

Analysis: Chapter 9: Create a new form f, f, the name of the CHECKBOX Group: Call the function checkboxgroup Create a new radio button group CBG Chapter 11: Call the function Checkbox to establish the first option, the name is "One", the default status is false, that is, no prior selection. Chapter 12: Establishing an option that has been default the correct, named "Three". Sections 13, 14, 15: When the user clicks the check box makes its status, the selection events representatives will be triggered. This radio frame has already registered itself to the listener itemListener of the ItemEvent event. The system automatically calls the PUBLIC VOID ITEMSTATECHANGED (ITEMEVENT E) method in this itemListener to respond to the status change of the radio box. Actually realizing the listener of the ItemListener interface. Calling the getSelectBox () method of the checkboxgroup can get which button selected, this method returns the user-selected checkbox object, and then call the object's method getLabel () know what information has been selected. Similarly, by calling the checkboxGroup's setSelectCheckbox () method, you can specify which button in the single selection button group in the program. For example, the following statement description is not known: cbd.setselectedCheckBox (three); otherwise directly using the checkbox radio button in the button group, such as direct calls: one.getState (); you can know this button is selected Then, then other buttons must be in an unselected state. Lines 16, 17, 18: Add one, two, three, to the container F, so that it can be displayed on the screen. The 20th line is the event handler! Dedicated to handle the effect of single option changes! I didn't join the code here. So it cannot handle any events.

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

New Post(0)