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

这边是我做的一个退出窗口确认信息的程序,由两个窗口组成,当我运行第一窗口也就是主窗口的时候,那个退出窗口也会自动弹出来,此处有不解。若按下主窗口中的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
牛虻
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.015957 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved