码迷,mamicode.com
首页 > 其他好文 > 详细

GUI

时间:2016-03-19 21:21:56      阅读:167      评论:0      收藏:0      [点我收藏+]

标签:

技术分享  1 package lyj;
  2 
  3 import java.awt.event.ActionEvent;
  4 import java.awt.event.ActionListener;
  5 
  6 import javax.swing.ButtonGroup;
  7 import javax.swing.JButton;
  8 import javax.swing.JDialog;
  9 import javax.swing.JFrame;
 10 import javax.swing.JLabel;
 11 import javax.swing.JMenu;
 12 import javax.swing.JMenuBar;
 13 import javax.swing.JMenuItem;
 14 import javax.swing.JOptionPane;
 15 import javax.swing.JRadioButton;
 16 import javax.swing.JTextField;
 17 import javax.swing.SwingConstants;
 18 
 19 public class GUI {
 20 
 21     public static void main(String[] args) {
 22         // TODO Auto-generated method stub
 23         //界面
 24         JFrame frm=new JFrame("测试");
 25         frm.setLayout(null);
 26         frm.setBounds(400, 200, 300, 250);
 27         frm.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
 28         
 29         
 30         JMenuBar mbar=new JMenuBar();
 31         frm.setJMenuBar(mbar);
 32         JMenu m=new JMenu("功能模块");
 33         mbar.add(m);
 34         JMenuItem mi11=new JMenuItem("结果");
 35         JMenuItem mi12=new JMenuItem("欢迎使用本软件");
 36         JMenuItem mi13=new JMenuItem("关闭");
 37         m.add(mi11);
 38         m.add(mi13);
 39         m.add(mi12);
 40         mi13.addActionListener(new ActionListener() {
 41             
 42             @Override
 43             public void actionPerformed(ActionEvent e) {
 44                 // TODO Auto-generated method stub
 45                 System.exit(0);
 46             }
 47         });
 48         
 49         
 50         //功能
 51         JLabel userLabel=new JLabel();
 52         userLabel.setText("姓名:");
 53         userLabel.setBounds(40, 20, 80,30);
 54         JTextField userText=new JTextField();
 55         userText.setEditable(true);
 56         userText.setHorizontalAlignment(SwingConstants.LEFT);
 57         userText.setColumns(20);
 58         userText.setBounds(100, 20, 120, 30);
 59         
 60         JLabel sLabel=new JLabel();
 61         sLabel.setText("性别:");
 62         sLabel.setBounds(40, 60, 80,30);
 63         ButtonGroup btnGroup=new ButtonGroup();
 64         JRadioButton manRadioButton=new JRadioButton("男人");
 65         manRadioButton.setBounds(100,60,80,25);
 66         manRadioButton.setSelected(true);
 67         JRadioButton womanRadioButton=new JRadioButton("女人");
 68         womanRadioButton.setBounds(200,60,80,25);
 69         btnGroup.add(manRadioButton);
 70         btnGroup.add(womanRadioButton);
 71         frm.add(manRadioButton);
 72         frm.add(womanRadioButton);
 73         
 74         mi11.addActionListener(new ActionListener() {
 75             
 76             @Override
 77             public void actionPerformed(ActionEvent e) {
 78                 // TODO Auto-generated method stub
 79                 JOptionPane.showMessageDialog(frm,"结果:"+userText.getText()+"是男人");
 80             }
 81         });
 82         
 83         JButton btn=new JButton("结果");
 84         btn.setBounds(100,125,80,30);
 85         btn.addActionListener(new ActionListener() {
 86         
 87             @Override
 88             public void actionPerformed(ActionEvent e) {
 89                 // TODO Auto-generated method stub
 90                 
 91                 JOptionPane.showMessageDialog(frm,"结果:"+userText.getText()+"是男人");
 92             }
 93         });
 94         
 95         frm.add(userLabel);
 96         frm.add(btn);
 97         frm.add(userText);
 98         frm.add(sLabel);
 99         frm.setVisible(true);
100     }
101 
102 }

 

GUI

标签:

原文地址:http://www.cnblogs.com/mune/p/5296126.html

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