⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 multilistener.java~22~

📁 提供了常用的JAVA技术的示例
💻 JAVA~22~
字号:
package MultiListener;import java.awt.*;import java.awt.event.*;import java.util.*;public class MultiListener implements ActionListener,ItemListener,WindowListener{    private Frame f;    private java.awt.List lst;    private TextField tf;    static Random num=new Random(1000);    public void create() {        f = new Frame("testing the listing");        tf=new TextField();        lst=new java.awt.List(4,false);        lst.add("1");        lst.add("2");        lst.add("3");        lst.add("4");        lst.addItemListener(this);        lst.addActionListener(this);        f.setSize(300,300);        f.add(lst,"Center");        f.add(tf,"South");        f.addWindowListener(this);        f.setVisible(true);    }    public void itemStateChanged(ItemEvent e){        int id=((java.awt.List)e.getSource()).getSelectedIndex();        switch(id){            case 0:{tf.setText("id-1 is :"+num.nextInt());                    tf.setBackground(new Color(225,230,0));                    break;                    }            case 1:{tf.setText("id-2 is :"+num.nextInt());                    tf.setBackground(new Color(225,100,0));                    break;                    }            case 2:{tf.setText("id-3 is :"+num.nextInt());                    tf.setBackground(new Color(100,100,100));                    break;                    }            case 3:{tf.setText("id-4 is :"+num.nextInt());                    break;                    }        }    }   public void actionPerformed(ActionEvent e){      /*  tf.setForeground(Color.blue);        tf.setBackground(new Color(225,230,0));        lst.setBackground(new Color(225,230,0));        lst.setForeground(new Color(0,0,255));*/    }    public void windowClosing(WindowEvent e){System.exit(1);}    public void windowActivated(WindowEvent e){}    public void windowClosed(WindowEvent e){}    public void windowDeactivated(WindowEvent e){}    public void windowDeiconified(WindowEvent e){}    public void windowIconified(WindowEvent e){}    public void windowOpened(WindowEvent e){}    public static void main(String[] args) {      MultiListener mul = new MultiListener();      mul.create();    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -