我正在用 JAVA 中的 Netbeans 制作 GUI。我的想法是这样的:
JFrame -> contains a JPanel -> call a JDialog.
-> call a second JDialog
这个想法是我想在第一个 JDialog 中阅读一些内容,当用户完成这个 JDialog 时,他按下一个按钮。这个 JDialog dispose() 和 JPanel 调用另一个 JDialog。
我的想法类似于 Netbeans 中的项目向导或类似的东西。
问题是:GroupLayout 一次只能与一个 Container 一起使用。
这是我的代码:
public class SubjectsPanel extends javax.swing.JPanel {
private AddSubject addsubject; //Is an own class that inherites from JDialog.
private AddGroups addgroups; //Is another own class that inherites from JDialog.
private JFrame jf;
public SubjectsPanel(JFrame fr) {
jf = fr;
initComponents();
}
/**
* This method is called from within the constructor to initialize the form.
* WARNING: Do NOT modify this code. The content of this method is always
* regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {
}
private void addButtonActionPerformed(java.awt.event.ActionEvent evt) {
addsubject = new AddSubject(jf,true);
addsubject.setSize(700, 350);
addsubject.setLocationRelativeTo(this);
addsubject.setTitle("Adding New Subject Wizard");
addsubject.setVisible(true);
addsubject.addWindowListener(new WindowListener() {
@Override
public void windowOpened(WindowEvent we) {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
@Override
public void windowClosing(WindowEvent we) {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
@Override
public void windowClosed(WindowEvent we) {
if(addsubject.getBool()){
addgroup = new AddGroup(jf,true);
addgroup.setSize(700, 350);
addgroup.setLocationRelativeTo(this);
addgroup.setTitle("Adding New Group Wizard");
addgroup.setVisible(true);
}
}
@Override
public void windowIconified(WindowEvent we) {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
@Override
public void windowDeiconified(WindowEvent we) {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
@Override
public void windowActivated(WindowEvent we) {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
@Override
public void windowDeactivated(WindowEvent we) {
}
});
}
}
当然,我省略了一些我认为不相关的代码部分。问题出在 WindowListener 中,就在这里:
addgroup = new AddGroup(jf,true);
addgroup.setSize(700, 350);
addgroup.setLocationRelativeTo(this);
addgroup.setTitle("Adding New Group Wizard");
addgroup.setVisible(true);
我怎样才能做好?
对不起我的英语不好。我还尝试阅读有关 GroupLayouts 的其他问题,但我无法用它们解决。