代码如下,执行setVisible(true)之前会输出“State:Normal”,执行后正常的话应该会输出:“State:Normal After Show Dlg”,但却不是这样子的。
请问这是为什么呢?谢谢....
xp + eclipse
package com.pj.append;import java.awt.Component;
import java.awt.Container;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.GridLayout;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JLabel;/** 应用程序的主界面。 */
public class GenFrame extends JFrame {
private static final String APPLICATION_NAME = "工具";
private static final long serialVersionUID = 667587814456162071L;
private static final int DEFAULT_HEIGHT_FRAME = 150;
private static final int DEFAULT_WIDTH_FRAME = 440;
private static int DIALOG_WIDTH = 400;
private static int DIALOG_HEIGHT = 120; private JButton btnRun; public GenFrame() {
setTitle(APPLICATION_NAME);
setSizeAndCentralizeMe(this, DEFAULT_WIDTH_FRAME, DEFAULT_HEIGHT_FRAME);
Container con = null;
con = new Container();
con.setLayout(new FlowLayout(FlowLayout.CENTER));
btnRun = new JButton("运行(R)");
btnRun.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
ProcessDialog dlg = new ProcessDialog();
System.out.println("State:Normal");
dlg.setVisible(true);
System.out.println("State:Normal After Show Dlg");
}
});
con.add(btnRun);
add(con);
setVisible(true);
} private class ProcessDialog extends JDialog {
private JButton btnFinish;
public JLabel progressHint;
private JLabel titleHint; public ProcessDialog() {
super(GenFrame.this);
setModal(true);
setLayout(new GridLayout(3, 1));
setSizeAndCentralizeMe(this, DIALOG_WIDTH, DIALOG_HEIGHT);
titleHint = new JLabel("正在准备运行...");
progressHint = new JLabel("正在准备运行...");
add(titleHint);
add(progressHint);
Container con = new Container();
con.setLayout(new FlowLayout(FlowLayout.CENTER));
btnFinish = new JButton("完成(F)");
btnFinish.setMnemonic('F');
btnFinish.setEnabled(false);
con.add(btnFinish);
add(con);
}
} /** 设置程序大小并定位程序在屏幕正中 */
private void setSizeAndCentralizeMe(Component cmp, int width, int height) {
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
cmp.setSize(width, height);
cmp.setLocation((screenSize.width - width) >> 1,
(screenSize.height - height) >> 1);
}}
请问这是为什么呢?谢谢....
xp + eclipse
package com.pj.append;import java.awt.Component;
import java.awt.Container;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.GridLayout;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JLabel;/** 应用程序的主界面。 */
public class GenFrame extends JFrame {
private static final String APPLICATION_NAME = "工具";
private static final long serialVersionUID = 667587814456162071L;
private static final int DEFAULT_HEIGHT_FRAME = 150;
private static final int DEFAULT_WIDTH_FRAME = 440;
private static int DIALOG_WIDTH = 400;
private static int DIALOG_HEIGHT = 120; private JButton btnRun; public GenFrame() {
setTitle(APPLICATION_NAME);
setSizeAndCentralizeMe(this, DEFAULT_WIDTH_FRAME, DEFAULT_HEIGHT_FRAME);
Container con = null;
con = new Container();
con.setLayout(new FlowLayout(FlowLayout.CENTER));
btnRun = new JButton("运行(R)");
btnRun.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
ProcessDialog dlg = new ProcessDialog();
System.out.println("State:Normal");
dlg.setVisible(true);
System.out.println("State:Normal After Show Dlg");
}
});
con.add(btnRun);
add(con);
setVisible(true);
} private class ProcessDialog extends JDialog {
private JButton btnFinish;
public JLabel progressHint;
private JLabel titleHint; public ProcessDialog() {
super(GenFrame.this);
setModal(true);
setLayout(new GridLayout(3, 1));
setSizeAndCentralizeMe(this, DIALOG_WIDTH, DIALOG_HEIGHT);
titleHint = new JLabel("正在准备运行...");
progressHint = new JLabel("正在准备运行...");
add(titleHint);
add(progressHint);
Container con = new Container();
con.setLayout(new FlowLayout(FlowLayout.CENTER));
btnFinish = new JButton("完成(F)");
btnFinish.setMnemonic('F');
btnFinish.setEnabled(false);
con.add(btnFinish);
add(con);
}
} /** 设置程序大小并定位程序在屏幕正中 */
private void setSizeAndCentralizeMe(Component cmp, int width, int height) {
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
cmp.setSize(width, height);
cmp.setLocation((screenSize.width - width) >> 1,
(screenSize.height - height) >> 1);
}}
解决方案 »
- 空指针异常,看了好久好久,实在看不出来,求帮助
- 求教java编程制作电子书系统的方法
- 做对日有没有钱途啊??????前辈指点下
- 用java编写通讯录
- java 多线程编程求助……
- 使用RMI时抛出 error during JRMP connection establishment; nested exception is:java.io.EOFException]
- 怎样使文件选择器可以选择多个文件?
- 很奇怪,我用jb+wls已经成功的发布过entitybean,我重新做一个的时候,deploy一个jar的时候什么反映都没有??
- 高手们! java 那条函数得到当前的工作目录?
- 有没有java打印的例子程序,请给两个!
- 用String.replace函數替換回車換行回題
- 数据显示问题,请大家帮帮忙,急!
这个对话框就是一个模态的了
模态对话框显示后,父对话框时要等待模态对话框响应完成了才会继续执行的。
谢谢...Modal dialog:
a dialog that blocks some windows while it is visible. The blocked windows are determined according to the dialog's scope of blocking.