• JList 单击 ,双击例


    JList 单击 ,双击例

    import javax.swing.*;
    import javax.swing.event.ListSelectionEvent;
    import javax.swing.event.ListSelectionListener;
    
    import java.awt.event.*;
    import java.awt.*;
    public class Exec64 extends JFrame implements ListSelectionListener {
        JList list;
        JTextArea text;
        static String[] lessons={"语文","数学","化学","地理"};
        static String[] times={"04-09-12","05-09-12","03-10-12","14-10-12"};
        public Exec64() {
            this.setTitle("Exec64 Test");
            this.setSize(400,400);
            this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            this.setLocationRelativeTo(null);
            list = new JList(lessons);
            list.setVisibleRowCount(1);
            list.addListSelectionListener(this);
            list.addMouseListener(new doubleClick());
            text = new JTextArea(5,20);
            text.setBorder(BorderFactory.createEtchedBorder());
            
            add(list,BorderLayout.NORTH);
            add(text);
            
            
            this.setVisible(true);
            pack();
        }
        
        public static void main(String[] args) {
            javax.swing.SwingUtilities.invokeLater(new Runnable(){
                public void run(){
                    new Exec64();
                }
            });
    
        }
        @Override
        public void valueChanged(ListSelectionEvent e) {
            text.setText(((JList)e.getSource()).getSelectedValue().toString());
            
        }
        class doubleClick extends MouseAdapter {
            public void mouseClicked(MouseEvent e) {
                if(e.getClickCount() ==2) {
                    text.append("\n"+times[((JList)e.getSource()).getSelectedIndex()]);
                }
            }
        }
    
    }
  • 相关阅读:
    mysql-proxy使用中的问题
    iOS中利用CoreTelephony获取用户当前网络状态(判断2G,3G,4G)
    Django连接MySQL出错
    前后端分离
    django 安装指定版本
    问题
    算法面试
    记录docker for windows 时候的错误
    Django项目部署
    git 上传至github
  • 原文地址:https://www.cnblogs.com/qqjue/p/2627374.html
Copyright © 2020-2023  润新知