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

📄 showlist.java

📁 源码为科学出版社出版的英文<java设计模式>(影印版)所用的所有例子程序
💻 JAVA
字号:
import java.awt.*;
import javax.swing.*;
import java.util.*;
import java.awt.event.*;


/** Simple sorted array used as data for JList*/
public class ShowList extends JxFrame {
    String names[];

    public ShowList() {
        super("List of names");
        JPanel jp = new JPanel();
        getContentPane().add(jp);
        jp.setLayout(new BorderLayout());
        
        //create the array
        names = new String[5];
        int i = 0;
        names[i++] = ("Dave");
        names[i++] = ("Charlie");
        names[i++] = ("Adam");
        names[i++] = ("Edward");
        names[i++] = ("Barry");
        
        //sort the array
        Arrays.sort (names);

        //create the list and add it
        JList nList = new JList(names);
        JScrollPane sc = new JScrollPane();
        sc.getViewport().add (nList);
        jp.add ("Center", sc);
        
        setSize(new Dimension(150, 150));
        setVisible(true);        
    }
    static public void main(String argv[]) {
        new ShowList();
    }
}

⌨️ 快捷键说明

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