import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Vector;
import javax.swing.ButtonGroup;
import javax.swing.ButtonModel;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JFrame;
import javax.swing.JList;
import javax.swing.JRadioButton;
public class JFrameDemo
{
public static void main(String[] args)
{
FrameDemo frame = new FrameDemo();
}
}
class FrameDemo extends JFrame implements ActionListener
{
private JButton button1;
private JRadioButton select1;
private JRadioButton select2;
private ButtonGroup group;
private JList list;
private JCheckBox _checkBox1;
private JCheckBox _checkBox2;
private JCheckBox _checkBox3;
public FrameDemo()
{
this.setBounds(200, 200, 300, 400);
this.setVisible(true);
this.setLayout(new FlowLayout(FlowLayout.CENTER,5,5));
select1 = new JRadioButton("java");
select2 = new JRadioButton("php");
group = new ButtonGroup();
group.add(select1);
group.add(select2);
this.add(select1);
this.add(select2);
_checkBox1 = new JCheckBox("Java");
_checkBox2 = new JCheckBox("PHP",true);
_checkBox3 = new JCheckBox("C++");
this.add(_checkBox1);
this.add(_checkBox2);
this.add(_checkBox3);
button1 = new JButton("确定");
this.add(button1);
list = new JList(new String[]{"11","22"});
list.setBounds(0, 30, 100, 100);
this.add(list);
initialize();
}
public void initialize(){
button1.addActionListener(this);
}
@Override
public void actionPerformed(ActionEvent e)
{
// TODO Auto-generated method stub
list.removeAll();
Vector
if(_checkBox1.isSelected()){
vector.add("Java");
}
if(_checkBox2.isSelected()){
vector.add("PHP");
}
if(_checkBox3.isSelected()){
vector.add("C++");
}
if(select1.isSelected()){
vector.add("java");
}
if(select2.isSelected()){
vector.add("php");
}
list.setListData(vector);
repaint();
}
}
请采纳写得好累
其实就是getText()和setText()的问题吧...
你button单击事件里面定义一个string a=xx.getText();
然后jlist那个控件setText(a)不就是了...
这么基础的问题
ActionListiner 认真看一下