| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 668 人关注过本帖
标题:有关窗口关闭显示的问题
只看楼主 加入收藏
牛虻
Rank: 1
等 级:新手上路
威 望:1
帖 子:472
专家分:0
注 册:2004-10-1
收藏
 问题点数:0 回复次数:5 
有关窗口关闭显示的问题

这边是我做的一个退出窗口确认信息的程序,由两个窗口组成,当我运行第一窗口也就是主窗口的时候,那个退出窗口也会自动弹出来,此处有不解。若按下主窗口中的Quit,那个退出窗口可以正常弹出,若按退出窗口中的No,退出窗口消失,又回到主窗口中,但是可以同时对两个窗口进行控制,我还有一个不解是:如何才能在同一时刻只能对一个窗口进行操作呢。 CODE: //SimpleExample.java 主窗口 import java.awt.*; import java.awt.event.*; import javax.swing.*; import javax.swing.border.*;

public class SimpleExample extends JFrame implements ActionListener { JButton a,b; public SimpleExample() { a = new JButton("Click"); b = new JButton("Quit"); this.getContentPane().setLayout(new FlowLayout()); this.getContentPane().add(a); this.getContentPane().add(b); this.setTitle("Menu"); this.setBounds(450,300,200,200); a.addActionListener(this); b.addActionListener(new QuitFrame()); this.setVisible(true); } public void actionPerformed(ActionEvent ae) { this.setVisible(false); try { Thread.sleep(2000); } catch (Exception ex) { ex.printStackTrace(); } this.setVisible(true); } public static void main(String[] args) { SimpleExample se = new SimpleExample(); } } ------------------------------------------------------------------------- //QuitFrame.java 退出确认窗口 import javax.swing.*; import javax.swing.border.*; import java.awt.*; import java.awt.event.*; public class QuitFrame implements ActionListener { static JFrame win; public void actionPerformed(ActionEvent ea) { win.setVisible(false); if((ea.getActionCommand()).equals("Quit")) win.setVisible(true); if((ea.getActionCommand()).equals("No")) win.setVisible(false); if((ea.getActionCommand()).equals("Yes")) { win.setVisible(false); System.exit(0); } } public QuitFrame() { JLabel msg = new JLabel(); JButton yesbutton = new JButton(); JButton nobutton = new JButton(); JPanel buttonbox = new JPanel(); win = new JFrame("Quit"); msg.setText("Do you really want to quit?"); msg.setBorder(new EmptyBorder(50,50,50,50)); yesbutton.setText("Yes"); nobutton.setText("No");

buttonbox.add(yesbutton); buttonbox.add(nobutton);

win.getContentPane().setLayout(new BorderLayout()); buttonbox.setLayout(new FlowLayout()); win.getContentPane().add(buttonbox,"South"); win.getContentPane().add(msg,"Center"); yesbutton.addActionListener(this);

nobutton.addActionListener(this); win.pack(); win.show(); } public static void main(String [] args) { QuitFrame qf = new QuitFrame(); } } THAT'S ALL

[此贴子已经被作者于2005-9-8 16:44:54编辑过]

搜索更多相关主题的帖子: 窗口 
2005-09-08 15:04
tempnetbar
Rank: 2
等 级:新手上路
威 望:4
帖 子:582
专家分:4
注 册:2004-5-5
收藏
得分:0 
TC

相信勤能补拙! 喜欢用好用的就永远学不到有用的。
2005-09-08 15:31
tempnetbar
Rank: 2
等 级:新手上路
威 望:4
帖 子:582
专家分:4
注 册:2004-5-5
收藏
得分:0 
这个问题我们不是在另外的帖子中讨论过了么?最好就用dialog做,为什么要用窗体呢?

相信勤能补拙! 喜欢用好用的就永远学不到有用的。
2005-09-08 15:35
Knocker
Rank: 8Rank: 8
等 级:贵宾
威 望:47
帖 子:10454
专家分:603
注 册:2004-6-1
收藏
得分:0 
以下是引用tempnetbar在2005-9-8 15:31:42的发言: TC
你还不会TC哩

九洲方除百尺冰,映秀又遭蛮牛耕。汽笛嘶鸣国旗半,哀伤尽处是重生。     -老K
治国就是治吏。礼义廉耻,国之四维。四维不张,国之不国。   -毛泽东
2005-09-08 15:36
飘飘叶子
Rank: 7Rank: 7Rank: 7
等 级:贵宾
威 望:34
帖 子:597
专家分:10
注 册:2005-8-17
收藏
得分:0 
做退出对话框还是用Dialog吧,方便得多
同时只想处理一个窗口只能用mode模式,Dialog里提供了这个

向着软件工程师的目标前进!
2005-09-08 16:02
牛虻
Rank: 1
等 级:新手上路
威 望:1
帖 子:472
专家分:0
注 册:2004-10-1
收藏
得分:0 
以下是引用飘飘叶子在2005-9-8 16:02:27的发言: 做退出对话框还是用Dialog吧,方便得多 同时只想处理一个窗口只能用mode模式,Dialog里提供了这个
谢谢指点。 T Tempnetbar,你多久没用TC拉

土冒
2005-09-08 16:42
快速回复:有关窗口关闭显示的问题
数据加载中...
 
   



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

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