这个代码没问题但就是结果和我想得不一样,第二张图片我必须得点击一下关闭键才会出现标签和文本框,为什么啊?求大佬解决啊啊啊啊!!!!!!
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
public class Demo01 extends JDialog {
public Demo01(JFrame jFrame){
super(jFrame,"ss",true);
this.setBounds(100,200,100,200);
this.setLayout(new FlowLayout());
this.setBackground(Color.white);
this.setDefaultCloseOperation(DISPOSE_ON_CLOSE);
this.setVisible(true);
this.add(new Label("zhanghu"));
this.add(new TextField(""));
}
public static void main(String[] args) {
JFrame jFrame=new JFrame("en");
jFrame.setBounds(100,100,100,100);
jFrame.setLayout(new FlowLayout());
jFrame.setBackground(Color.white);
jFrame.add(new Label("hh"));
jFrame.add(new TextField(" "));
Button button=new Button("dianji");
jFrame.add(button);
jFrame.setVisible(true);
jFrame.setDefaultCloseOperation(EXIT_ON_CLOSE);
button.addActionListener(new AbstractAction() {
@Override
public void actionPerformed(ActionEvent actionEvent) {
Demo01 demo01=new Demo01(jFrame);
demo01.setVisible(true);
}
});
}
}