Java components and event processing (2)-components

Java components and event handling (2) Components in the window


import java.awt.Color;
import java.awt.Container;
import java.awt.FlowLayout;
import javax.swing.ButtonGroup;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPasswordField;
import javax.swing.JRadioButton;
import javax.swing.JTextArea;
import javax.swing.JTextField;

public class Two extends JFrame
{
    
    
	JTextField jtf;//文本框
	JLabel jl;//标签
	JButton jb;//按钮
	JTextArea jta;//文本区
	
	JComboBox jcb;//下拉列表
	
	JRadioButton jrb1;//单选框
	JRadioButton jrb2;
	
	JCheckBox jcb1;//复选框
	JCheckBox jcb2;
	
	JPasswordField jpf;//密码框
	
	public Two(String s)
	{
    
    
		super(s);
		setLayout(new FlowLayout());
		
		setBounds(400, 400, 400, 400);
		
		Container con = getContentPane();
		con.setBackground(Color.cyan);
		
		jtf = new JTextField(10);
		jl = new JLabel("请输入");
		jb = new JButton("点击");
		jta = new JTextArea(5,10);
		jcb = new JComboBox();
		jcb.addItem("沈阳");
		jcb.addItem("大连");
		
		ButtonGroup bg = new ButtonGroup();
		jrb1 = new JRadioButton("男");
		jrb2 = new JRadioButton("女");
		bg.add(jrb1);
		bg.add(jrb2);
		
		
		jcb1 = new JCheckBox("数学");
		jcb2 = new JCheckBox("语文");
		
		jpf = new JPasswordField(10);
		
		add(jtf);
		add(jl);
		add(jb);
		add(jta);
		add(jcb);
		add(jrb1);
		add(jrb2);
		add(jcb1);
		add(jcb2);
		add(jpf);
		
		setVisible(true);
		
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		
	}
}
class Test
{
    
    
	public static void main(String[] args) 
	{
    
    
		Two a = new Two("二");
		
	}
}

Insert picture description here
Summary:
1. First add on the basis of the
window (see the previous article for details on the window)
2. Components include: text box, label, button, text area, drop-down list, radio box, check box, password box

Guess you like

Origin blog.csdn.net/m0_47385081/article/details/114241561