请完成下列Java程序:建立一个Applet程序,包括创建一个画布构件、一个面板构件,面板构件上包含3个按钮,用来设置画布和面板的背景颜色,这3个按钮(Red、Green、Blue)分别控制画布和面板背景色改变为3原色,即红、绿、蓝。要求画布宽度为300,高度为200。注意:请勿改动main()主方法和其他已有语句内容,仅在下划线处填入适当的语句。源程序文件代码清单如下:import java.awt.*;import java.applet.*;/*<applet code="ex10_2.class" width=800 height=400 ></applet>*/public class ex10_2 extends Applet{private Panel pane110_2;private Canvas canvas10_2;private Button btn1, btn2, btn3;public void init(){canvas10_2=new Canvas();canvas10_2. ______;canvas10_2.setBackground(Color.black);add(canvas10_2);pane110_2 = new Panel();pane110_2.setBackground( Color.black );btn1 = new Button( "Red" );btn2 = new Button( "Green" );btn3 = new Button( "Blue" );pane110_2.add( btn1 );pane110_2.add( btn2 );pane110_2.add( btn3 );______;}public boolean action( Event e, Object o ){if( e.target == btn1 ){pane110_2.setBackground( Color.red );canvas10_2.setBackground( Color.red );}else if( e.target == btn2 ){pane110_2.setBackground( Color.green );canvas10_2.setBackground(Color.green);}else if( e.target == btn3 ){canvas10_2.setBackground( Color.blue );pane110_2.setBackground( Color.blue );}return true;}}
请完成下列Java程序:建立一个Applet程序,包括创建一个画布构件、一个面板构件,面板构件上包含3个按钮,用来设置画布和面板的背景颜色,这3个按钮(Red、Green、Blue)分别控制画布和面板背景色改变为3原色,即红、绿、蓝。要求画布宽度为300,高度为200。
注意:请勿改动main()主方法和其他已有语句内容,仅在下划线处填入适当的语句。
源程序文件代码清单如下:
import java.awt.*;
import java.applet.*;
/*
<applet code="ex10_2.class" width=800 height=400 >
</applet>
*/
public class ex10_2 extends Applet
{
private Panel pane110_2;
private Canvas canvas10_2;
private Button btn1, btn2, btn3;
public void init()
{
canvas10_2=new Canvas();
canvas10_2. ______;
canvas10_2.setBackground(Color.black);
add(canvas10_2);
pane110_2 = new Panel();
pane110_2.setBackground( Color.black );
btn1 = new Button( "Red" );
btn2 = new Button( "Green" );
btn3 = new Button( "Blue" );
pane110_2.add( btn1 );
pane110_2.add( btn2 );
pane110_2.add( btn3 );
______;
}
public boolean action( Event e, Object o )
{
if( e.target == btn1 )
{
pane110_2.setBackground( Color.red );
canvas10_2.setBackground( Color.red );
}
else if( e.target == btn2 )
{
pane110_2.setBackground( Color.green );
canvas10_2.setBackground(Color.green);
}
else if( e.target == btn3 )
{
canvas10_2.setBackground( Color.blue );
pane110_2.setBackground( Color.blue );
}
return true;
}
}