代码如下:packageswing;importjava.awt.*;importjava.awt.event.ActionEvent;importjava.awt.event.ActionListener;importjavax.swing.*;@SuppressWarnings("serial")classMyJDialog...
代码如下:
package swing;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.*;
@SuppressWarnings("serial")
class MyJDialog extends JDialog{
public MyJDialog(MyFrame frame){
super(frame,"窗体",true);
Container container=getContentPane();
container.add(new JLabel("对话框"));
setBounds(120,120,100,100);
}
}
@SuppressWarnings("serial")
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 MyJDialog(MyFrame.this).setVisible(true);
}
});
container.add(bl);
}
}
展开