Topic: 隐藏窗口如何再显示出来 急急急!!!!

  Print this page

1.隐藏窗口如何再显示出来 急急急!!!! Copy to clipboard
Posted by: java_wq
Posted on: 2005-06-12 10:19

两个窗体(主窗体、副窗体),主窗体中一个button,作用是隐藏主窗体显示副窗体,问题是怎么在副窗体中再把主窗体再显示回来。请教高手。急急急!!!!

2.Re:隐藏窗口如何再显示出来 急急急!!!! [Re: java_wq] Copy to clipboard
Posted by: wanghang110119
Posted on: 2005-06-12 11:02

那你在副窗体中定义一个按钮
让主窗体显示显示出来不就行啦!

3.Re:隐藏窗口如何再显示出来 急急急!!!! [Re: java_wq] Copy to clipboard
Posted by: java_wq
Posted on: 2005-06-12 14:19

高手请指教副窗体中按钮代码如何写

4.Re:隐藏窗口如何再显示出来 急急急!!!! [Re: java_wq] Copy to clipboard
Posted by: mesocool
Posted on: 2005-06-12 14:56

setVisible(true);

5.Re:隐藏窗口如何再显示出来 急急急!!!! [Re: java_wq] Copy to clipboard
Posted by: java_wq
Posted on: 2005-06-12 21:56

可是副窗体中如何调用主窗体已经隐藏的类实例,怎样调用setVisible(true)

6.Re:隐藏窗口如何再显示出来 急急急!!!! [Re: java_wq] Copy to clipboard
Posted by: snowbird2005
Posted on: 2005-06-13 00:48

以下代码供参考:

import java.awt.Button;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JFrame;

public class FirstFrame extends JFrame implements ActionListener
{
private Button firstButton,secondButton;
JFrame secondFrame = new JFrame("Second Frame");

public FirstFrame()
{
super("First Frame");

firstButton=new Button("show second frame");
setLayout(new FlowLayout());
firstButton.addActionListener(this);
add(firstButton);
setVisible(true);
setSize(300,300);
setDefaultCloseOperation(EXIT_ON_CLOSE);

secondButton=new Button("show first frame");
secondFrame.setLayout(new FlowLayout());
secondFrame.setSize(400,300);
secondFrame.add(secondButton);
secondFrame.setDefaultCloseOperation(EXIT_ON_CLOSE);

secondButton.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
setVisible(true);
secondFrame.setVisible(false);
}

});

secondFrame.setVisible(false);
}

public void actionPerformed(ActionEvent e)
{
setVisible(false);
secondFrame.setVisible(true);
}

public static void main(String[] args)
{
new FirstFrame();
}

}

7.Re:隐藏窗口如何再显示出来 急急急!!!! [Re: java_wq] Copy to clipboard
Posted by: java_wq
Posted on: 2005-06-13 17:05

我理解楼上高手的意思是在secondFrame中添加了secondButton用来和firstFrame发生联系。我的本意是不能在secondFrame中添加额外的组件(这就破坏了secondFrame的原有布局),直接使用其中的button来把刚刚隐藏的firstFrame显示出来。请高手再次指教,多谢。

8.Re:隐藏窗口如何再显示出来 急急急!!!! [Re: java_wq] Copy to clipboard
Posted by: snowbird2005
Posted on: 2005-06-13 18:16

那你在副窗口secondFrame的原有的button注册一个actionlistener不就行了?


   Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent
Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1
客服电话 18559299278    客服信箱 714923@qq.com    客服QQ 714923