本程序中,主窗口有一个按钮“显示对话框”,点击该按钮后显示一个对话框,对话框的标题是“对话框”,其上有一个文字标签“这是一个练习,希望大家都能考个好成绩”,此时仍允许对原来窗口进行操作,当关闭新生成的对话框时退出程序。运行结果如图所示。
注意:请勿改动main()主方法和其他已有语句内容,仅在横线处填入适当语句。 Import __________; import java.awt.event.*; import javax.swing.*; public class Example2_2 extends Frame implements ActionListener { private Dialog dlg; private Button but; public static void main(String argv[]) { Example2_2 f = new Example2_2("Example2_2"); Panel pan=new Panel(); } public Example2_2(String str) { super(str); setSize(200,200); setLayout (new FlowLayout ()); but = new Button("显示 Dialog"); add (but); but. addActionListener (this); dlg = new Dialog(______,"Dialog",false); dlg.add("Center",new Label("这是一个练习,希望大家都能考个好成绩")); dlg.setSize(300,100); setVisible (true); addWindowListener (new WindowAdapter ( ) { public void windowClosing(WindowEvent e){ System.exit (0); } }); dlg.addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { System.exit (0); } }); }public void actionPerformed(ActionEvent e){ dlg. setVisible(true); //显示介面 } }