我创建了一个包含一个按钮的“frame1”,所以如果我点击那个按钮,按钮操作执行的方法将检查 LinkedList 是否为空,如果是,它将设置包含 radioButton 调用 addEmployees_Auto 的“addEmployee”框架可见,并且单击时,它将从 frame1 调用方法“add_Auto”。这应该填充frame1中的linkedList,但如果我再次单击按钮,LinkedList又是空的。为什么?LinkedList 不应该被填充吗?
这是“frame1”
public class Frame1 extends javax.swing.JFrame {
LinkedList <Employee>list2=new LinkedList <Employee>();
....
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
System.out.println("size="+list2.size());
if(list2.isEmpty())
new AddEmployees.setVisible(true);
}
public void addEmployees_Auto()
{
list2.add(new Employee(20910733,"Ahmed","Manager",2700));
list2.add(new Employee(20910835,"Omar","Teaacher",2100));
list2.add(new Employee(20910674,"Mohammed","Manager",3000));
list2.add(new Employee(20910955,"Kareem","",2700));
list2.add(new Employee(20910921,"Ameer","teacher",2500));
}
}
添加员工框架:
public class AddEmployees extends javax.swing.JFrame {
...
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt)
{
if(jRadioButton2.isSelected()){
new Frame1().addEmployees_Auto();
this.setVisible(false);
}
}