猿问

求助,为何不能弹出窗口

import java.awt.Color;

import java.awt.Container;

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;

import javax.swing.SwingConstants;

import javax.swing.WindowConstants;


class MyDialog extends JDialog{

public MyDialog(MyFrame frame){

super(frame,"第一个Jdialog窗口",true);

Container container=getContentPane();

container.add(new JLabel("这是与各对话框"));

setBounds(120,120,100,100);

}

}

public class MyFrame extends JFrame {

public static void main(String[] args) {

new MyFrame();

}

public MyFrame(){

Container container=getContentPane();

container.setLayout(null);

JLabel jl=new JLabel("这是一个JFrame窗口");

jl.setHorizontalAlignment(SwingConstants.CENTER);

container.add(jl);

JButton bl=new JButton("弹出对话框");

bl.setBounds(10,10,100,21);

bl.addActionListener(new ActionListener(){

public void actionPerformed(ActionEvent e){

new MyDialog(MyFrame.this).setVisible(true);

}

});

container.add(bl);

bl.setVisible(true);

jl.setVisible(true);

container.setBackground(Color.blue);

setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);

}

}


慕妹3559746
浏览 1237回答 2
2回答

RM林夕

你这一行注释都不带写的啊,

慕妹3559746

我的神啊,,各位师兄师姐们求助啊
随时随地看视频慕课网APP

相关分类

Java
我要回答