| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 529 人关注过本帖
标题:关于jList的一个问题,怎么把按钮的监听添加进去啊
只看楼主 加入收藏
holyhsw
Rank: 1
等 级:新手上路
帖 子:20
专家分:0
注 册:2011-6-12
结帖率:40%
收藏
 问题点数:0 回复次数:0 
关于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();
    }
}
搜索更多相关主题的帖子: values public Object 
2011-11-11 23:31
快速回复:关于jList的一个问题,怎么把按钮的监听添加进去啊
数据加载中...
 
   



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

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