package manager;import javax.swing.JDialog;
import javax.swing.JPanel;
import java.awt.BorderLayout;
import java.awt.Dimension;
import javax.swing.JLabel;
import java.awt.Rectangle;
import javax.swing.JTextField;
import javax.swing.JComboBox;
import javax.swing.JButton;public class Welcome extends JDialog{ private JDialog jDialog = null;  //  @jve:decl-index=0:visual-constraint="227,4"
private JPanel jContentPane = null;
private JLabel WelPicture = null;
private JLabel UserName = null;
private JComboBox inputUserName = null;
private JLabel PassWord = null;
private JTextField inputPassWord = null;
private JButton WelOK = null;
private JButton WelEXIT = null;
private JDialog getJDialog() {
if (jDialog == null) {
jDialog = new JDialog();
jDialog.setLocationRelativeTo(null);
jDialog.setSize(new Dimension(489, 301));
jDialog.setTitle("企业人事管理系统");
jDialog.setContentPane(getJContentPane());
}
return jDialog;
}
private JPanel getJContentPane() {
if (jContentPane == null) {

PassWord = new JLabel();
PassWord.setBounds(new Rectangle(72, 154, 100, 22));
PassWord.setText("密码:");

UserName = new JLabel();
UserName.setBounds(new Rectangle(74, 113, 94, 25));
UserName.setText("用户名:");

WelPicture = new JLabel();
WelPicture.setBounds(new Rectangle(2, 2, 480, 83));
WelPicture.setText("显示图片");

jContentPane = new JPanel();
jContentPane.setLayout(null);
jContentPane.add(WelPicture, null);
jContentPane.add(UserName, null);
jContentPane.add(getInputUserName(), null);
jContentPane.add(PassWord, null);
jContentPane.add(getInputPassWord(), null);
jContentPane.add(getWelOK(), null);
jContentPane.add(getWelEXIT(), null);
}
return jContentPane;
} private JComboBox getInputUserName() {
if (inputUserName == null) {
inputUserName = new JComboBox();
inputUserName.setBounds(new Rectangle(224, 113, 118, 26));
inputUserName.addItem("admin");
}
return inputUserName;
} private JTextField getInputPassWord() {
if (inputPassWord == null) {
inputPassWord = new JTextField();
inputPassWord.setBounds(new Rectangle(222, 153, 129, 23));
}
return inputPassWord;
}
private JButton getWelOK() {
if (WelOK == null) {
WelOK = new JButton();
WelOK.setBounds(new Rectangle(90, 210, 108, 25));
WelOK.setText("确定");
}
return WelOK;
}
private JButton getWelEXIT() {
if (WelEXIT == null) {
WelEXIT = new JButton();
WelEXIT.setBounds(new Rectangle(230, 208, 110, 29));
WelEXIT.setText("放弃");
}
return WelEXIT;
}

public static void main(String[]args){
Welcome welthis =new Welcome();
welthis.show();

}}

解决方案 »

  1.   

    public static void main(String[] args) {
    Welcome welthis = new Welcome();
    JDialog jd=welthis.getJDialog();
    // welthis.show();
    jd.setVisible(true); }
      

  2.   

    做过swt的 没做swing的 绑定
      

  3.   

    .......
    既然继承JDialog 为什么里面还要来个JDialog的变量?
    奇怪的设计
      

  4.   

    public static void main(String[] args) {
            Welcome welthis = new Welcome();
            welthis.setContentPane(welthis.getJContentPane());
            welthis.setSize(500, 400);
            welthis.setVisible(true);
        }