/*
* 选课,自己玩,鲍志强的选课系统,哈哈哈哈~
* 日期:2010年4月27日
*/
package 事件和checkbox练习册;
imp
ort java.awt.*;
imp
ort javax.swing.*;
imp
ort java.awt.event.*;
public class Test1 extends JFrame implements ActionListener{
JCheckBox jcb1,jcb2,jcb3;
JButton jb=null;
JLabel jl=null;
JTextField jtxt=null;
JPanel jp1=null;
JPanel jp2=null;
public void settext(String str)
{
this.jtxt.setText(str);
}
public static void main(String[] args) {
// TODO Auto-generated method stub
Test1 t=new Test1();
}
public Test1()
{
this.setLayout(new GridLayout(3,1));
jp1=new JPanel();
jcb1=new JCheckBox("语文",false);
jcb2=new JCheckBox("数学",false);
jcb3=new JCheckBox("英语",false);
jp1.add(jcb1);
jp1.add(jcb2);
jp1.add(jcb3);
JPanel jp3=new JPanel();
jb=new JButton("提交");
jb.setSize(20, 10);
jp3.add(jb);
jl=new JLabel("您的选课为:");
jtxt=new JTextField(10);
jp2=new JPanel();
jp2.add(jl);
jp2.add(jtxt);
jb.addActionListener(this);
jb.setActionCommand("提交");
this.add(jp1);
this.add(jp3);
this.add(jp2);
this.setTitle("欢迎进入鲍志强的选课系统");
this.setSize(300,200);
this.setLocation(300,200);
this.setVisible(true);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
public Test1(String string) {
// TODO Auto-generated constructor stub
}
@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
if(e.getActionCommand().equals("提交"))
{
String str="";
if(jcb1.isSelected())
str+=jcb1.getText();
if(jcb2.isSelected())
str+=","+jcb2.getText();
if(jcb3.isSelected())
str+=","+jcb3.getText();
this.jtxt.setText(str);
}
}
}