码迷,mamicode.com
首页 > Windows程序 > 详细

实验十二:SWING界面设计

时间:2019-06-17 01:01:36      阅读:130      评论:0      收藏:0      [点我收藏+]

标签:ext   ble   界面设计   editable   单选框   listen   sel   专业   网络   

一、源代码

package ziwojieshao;
import java.awt.FlowLayout;
import javax.swing.*;
import java.awt.Container;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class AA extends JFrame{
public AA()
{
JFrame jf1=new JFrame ("Hellow");
jf1.setLayout(new FlowLayout());
jf1.getContentPane().add(new JButton("姓名")) ;
jf1.getContentPane().add(new JTextField("牛明旺",10)) ;

JRadioButton j1=new JRadioButton("男",true);
JRadioButton j2=new JRadioButton("女");
ButtonGroup g=new ButtonGroup();
g.add(j1);
g.add(j2);
JPanel p1=new JPanel();
p1.add(j1);
p1.add(j2);
jf1.getContentPane().add(p1);
jf1.setSize(320,210);

String proList[] = { "年龄","民族" ,"籍贯","学号","学院","专业"};
JComboBox comboBox;
Container conPane = getContentPane();
comboBox = new JComboBox(proList);
comboBox.setEditable(true);
conPane.add(comboBox);
JTextField b=new JTextField(20);
jf1.add(conPane);
jf1.add(b);
comboBox.addActionListener(new ActionListener()
{public void actionPerformed(ActionEvent e)
{
if(comboBox.getSelectedItem().equals("年龄"))
b.setText("20");
else if(comboBox.getSelectedItem().equals("民族"))
b.setText("汉");
else if(comboBox.getSelectedItem().equals("籍贯"))
b.setText("河北 邯郸");
else if(comboBox.getSelectedItem().equals("学号"))
b.setText("20173311133");
else if(comboBox.getSelectedItem().equals("学院"))
b.setText("计算机学院");
else if(comboBox.getSelectedItem().equals("专业"))
b.setText("网络工程");
}
});


jf1.setVisible(true);
}
public static void main (String[] args) {
new AA()
; }

 


}

二、结果

技术图片

技术图片

三、心得体会

1、单选框

JRadioButton j1=new JRadioButton("男"); JRadioButton j2=new JRadioButton("女");

2、有些函数要放到主函数外才对

3、 JFrame和JDialog类拥有一个setDefaultCloseOperation()方法,可用于窗口/对话框关闭处理。

 

实验十二:SWING界面设计

标签:ext   ble   界面设计   editable   单选框   listen   sel   专业   网络   

原文地址:https://www.cnblogs.com/nmw111/p/11037485.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!