JAVA编写一个窗口(frame),要求窗口中有文本框,按钮,标签,单选框,复选框,

2020-05-29 科技 68阅读
import javax.swing.*;
import java.awt.*;
public class test extends JFrame{
public test(){
JButton button; //按钮
JLabel label; //标签
JComboBox combobox;//下拉菜单
JCheckBox checkbox;//复选框
JRadioButton radiobutton;//单选框
JTextField textfield;//文本框

button = new JButton("按钮");
label = new JLabel("标签:");
checkbox = new JCheckBox("复选框一");
radiobutton = new JRadioButton("单选框一");
combobox = new JComboBox();
textfield = new JTextField(100);

Container c = this.getContentPane();
c.setLayout(new FlowLayout());
c.add(button);
c.add(label);
c.add(checkbox);
c.add(radiobutton);

combobox.addItem("1");
combobox.addItem("2");
c.add(combobox);

c.add(textfield);

setSize(300, 200);
setVisible(true);
}
public static void main(String[] args) {
// TODO 自动生成方法存根
test mytest = new test();
}
}
声明:你问我答网所有作品(图文、音视频)均由用户自行上传分享,仅供网友学习交流。若您的权利被侵害,请联系fangmu6661024@163.com