java之list的使用
frames.java
package smart.code.one; import java.awt.*; import java.awt.event.*; import javax.swing.*; import com.borland.jbcl.layout.*; /** * <p>Title: </p> * <p>Description: </p> * <p>Copyright: Copyright (c) 2002</p> * <p>Company: </p> * @author smart * @version 1.0 */ @SuppressWarnings("serial") public class Frames extends JFrame { JPanel contentPane; XYLayout xYLayout1 = new XYLayout(); List list1 = new List(); Button button1 = new Button(); //Construct the frame public Frames() { enableEvents(AWTEvent.WINDOW_EVENT_MASK); try { list1Init(); 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(xYLayout1); this.setSize(new Dimension(400, 300)); this.setTitle("Frame Title"); button1.setLabel("Delete"); button1.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(ActionEvent e) { button1_actionPerformed(e); } }); contentPane.add(list1, new XYConstraints(46, 24, 138, 161)); contentPane.add(button1, new XYConstraints(215, 45, 115, 40)); } //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); } } public void list1Init() throws Exception { list1.add("Java thinking"); list1.add("VC++ thinking"); list1.add("C++ thinking"); list1.add("计算机英语"); list1.add(" C language"); list1.add("操作系统"); list1.add("汇编语言"); list1.add("编译原理"); list1.add("数字逻辑"); list1.add("MFC编程"); list1.add("系统结构"); list1.add("数值分析"); list1.add("大学英语"); list1.add("大学德育"); list1.add("思想教育"); list1.add("财政学"); } void button1_actionPerformed(ActionEvent e) { //String s = list1.getSelectedItem(); int i = list1.getSelectedIndex(); list1.remove(i); } }
Listdelete.java
package smart.code.one; import javax.swing.UIManager; import java.awt.*; /** * <p>Title: </p> * <p>Description: </p> * <p>Copyright: Copyright (c) 2017</p> * <p>Company: </p> * @author smart * @version 1.0 */ public class Listdelete { boolean packFrame = false; //Construct the application public Listdelete() { Frames frame = new Frames(); //Validate frames that have preset sizes //Pack frames that have useful preferred size info, e.g. from their layout if (packFrame) { frame.pack(); } else { frame.validate(); } //Center the window Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); Dimension frameSize = frame.getSize(); if (frameSize.height > screenSize.height) { frameSize.height = screenSize.height; } if (frameSize.width > screenSize.width) { frameSize.width = screenSize.width; } frame.setLocation((screenSize.width - frameSize.width) / 2, (screenSize.height - frameSize.height) / 2); frame.setVisible(true); } //Main method public static void main(String[] args) { try { UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); } catch(Exception e) { e.printStackTrace(); } new Listdelete(); } }
jbcl的使用可以参考:http://blog.okgoes.com/index/index/detail?id=9&type=blog&k=MkTxKNjspe&t=1496288987