关于jList的一个问题,怎么把按钮的监听添加进去啊
public class JListDemo extends JFrame{JButton btnLeft = new JButton(">>");
JButton btnRight = new JButton("<<");
Object[] values = {"a","b","c"};
JList listLeft = new JList(values);
JList listRight = new JList();
public JListDemo(){
this.setTitle("JListDemo");
listLeft.setSize(100,200);
listLeft.setLocation(50, 50);
listRight.setBounds(300, 50, 100, 200);
btnLeft.setSize(60, 25);
btnRight.setSize(60,25);
btnLeft.setLocation(190, 100);
btnRight.setLocation(190,150);
this.getContentPane().setLayout(null);
this.getContentPane().setBackground(Color.green);
this.getContentPane().add(listLeft);
this.getContentPane().add(listRight);
this.getContentPane().add(btnLeft);
this.getContentPane().add(btnRight);
this.setSize(500,400);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setVisible(true);
btnLeft.addActionListener((ActionListener) this);
btnRight.addActionListener((ActionListener) this);
}
public void actionPerformed(ActiveEvent e){
int count;
String itemStr;
Vector vector1=new Vector();
if(((EventObject) e).getSource()==btnLeft){
count=listLeft.getModel().getSize();
for(int i=0;i<count;i++){
itemStr=(String) listLeft.getModel().getElementAt(i);
vector1.add(itemStr);
}
btnRight.add(vector1);
}
}
public class MyMouseListener implements MouseListener{
@Override
public void mouseClicked(MouseEvent e) {
int count;
String itemStr;
Vector vector1=new Vector();
if(e.getSource()==btnLeft){
count=listLeft.getModel().getSize();
for(int i=0;i<count;i++){
itemStr=(String) listLeft.getModel().getElementAt(i);
vector1.add(itemStr);
}
//btnRight.setListData(vector1);
}
}
@Override
public void mouseEntered(MouseEvent e) {
// TODO Auto-generated method stub
}
@Override
public void mouseExited(MouseEvent e) {
// TODO Auto-generated method stub
}
@Override
public void mousePressed(MouseEvent e) {
// TODO Auto-generated method stub
}
@Override
public void mouseReleased(MouseEvent e) {
// TODO Auto-generated method stub
}
}
public static void main(String[] args) {
new JListDemo();
}
}
----------------解决方案--------------------------------------------------------