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

📄 listtest.java

📁 corejava的源程序内有好多的源代码
💻 JAVA
字号:
/**   @version 1.21 2001-07-17   @author Cay Horstmann*/import java.awt.*;import java.awt.event.*;import javax.swing.*;import javax.swing.event.*;/**   This program demonstrates a simple fixed list of strings.*/public class ListTest{     public static void main(String[] args)   {        JFrame frame = new ListFrame();      frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);      frame.show();   }}/**   This frame contains a word list and a label that shows a    sentence made up from the chosen words. Note that you can    select multiple words with Ctrl+click and Shift+click.*/class ListFrame extends JFrame{     public ListFrame()   {        setTitle("ListTest");      setSize(WIDTH, HEIGHT);      String[] words =      {           "quick","brown","hungry","wild","silent",         "huge","private","abstract","static","final"      };      wordList = new JList(words);      JScrollPane scrollPane = new JScrollPane(wordList);      JPanel p = new JPanel();      p.add(scrollPane);      wordList.addListSelectionListener(new         ListSelectionListener()         {            public void valueChanged(ListSelectionEvent event)            {                 Object[] values = wordList.getSelectedValues();               StringBuffer text = new StringBuffer(prefix);               for (int i = 0; i < values.length; i++)               {                    String word = (String)values[i];                  text.append(word);                  text.append(" ");               }               text.append(suffix);               label.setText(text.toString());            }         });      Container contentPane = getContentPane();      contentPane.add(p, BorderLayout.SOUTH);      label = new JLabel(prefix + suffix);      contentPane.add(label, BorderLayout.CENTER);   }   private static final int WIDTH = 400;   private static final int HEIGHT = 300;   private JList wordList;   private JLabel label;   private String prefix = "The ";   private String suffix = "fox jumps over the lazy dog.";}

⌨️ 快捷键说明

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