?? frame1.java
字號:
package ex10_02;import java.awt.*;import java.awt.event.*;import javax.swing.*;import java.util.*;public class Frame1 extends JFrame { JPanel contentPane; JScrollPane jScrollPane1 = new JScrollPane(); JList jList1 = new JList(); /**Construct the frame*/ public Frame1() { enableEvents(AWTEvent.WINDOW_EVENT_MASK); try { jbInit(); } catch(Exception e) { e.printStackTrace(); } } /**Component initialization*/ private void jbInit() throws Exception { //setIconImage(Toolkit.getDefaultToolkit().createImage(Frame1.class.getResource("[Your Icon]"))); contentPane = (JPanel) this.getContentPane(); contentPane.setLayout(null); this.setSize(new Dimension(400, 300)); this.setTitle("Frame Title"); this.addWindowListener(new java.awt.event.WindowAdapter() { public void windowOpened(WindowEvent e) { this_windowOpened(e); } }); jScrollPane1.setBounds(new Rectangle(11, 9, 131, 96)); jList1.addMouseListener(new java.awt.event.MouseAdapter() { public void mouseClicked(MouseEvent e) { jList1_mouseClicked(e); } }); contentPane.add(jScrollPane1, null); jScrollPane1.getViewport().add(jList1, null); } /**Overridden so we can exit when window is closed*/ protected void processWindowEvent(WindowEvent e) { super.processWindowEvent(e); if (e.getID() == WindowEvent.WINDOW_CLOSING) { System.exit(0); } } void this_windowOpened(WindowEvent e) {//建立向量對象Vector myvector = new Vector();//添加向量對象的元素myvector.addElement("香蕉");myvector.addElement("芭蕉");myvector.addElement("鳳梨");myvector.addElement("蘋果");myvector.addElement("葡萄");//將向量對象內的元素加入jList組件中成為待選項目jList1.setListData(myvector); } void jList1_mouseClicked(MouseEvent e) { }}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -