java之list的使用
frames.java
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87
| package smart.code.one;
import java.awt.*; import java.awt.event.*; import javax.swing.*; import com.borland.jbcl.layout.*;
@SuppressWarnings("serial") public class Frames extends JFrame { JPanel contentPane; XYLayout xYLayout1 = new XYLayout(); List list1 = new List(); Button button1 = new Button();
public Frames() { enableEvents(AWTEvent.WINDOW_EVENT_MASK); try { list1Init(); jbInit(); } catch(Exception e) { e.printStackTrace(); } } private void jbInit() throws Exception { 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)); } 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) { int i = list1.getSelectedIndex(); list1.remove(i);
} }
|
Listdelete.java
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
| package smart.code.one;
import javax.swing.UIManager;
import java.awt.*;
public class Listdelete { boolean packFrame = false;
public Listdelete() { Frames frame = new Frames(); if (packFrame) { frame.pack(); } else { frame.validate(); } 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); } 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