请完善程序(程序文件名:Java_3.java)并进行调试。请在下画线处填入正确内容,然后删除下画线。请勿删除注释行和其他已有的语句内容。
[题目要求]
生成下面左边图形界面,单击图中的New按钮,弹出如右图所示的对话框。
源程序:
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class Java_3
public static void main(String[] args)
MulticastFrame frame=new MulticastFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.show();
class MulticastFrame extends JFrame
public MulticastFrame()
setTitle("MulticastTest");
setSize(WIDTH,HEIGHT);
MulticastPanel panel=new MulticastPanel();
Container contentPane=getContentPane();
contentPane.add( (1) );
public static final int WIDTH=300;
public static final int HEIGHT=200;
class MulticastPanel extends JPanel
public MulticastPanel()
JButton newButton=new JButton("New");
add(newButton);
ActionListener newListener=new ActionListener()
public void actionPerformed(ActionEvent event)
makeNewFrame();
;
newButton.addActionListener(newListener);
closeAllButton=new JButton("Close all");
add(closeAllButton);
private void makeNewFrame()
final BlankFrame frame=new BlankFrame();
frame.show();
ActionListener closeAllListener=new ActionListener()
public void actionPerformed(ActionEvent event)
frame. (2) (); //使窗口隐藏或消除
;
closeAllButton.addActionListener( (3) );
private JButton closeAllButton;
Class BlankFrame extends JFrame
public BlankFrame()
(4) ++;
setTitle("Frame"+counter);
setSize(WIDTH,HEIGHT);
setLocation(SPACING*counter,SPACING*counter);
public static final int WIDTH=200;
public static final int HEIGHT=150;
public static final int SPACING=30;
private static int counter=0;
参考答案:panel
解析: 通过程序解析可以看出,需要将panel构件添加到内容面板上。