我想通过单击 Home J Frame 中的标签来停止重复 J 内部形式。我试图在加载表单后将“<<”添加到标签中。现在,当我尝试加载第二个 J 内部表单时,我遇到了空指针异常。这是我加载 J 内部表单的方法:
public void lordForm(JInternalFrame frame) {
jDesktopPane1.add(frame);
frame.setVisible(true);
}
public void load(String ss, JInternalFrame in, JLabel jl) {
JInternalFrame[] j = jDesktopPane1.getAllFrames();
boolean b = false;
for (JInternalFrame jI : j) {
if (jI.getName().equals(ss)) {
b = true;
break;
}
}
if (!b) {
LF(in);
jl.setText(ss + " >>");
jl.setEnabled(false);
} else {
in.moveToFront();
}
}
我正在使用moveToFront()方法移动选定的 J 内部表单。
这些是标记鼠标释放事件的绳索:
private void lblinvoiceMouseReleased(java.awt.event.MouseEvent evt) <br/> {
load("Invoice", new Invoice(), lblinvoice);
}
private void lblReservationMouseReleased(java.awt.event.MouseEvent evt){
load("Reservation", new Reservation(), lblReservation);
}
堆栈跟踪如下。
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException at
viewer.MainFrame.load(MainFrame.java:39) at
viewer.MainFrame.lblinvoiceMouseReleased(MainFrame.java:186) at
viewer.MainFrame.access$000(MainFrame.java:18) at
viewer.MainFrame$1.mouseReleased(MainFrame.java:82)
并且viewer.MainFrame.load(MainFrame.java:39)
是if (jI.getName().equals(ss)) {
_ viewer.MainFrame.lblinvoiceMouseReleased(MainFrame.java:186)
_load("Invoice", new Invoice(), lblinvoice);