| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 408 人关注过本帖
标题:关于界面的问题 怎么把选择的上海长沙也像男女一样输出来啊
只看楼主 加入收藏
holyhsw
Rank: 1
等 级:新手上路
帖 子:20
专家分:0
注 册:2011-6-12
结帖率:40%
收藏
 问题点数:0 回复次数:0 
关于界面的问题 怎么把选择的上海长沙也像男女一样输出来啊
package newer.javax;

import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;
import java.util.Vector;

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.JPanel;
import javax.swing.JRadioButton;

import newer.javax.Demo4.MyActionListener;

public class Frame extends JFrame{
    JLabel jLabel1=new JLabel("户籍");
    JComboBox jComboBox1=new JComboBox();
//    JRadioButton jRadioButton1=new JRadioButton("男",true);
//    JRadioButton jRadioButton2=new JRadioButton();
    ButtonGroup buttonGroup1=new ButtonGroup();
    ArrayList<JCheckBox> checkBoxs = new ArrayList<JCheckBox>();
    JComboBox list1= null;
    public Frame(){
        super("表单组件示例");
        JLabel lbl1 = new JLabel();//创建文本标签lbl1
        lbl1.setText("用户基本信息 ");
        this.getContentPane().add(lbl1);
        setSize(300,300);
        setDefaultCloseOperation(EXIT_ON_CLOSE);
        this.getContentPane().setLayout(new FlowLayout());
        this.getContentPane().add(jLabel1);
        jComboBox1.addItem("长沙");
        jComboBox1.addItem("上海");
        list1 = new JComboBox();
        this.getContentPane().add(jComboBox1);
        this.getContentPane().add(list1);

        
        //复选框示例
        JCheckBox jCeckBox1=new JCheckBox("C");
        JCheckBox jCeckBox2=new JCheckBox("SQL");
        JCheckBox jCeckBox3=new JCheckBox("HTML");
        JCheckBox jCeckBox4=new JCheckBox("JAVA");
        checkBoxs.add(jCeckBox1);
        checkBoxs.add(jCeckBox2);
        checkBoxs.add(jCeckBox3);
        checkBoxs.add(jCeckBox4);
        this.getContentPane().add(jCeckBox1);
        this.getContentPane().add(jCeckBox2);
        this.getContentPane().add(jCeckBox3);
        this.getContentPane().add(jCeckBox4);
        
        //单选按钮示例
//        jRadioButton2.setText("女");
//        this.getContentPane().setLayout(new FlowLayout());
//        this.getContentPane().add(jRadioButton1);
//        this.getContentPane().add(jRadioButton2);
//        buttonGroup1.add(jRadioButton1);
//        buttonGroup1.add(jRadioButton2);
        JCheckBox box1 = new JCheckBox("男");
        box1.setSize(40,20);
        box1.setLocation(20,20);
        JCheckBox box2 = new JCheckBox("女");
        box2.setSize(40,20);
        box2.setLocation(20,60);

        checkBoxs.add(box1);
        checkBoxs.add(box2);
        this.getContentPane().add(box1);
        this.getContentPane().add(box2);
        buttonGroup1.add(box1);
        buttonGroup1.add(box2);
        
        JButton btn1 = new JButton();//创建按钮对象
        btn1.setText("确定");
        this.getContentPane().add(btn1);
        btn1.addActionListener(new MyActionListener());
        
        this.setVisible(true);
    }
    class MyActionListener implements ActionListener{

        public void actionPerformed(ActionEvent arg0) {
            // TODO Auto-generated method stub
            for(int i=0;i<checkBoxs.size();i++){
                JCheckBox checkBox = checkBoxs.get(i);
                if(checkBox.isSelected()){
                    System.out.println("你选择了:"+checkBox.getText());
                }
            }
            
        }//System.out.print(list1.getSelectedItem());
        
        }
    public static void main(String [] args){
        Frame showJComboBox1=new Frame();
    }   
    }

搜索更多相关主题的帖子: 男女 上海 package public import 
2011-11-05 23:46
快速回复:关于界面的问题 怎么把选择的上海长沙也像男女一样输出来啊
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.040496 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved