JAVA中的界面返回

来源:百度知道 编辑:UC知道 时间:2024/06/19 23:44:16
我想在两个界面中通过按扭来回跳转,
但是只能转一次,第二次不能引用原来的Panel,
请高手指教

两个CLASS:

第一个

public class GUILogin extends JFrame implements ActionListener
{
JPanel PLogin;
private JButton BFindPWD;

public GUILogin()
{
PLogin = new JPanel ();
PLogin.setLayout(null);
BFindPWD = new JButton ("Forget PWD");
BFindPWD.addActionListener(this);

PLogin.add(BFindPWD);
BFindPWD.setBounds(660, 430, 90, 30);
}

public void SetFrame()
{
setContentPane(PLogin);
setSize(800, 732);
setTitle("Library");
setLocationRelativeTo(null);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setResizable(false);
setVisible(true);
}
public void actionPerformed(ActionEvent e)
{
if(e.getSource().equals(BLSubmit))
{
GUIFindPWD DBProFindPWD = new GUIFindPWD();
setContentPane(DBProFindPWD.P

可以不继承把两个JFrame类写到一个类里面多方便

//这里应该怎么写才能返回上一个界面?
//就是GUILogin
===========================================
Component c;
for(;(c=this.getParent())!=null;)
if(c instanceof GUILogin)break;
if(c!=null){
((GUILogin)c).SetFrame();
}