日期:2014-05-20  浏览次数:20787 次

大神给看看
package com.baidu.rumen13;

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;
class MyJDialog extends JDialog{
public MyJDialog(MyFrame frame){
super(frame,"第一个JDialog窗体",true);
Container container=getContentPane();
container.add(new JLabel("这是一个对话框"));
setBounds(120, 120, 100, 100);
}
}
public class MyFrame extends JFrame{
public MyFrame(){
JLabel jl=new JLabel("这是一个Jframe窗体");
setBounds(50, 50, 500, 400);
Container container=getContentPane();
container.setLayout(null);
jl.setHorizontalAlignment(SwingConstants.CENTER);
container.add(jl);


JButton bl=new JButton("弹出对话框");
bl.setBounds(10, 10, 100, 21);
bl.addActionListener(new ActionListener() {

@Override
public void actionPerformed(ActionEvent e) {
new MyJDialog(MyFrame.this).setVisible(true);

}
});
container.add(bl);这个地方书中省略了部分代码
}
public static void main(String[] args) {
new MyFrame();
}
}
为啥点了运行之后 啥都出不来?
------解决方案--------------------
this.setVisible(true);

这句加上试试看!