我在尝试返回上一个JFrame
时遇到了困难。在FirstFrame中,它有一个参数。在secondFrame中,如何返回firstFrame,因为它没有参数?
我正在把头发拉出来。任何帮助,将不胜感激。
FirstFrame.java
public class FirstFrame extends JFrame
{
public FirstFrame(final String name)
{
goToSecondFrame.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
SecondFrame sec= new SecondFrame();
sec.createAndShowGui();
sec.setVisible(true);
setVisible(false);
dispose();
}
});
}
}
SecondFrame.java
public static void main(String[] args) {
SwingUtilities.invokeLater(() -> {
createAndShowGui();
});
}
static void createAndShowGui() {
JFrame frame = new JFrame("Second Frame");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.getContentPane().add(new Second());
frame.pack();
frame.setLocationRelativeTo(null);
frame.setVisible(true);
}
public Second()
{
back.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
FirstFrame back = new FirstFrame(); // Getting error
back.setVisible(true);
setVisible(false);
dispose();
}
});
}
答案 0 :(得分:1)
首先在课程顶部定义框架:
JFrame frame = new JFrame("Delete Admin");
然后这样做:
back.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
staffManagment back = new staffManagment("");
back.setVisible(true);
setVisible(false);
frame.dispose();
}
});