代码如下,执行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);
}}