目录
容器:JFrame
组件:
JPanel:面板
JButton:按钮
JLabel:标签
JTextArea:文本域
JTextField:文本框
JPasswordField:密码框
JCheckBox:复选框
JRadioButton:单选框(需要放入按钮组(ButtonGroup)使用)
ButtonGroup:把单选按钮放进一个组里
public class DialogDemo01 extends JDialog{
public DialogDemo01(JFrame jframe) {
super(jframe,true);
this.setBounds(100,100,500,300,500);
Container container1= this.getContentPane();
container1.setLayout(null);
//container.add(new Label("五班"));
JButton button1=new JButton("五班");
button1.setBounds(30,30,200,50);
container1.add(button1);
}
public static void main(String[] args) {
JFrame j=new JFrame();
j.setVisible(true);
j.setBounds(100,100,700,500);
j.setDefaultCloseOperation(EXIT_ON_CLOSE);
Container container= j.getContentPane();
container.setLayout(null);
JButton button=new JButton("我要登录");
button.setBounds(30,30,200,50);
button.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
DialogDemo01 s=new DialogDemo01(j);
s.setVisible(true);
System.out.println("被点击了");
}
});
}
}
package demo02;
public class JScrollDemo extends JFrame{
public JScrollDemo() {
Container container1= this.getContentPane();
//文本域
JTextArea textarea= new JTextArea(20,50);
textarea.setText("五班");
//scroll面板
JScrollPane scrollpane=new JScrollPane(textarea);
container1.add(scrollpane);
this.setDefaultCloseOperation(EXIT_ON_CLOSE);
this.setVisible(true);
this.setBounds(100,100,500,300,500);
}
public static void main(String[] args) {
new JScrollDemo();
}
}
package demo03;
public class TestBorderLayout2 {
public static void main(String[] args) {
JFrame j=new JFrame();
j.setVisible(true);
j.setBounds(100,100,700,300,500);
j.setDefaultCloseOperation(WindowConstants.HIDE_ON_CLOSE);
JButton east=new JButton("east");
JButton west=new JButton("west");
JButton south=new JButton("south");
JButton north=new JButton("north");
JButton center=new JButton("center");
j.add(east,BorderLayout.EAST);
j.add(west,BorderLayout.WEST);
j.add(south,BorderLayout.SOUTH);
j.add(north,BorderLayout.NORTH);
j.add(center,BorderLayout.CENTER);
}
}
package demo04
public class CheckBox extends JFrame{
public CheckBox() {
Container container1= this.getContentPane();
//单选框
JCheckBox checkbox1=new JCheckBox("checkbox1");
JCheckBox checkbox2=new JCheckBox("checkbox2");
JCheckBox checkbox3=new JCheckBox("checkbox3");
container1.add(checkbox1,BorderLayout.CENTER);
container1.add(checkbox2,BorderLayout.EAST);
container1.add(checkbox3,BorderLayout.SOUTH);
this.setDefaultCloseOperation(EXIT_ON_CLOSE);
this.setVisible(true);
this.setBounds(100,100,500,300,500);
}
public static void main(String[] args) {
new CheckBox();
}
}