标题:WindowEvent适配器问题!
取消只看楼主
zhouqingle
Rank: 1
等 级:新手上路
帖 子:30
专家分:0
注 册:2005-2-4
 问题点数:0 回复次数:6 
WindowEvent适配器问题!

private class MakeFrameAction implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
JFrame subFrame = new CloseFrame(parFrame);
subFrame.show();
subFrame.addWindowListener(new WindowAdapter()
{
public void WindowClosing(WindowEvent event)
{
if(!parFrame.isShowing());
parFrame.show();
}
});
parFrame.hide();
}
}
我想关闭第二个窗口~然后第一个主窗口会显示出来```可是编译都通过了```主窗口还是没有Show出来`
帮看下应该怎么改。

搜索更多相关主题的帖子: WindowEvent parFrame 配器 subFrame void 
2006-11-12 18:05
zhouqingle
Rank: 1
等 级:新手上路
帖 子:30
专家分:0
注 册:2005-2-4
得分:0 

import java.awt.Toolkit;
import java.awt.Dimension;
import java.awt.Container;
import java.awt.Image;
import java.awt.Color;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JButton;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

public class StudentFrame
{
public static void main(String[] args)
{
OpenFrame frame = new OpenFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.show();
}
}

class OpenFrame extends JFrame
{
private static final int WIDTH = 400;
private static final int HEIGHT = 300;
public OpenFrame()
{
Container con = getContentPane();
Toolkit kit = Toolkit.getDefaultToolkit();
Dimension screenSize = kit.getScreenSize();
int width = screenSize.width;
int height = screenSize.height;
int x = (width - WIDTH)/2;
int y = (height - HEIGHT)/2;
setBounds(x, y, WIDTH, HEIGHT);
Image image = kit.getImage("fuck.gif");
setIconImage(image);
setTitle("主窗口");
setResizable(false);
OpenButtonPanel panel = new OpenButtonPanel(this);
con.add(panel);
}
}

class OpenButtonPanel extends JPanel
{
private JButton makeNewFrameButton;
private JFrame parFrame;
public OpenButtonPanel(JFrame frame)
{
parFrame = frame;
makeNewFrameButton = new JButton("Open New Frame");
add(makeNewFrameButton);
makeNewFrameButton.addActionListener(new MakeFrameAction());
}


private class MakeFrameAction implements ActionListener
{

public void actionPerformed(ActionEvent e)
{
JFrame subFrame = new CloseFrame(parFrame);
subFrame.show();
subFrame.addWindowListener(new WindowAdapter()
{
public void WindowClosing(WindowEvent event)
{
if(!parFrame.isShowing());
parFrame.show();
}
});
parFrame.hide();
}
}
}


class CloseFrame extends JFrame
{
private static final int WIDTH = 400;
private static final int HEIGHT = 300;
private JFrame parFrame;

public CloseFrame(JFrame frame)
{
parFrame = frame;
Container con = getContentPane();
setSize(WIDTH, HEIGHT);
setTitle("第二个窗口");
setResizable(false);
CloseButtonPanel panel = new CloseButtonPanel(this);
con.add(panel);
}
class CloseButtonPanel extends JPanel
{
public CloseButtonPanel(JFrame subFrame)
{
JButton closeNewFrameButton = new JButton("Close New Button");
add(closeNewFrameButton);
closeNewFrameButton.addActionListener(new CloseNewFrameAction(subFrame));
}
}

class CloseNewFrameAction implements ActionListener
{
private JFrame subFrame;
public CloseNewFrameAction(JFrame subFrame)
{
this.subFrame = subFrame;
}
public void actionPerformed(ActionEvent e)
{
subFrame.hide();
parFrame.show();
}
}
}
不好意思```这回发完了~~我以为看这里可以看出问题```


学会珍惜,所以懂得放弃;学会残忍,所以懂得完整. 有自己的性格,自信,乐观,顺其自然,爱自己最好.
2006-11-12 22:32
zhouqingle
Rank: 1
等 级:新手上路
帖 子:30
专家分:0
注 册:2005-2-4
得分:0 

我是想在第二个窗口弹出来后~~按窗口右上角的关闭来关闭窗口~~使第一次主窗口跳回出来~~
可是我这里不跳啊~~晕了```还要按Ctrl+C才能结束进程~~~


学会珍惜,所以懂得放弃;学会残忍,所以懂得完整. 有自己的性格,自信,乐观,顺其自然,爱自己最好.
2006-11-12 23:56
zhouqingle
Rank: 1
等 级:新手上路
帖 子:30
专家分:0
注 册:2005-2-4
得分:0 
你那可以实现这个事件吗?~~
可是我的编译都通过了,没找出错误出来呢~~~

学会珍惜,所以懂得放弃;学会残忍,所以懂得完整. 有自己的性格,自信,乐观,顺其自然,爱自己最好.
2006-11-13 00:03
zhouqingle
Rank: 1
等 级:新手上路
帖 子:30
专家分:0
注 册:2005-2-4
得分:0 

public void WindowClosing(WindowEvent e)
{
System.out.println("晕晕");
if(!parFrame.isShowing());
parFrame.setVisible(true);
}
我在事件里加了这个输出字符串~~~System.out.println("晕晕");可是没输出效果~~这样的话要怎么解决了~~卡死在这里了`~~晕晕的


学会珍惜,所以懂得放弃;学会残忍,所以懂得完整. 有自己的性格,自信,乐观,顺其自然,爱自己最好.
2006-11-13 00:50
zhouqingle
Rank: 1
等 级:新手上路
帖 子:30
专家分:0
注 册:2005-2-4
得分:0 
谢谢各位了`问题解决了~~~
WindowClosing改成windowClosing就没问题了````

学会珍惜,所以懂得放弃;学会残忍,所以懂得完整. 有自己的性格,自信,乐观,顺其自然,爱自己最好.
2006-11-13 02:48
zhouqingle
Rank: 1
等 级:新手上路
帖 子:30
专家分:0
注 册:2005-2-4
得分:0 
是啊。以后会注意的~~~太盲目了,没有好好检查

学会珍惜,所以懂得放弃;学会残忍,所以懂得完整. 有自己的性格,自信,乐观,顺其自然,爱自己最好.
2006-11-13 12:12



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-102464-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.087577 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved