注意:下面出现的“考生文件夹”均为%USER%。
在考生文件夹中存有文件名为Java_3.java的文件,该程序是不完整的,请在注释行“//**********Found**********”下一行语句的下画线地方填入正确内容,然后删除下画线,请勿删除注释行或改动其他已有语句内容。存盘时文件必须存放在考生文件夹下,不得改变原有文件的文件名。
本题的要求是:
阅读Java_3.java程序,该程序的功能是单击下“黄色”按钮,使图形用户界面窗口的背景色变为黄色。完成程序并运行,所得结果为
![](https://img.ixiawen.com/uploadfile/2017/0712/20170712061703595.jpg)
单击“黄色”按钮后,窗口背景变成黄色。
给定源程序:
import Java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class Java_3
public static void main(String[]args)
ButtonFrame frame=new ButtonFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame show();
//*********Found********
class______extends JFrame
public ButtonFrame()
setTitle("测试按钮");
setSize(DEFAULT_WIDTH, DEFAULT_HEIGHT);
ButtonPanel panel=new ButtonPanel();
Container contentPane=getContentPane();
contentPane.add(panel);
public static final int DEFAULT_WIDTH=200;
public static final int DEFAULT_HEIGHT=100;
class ButtonPanel extends JPanel
public ButtonPanel()
JButton yellowButton=new JButton("黄色");
add(yellowButton);
ColorAction yellowAction=new ColorAction(Color YELLOW);
yellowButton.addActionListener(yellowAction);
//*********Found********
private class ColorAction implements______
public ColorAction(color c)
backgroundColor = c;
//*********Found********
public void______(ActionEvent event)
setBackground(backgroundColor);
private Color backgroundColor;