36.下面是用java图形类设计的一个简单事件处理程序,其功能参考程序的注释描述,正确填充完整①~⑤空格代码。(注意:相同的标号说明里面的代码是一样的,注意拼写,机考前后多空格与大小写字母错误判断为0分)
事件处理程序:没点击任何按钮的状态如左图,点击对应颜色按钮后变色的状态如右图。
参考程序:
package Demo;
import java.awt.Color;
import java.awt.Container;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
public class ActionEventDemo extends JFrame implements ①//继承Frame实现ActionListener接口{
ActionEventDemo () {
JPanel panel = new JPanel();
// 创建三个事件源
JButton redbutton = new JButton("红色");
JButton greenbutton = new JButton("绿色");
JButton bluebutton = new JButton("蓝色");
//把三个按钮添加到面板panel1中
②(redbutton);
②(greenbutton);
②(bluebutton);
Container con = this.getContentPane();
con.add(panel, "North");
// 为事件源按钮注册事件监听器
redbutton.③;
greenbutton.③;
bluebutton.③;
}
public void actionPerformed(④e) {// 实现接口方法,参数为对应的事件对象
String btnLabel = e.getActionCommand();
Container con = getContentPane();
if (btnLabel.equals("红色")) {
con.setBackground(Color.RED);
} else if (btnLabel.equals("绿色")) {
con.setBackground(Color.GREEN);
} else if (btnLabel.equals("蓝色")) {
con.setBackground(Color.BLUE);
}
}
public static void main(String argc[]) {
ActionEventDemo2 myframe = new ActionEventDemo2();
myframe.setTitle("ActionEvent事件");
myframe.setSize(300, 200);
myframe.⑤; //设置窗体可视
}
}
37.【填空题】 (2分)
已具备运行条件,进入线程队列,排队等待CPU。一旦获得CPU使用权,就可进入___状态。
38.【填空题】 (2分)
线程___步指的是当有一个线程在对某块内存进行操作时,其他线程都不可以对这块内存进行操作,直到该线程完成操作。
39.【填空题】 (2分)
同步方法可以对某个方法进行同步,通过在方法声明部分加上___关键字来实现。
40.【填空题】 (2分)
当一个线程类实例被创建时,线程处于___状态,此时的线程已经被初始化,并分配了资源。
41.【填空题】 (2分)
在Windows系统中,一个运行的exe程序就是一个___。
42.【填空题】 (2分)
在多线程应用程序中,各个线程采用___的方式,实现对临界资源的共享。
编写程序实现右图所示的界面,参见的下图,并为按钮添加事件处理,要求每按一下按钮,数字加5,初始值为0。请参照参考程序的注释描述,正确填充完整①~⑤空格代码。(机考自动判卷,注意区分大小写与前后空格,答案写错不得分)
import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
public class chen {
static int i = 0;
public static void main(String args[]){
final ①button = new JButton("按钮(+5)");//声明一个按钮
JFrame frame = new JFrame("图形界面与事件处理");
②lable = new JLabel();//声明一个标签
button.③ (new ActionListener(){//在按钮上绑定侦听器
public void actionPerformed(ActionEvent e){
if(e.getSource()==button){
④ //每点击一次按钮数字加5,写自加赋值语句不得分
}
}
});
lable.setText("i");
frame.add(lable,BorderLayout.NORTH);
frame.add(button);
frame.setBounds(30, 30, 200, 200);
⑤;//将窗口对象设为可见.
frame.addWindowListener(new WindowAdapter(){
public void WindowClosing(WindowEvent e){
System.exit(0);
}
});
chen che = new chen();
}
}