java之list的移除

okgoes 2023-05-09 13:07:14
Categories: Tags:

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.*;

/**
 * <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(400300));
    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(4624138161));
    contentPane.add(button1,  new XYConstraints(2154511540));
}
  //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

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.*;

/**
 * <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