This time through learning, I mastered the use of drop-down menus and radio buttons
Drop-down menu construction method:
JComboBox ()
Create a JComboBox with a default data model.
JComboBox (ComboBoxModel AModel)
Create a JComboBox whose entries are taken from the existing ComboBoxModel
JComboBox (object[] items)
Creates a JComboBox that contains the elements in the specified array.
JComboBox (vector<?> items)
Creates a JComboBox that contains the elements in the specified Vector.
Radio Button Construction Method:
Jradiobutton ()
Creates a radio button that is initialized to no selection, and its text is not set.
Jradiobutton (Action a)
Creates a radio button whose properties are from the provided Action.
Jradiobutton (icon icon)
Creates a radio button that is initialized to an unchecked selection with the specified image but no text.
Jradiobutton (Icon icon, Boolean selected)
Creates a radio button with the specified image and selection state, but no text.
Jradiobutton (String text)
Creates a radio button with the specified text with a status of not selected.
Jradiobutton (String text, Boolean selected)
Creates a radio button with the specified text and selection state.
Jradiobutton (String Text, icon icon)
Creates a radio button that has the specified text and image and is initialized to no selection.
Jradiobutton (String Text, Icon icon, Boolean selected)
Creates a radio button with the specified text, image, and selection state.
Use buttons, labels, drop-down menus, password boxes, text boxes, radio buttons and other components to write a "test entry" applet
Import java.awt.*;
Import java.awt.event.*;
Import java.awt.image.*;
Import javax.swing.*;
Import java.util.ArrayList;
public class Test extends JFrame {
Private static final String Version = "Green Chinese version 3.2.0";
Private JFrame frame;
Private JList lb;
Private JLabel Statuslabel;
Private JButton an1, an2,an3,an4,an5;//button
Private JLabel bq1, BQ2, Bq3, Bq4, Bq5, bq6,bq7,bq8,bq9,bq10,bq11,bq12;
Private JPanel MB1, MB2, MB3, Xuanxiang, CENTER,MB4;
Private JTextField wbk;
Private JPasswordField MMK;
Private JComboBox xlk;
Private JScrollPane GD;
Private Jradiobutton dx1,dx2;
Private Buttongroup dxz;
Private JDialog D;
Public Test ()
{
Makeframe ();
}
private void Makeframe () {
North
Xuanxiang = new JPanel ();
Bq4 = new JLabel ("Subject:");
BQ5 = new JLabel ("Education");
String[] JG = {"Level two computer", "level two C language", "Accounting practitioner Qualification Certificate", "English Four Level", "English Six", "Java Two"};
Xlk = new JComboBox (JG);
String[] xl = {"High school", "College", "undergraduate", "Master", "PhD"};
LB = new JList (XL);
Lb.setvisiblerowcount (1);
GD = new JScrollPane (lb);
This.setlayout (New GridLayout (2, 1));
Xuanxiang.add (BQ4);
Xuanxiang.add (XLK);
Xuanxiang.add (BQ5);
Xuanxiang.add (GD);
Center
Center = new JPanel ();
Bq4=new JLabel ("(a) the examinee guarantees not to use this website to engage in any activity which violates the laws and regulations and the policy stipulation,");
Bq9=new JLabel ("The examinee warrants not to conduct any malicious acts against this website. ");
Bq7=new JLabel ("(b) the candidate undertakes to read this agreement carefully, and after clicking" Agree ", said that it has been with me");
Bq10=new JLabel ("The parties voluntarily enter into this agreement and are fully bound by the terms of the agreement.") ");
Bq8=new JLabel ("(iii) the EXAMINEE undertakes to carefully read this system to instruct the examinee to operate the stipulation (for example the examination notice etc.)");
Bq11=new JLabel ("and strictly follow its requirements. ");
Dx1=new Jradiobutton ("agree");//Add Event response If you choose to agree you can click the registration button
Dx1.addactionlistener (new ActionListener () {
@Override
public void actionperformed (ActionEvent e) {
an3.setenabled (true);
}});
Dx2=new Jradiobutton ("disagree");//Add Event response If you choose not to agree, you can not click the registration button
Dx2.addactionlistener (new ActionListener () {
@Override
public void actionperformed (ActionEvent e) {
an3.setenabled (false);
}});
Dx1.setselected (TRUE);//radio button Default selection consent
Dxz=new buttongroup ();
Dxz.add (DX1); Dxz.add (DX2);
Bq12=new JLabel ("");
AN3 = new JButton ("registration");
An3.addactionlistener (New ActionListener () {
@Override
public void actionperformed (ActionEvent e) {
//TODO auto-generated method stub
Joptionpane.showmessagedialog (NULL, "Congratulations! You have successfully enrolled ");
}});
an4= New JButton ("Exit");
An4.addactionlistener (New ActionListener () {
@Override
public void actionperformed (ActionEvent e) {
//TODO auto-generated method stub
System.exit (0);
}});
Center.add (BQ4);
Center.add (BQ9);
Center.add (BQ7);
Center.add (BQ10);
Center.add (BQ8);
Center.add (bq11);
Center.add (BQ12);
Center.add (DX1); Center.add (DX2);
Center.add (BQ12);
Center.add (AN3); Center.add (AN4);
//Window
frame = new JFrame ("Examination registration System");
Makemenubar (frame);
Container ContentPane = Frame.getcontentpane ();
Specify the layout manager with nice spacing
Contentpane.setlayout (New BorderLayout (6, 6));
Contentpane.add (Xuanxiang, Borderlayout.north);
Contentpane.add (center, Borderlayout.center);
To display version versioning information in a label by creating a Label object
Statuslabel = new JLabel (VERSION);
Contentpane.add (Statuslabel, Borderlayout.south);
ImageIcon tp11 = new ImageIcon ("Picture/iconpng.png");
Frame.seticonimage (Tp11.getimage ());
Frame.pack ();
Display the window in the middle of the screen by calculation
Frame.setlocation (300,280);
Frame.setresizable (FALSE);
Frame.setsize (450, 400);
Frame.setvisible (TRUE);
Frame.setdefaultcloseoperation (Jframe.exit_on_close);
}
private void Makemenubar (final JFrame frame) {//Declaration constants for defining shortcut keys for menus
Final int shortcut_mask = Toolkit.getdefaulttoolkit ()
. Getmenushortcutkeymask ();//Get a mask for menu shortcuts
JMenuBar menubar = new JMenuBar ();
Frame.setjmenubar (menubar);
JMenu menu;
JMenuItem item;
Create the File menu
menu = new JMenu ("User login");
Menubar.add (menu);
item = new JMenuItem ("login | Register ...");
Item.setaccelerator (keystroke
. Getkeystroke (Keyevent.vk_o, shortcut_mask)); Add shortcut keys to the Open menu Ctrl+o
Menu.add (item);
Item.addactionlistener (new ActionListener () {
@Override
public void actionperformed (ActionEvent arg0) {
Final JDialog Dialog = new JDialog (frame, "login | register", TRUE);
MB1 = new JPanel ();
MB2 = new JPanel ();
MB3 = new JPanel ();
Bq1 = new JLabel ("User name");
BQ2 = new JLabel ("password");
Bq3 = new JLabel (" Bq3.setcursor (Cursor.getpredefinedcursor (cursor.hand_cursor));
An1 = new JButton ("login");
An2 = new JButton ("Cancel");
WBK = new JTextField (10);
MMK = new JPasswordField (10);
Dialog.setlayout (New GridLayout (3, 1));
An1 = new JButton ("OK");
An1.addactionlistener (New ActionListener () {
public void actionperformed (ActionEvent arg0) {
Dialog.dispose ();
}
});
An2 = new JButton ("Cancel");
An2.addactionlistener (New ActionListener () {
@Override
public void actionperformed (ActionEvent arg0) {
TODO auto-generated Method Stub
Dialog.dispose ();
}
});
Mb1.add (BQ1);
Mb1.add (WBK);
Mb2.add (BQ2);
Mb2.add (MMK);
Mb3.add (AN1);
Mb3.add (an2);
Mb3.add (BQ3);
Dialog.add (MB1);
Dialog.add (MB2);
Dialog.add (MB3);
Dialog.setbounds (600, 400, 200, 150);
Dialog.setresizable (FALSE);
Dialog.setvisible (TRUE);
Dialog.setresizable (FALSE);
}
});
Menu.addseparator ();
item = new JMenuItem ("Exit");
Item.setaccelerator (keystroke
. Getkeystroke (Keyevent.vk_q, shortcut_mask));
Item.addactionlistener (new ActionListener () {
@Override
public void actionperformed (ActionEvent arg0) {
TODO auto-generated Method Stub
System.exit (0);
}
});
Menu.add (item);
menu = new JMenu ("help");
Menubar.add (menu);
item = new JMenuItem ("About us ...");
Item.addactionlistener (new ActionListener () {
@Override
public void actionperformed (ActionEvent arg0) {
Joptionpane.showmessagedialog (NULL, "Current version is green Chinese version 3.2.0");
}
});
Menu.add (item);
}
public static void Main (string[] args) {
TODO auto-generated Method Stub
New Test ();
}
}
My picture.
Java Second Job