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

📄 simplelist.java

📁 java swing 开发代码
💻 JAVA
字号:
//  SimpleList.java// A simple example of a JList object built from an array of Strings.//package	jswing.ch07;import java.awt.*;import java.awt.event.*;import javax.swing.*;public class SimpleList extends JPanel {    String label[] = { "Zero","One","Two","Three","Four","Five","Six",                       "Seven","Eight","Nine","Ten","Eleven" };    JList list;    public SimpleList() {        this.setLayout(new BorderLayout());        list = new JList(label);        JScrollPane pane = new JScrollPane(list);        JButton button = new JButton("Print");        button.addActionListener(new PrintListener());        add(pane, BorderLayout.CENTER);        add(button, BorderLayout.SOUTH);    }    public static void main(String s[]) {         JFrame frame = new JFrame("Simple List Example");         frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);         frame.setContentPane(new SimpleList());         frame.setSize(250, 200);         frame.setVisible(true);    }    // An inner class to respond to clicks on the Print button    class PrintListener implements ActionListener {        public void actionPerformed(ActionEvent e) {            int selected[] = list.getSelectedIndices();            System.out.println("Selected Elements:  ");            for (int i=0; i < selected.length; i++) {                String element =                      (String)list.getModel().getElementAt(selected[i]);                System.out.println("  " + element);            }        }    }}

⌨️ 快捷键说明

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