首页
外语
计算机
考研
公务员
职业资格
财经
工程
司法
医学
专升本
自考
实用职业技能
登录
计算机
本题的功能是用按钮来控制文字的颜色。窗口中有三个按钮:“Yellow”、“Blue”和“Red”,它们分别对应文字标签中文本的颜色为黄色、蓝色和红色,点击任意一个按钮,文字标签中的文本就变成按钮对应的颜色。 import java.awt.*; impor
本题的功能是用按钮来控制文字的颜色。窗口中有三个按钮:“Yellow”、“Blue”和“Red”,它们分别对应文字标签中文本的颜色为黄色、蓝色和红色,点击任意一个按钮,文字标签中的文本就变成按钮对应的颜色。 import java.awt.*; impor
admin
2012-12-02
45
问题
本题的功能是用按钮来控制文字的颜色。窗口中有三个按钮:“Yellow”、“Blue”和“Red”,它们分别对应文字标签中文本的颜色为黄色、蓝色和红色,点击任意一个按钮,文字标签中的文本就变成按钮对应的颜色。
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
class ButtonPanel extends JPanel implements ActionListener{
public ButtonPanel(){
yellowButton = new JButton("Yellow");
blueButton = new JButton("Blue");
redButton = new JButton("Red");
jl = new JLabel("I am from China!");
add(yellowButton);
add(blueButton);
add(redButton);
add(jl);
yellowButton.addActionListener(this);
blueButton.addActionListener(this);
redButton.addActionListener(this);
}
public void actionPerformed(ActionEvent evt){
Object source = evt.getSource();
Color color = getForeground();
if (source == yellowButton) color = Color.yellow;
else if (source == blueButton) color = Color.blue;
else if (source == redButton) color = Color.red;
______;
______;
}
private JButton yellowButton;
private JButton blueButton;
private JButton redButton;
private JLabel jl;
}
class ButtonFrame extends JFrame{
public ButtonFrame(){
setTitle("exam_16");
setSize(300, 200);
addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent e){
System.exit(0);
}
});
Container contentPane = getContentPane();
contentPane.add(new ButtonPanel());
}
}
public class java2{
public static void main(String[] args){
JFrame frame = new ButtonFrame();
frame.show();
}
}
选项
答案
第1处:jl.setForeground(color)第2处:jl.repaint()
解析
在构件类的方法中,setForeground()为设置构件的前景色,repaint()为重新绘制构件。
转载请注明原文地址:https://kaotiyun.com/show/36ID777K
本试题收录于:
二级Java题库NCRE全国计算机二级分类
0
二级Java
NCRE全国计算机二级
相关试题推荐
1949年后,中国积极主动地融人世界。将下列重大外交事件按时间先后顺序排列,正确的是()。①重返联合国②中美关系正常化③参加万隆会议④加入世界贸易组织
亚欧大陆中部、北美洲中部和南美洲南部分布着()。
根据我国《民法通则》中的无过错责任原则,应由下列何人对损害结果承担民事责任?()
我国在大力推进粮食行业信息化发展的同时所要坚持的基本原则不包括()。
中国APEC峰会批准了《亚太经合组织互联互通蓝图》这一里程碑式文件,决心在2025年前实现()的远景目标,并完成共同确立的具体指标。
经济学上所推崇的“橄榄型”收入分配结构.是指低收人和高收入相对较少、中等收入占绝大多数的分配结构。我国正在采取措施,实施“提低、扩中、调高、打非、保困”的方针,使收入分配朝着“橄榄型”方向发展。这主要是为了促进()。
根据下面材料回答下列小题。总体看来,2004年世界各国的石油探明储量基本变化不大。但是由于BP公司修正了前苏联、哈萨克斯坦、伊朗、利比亚和苏丹等国的数据,特别是哈萨克斯坦从12亿吨修正到54亿吨,从而使各国在全球石油储量分布中所占的比例发生了一些变化
设某数据库中有旅客表A(旅客编号,城市)和旅客表B(旅客编号,城市),现将所有旅客的数据存储这两张表中。请补全如下查询语句,使得该查询语句能查询所有旅客所在的全部的不重复的城市。SELECT城市FROM旅客表A【14】SELECT城市FROM旅客表B
用于在子类中调用被重写父类方法的关键字是()。
对话框在关闭前,不能继续执行应用程序的其他部分,这种对话框称为()。
随机试题
A、过清音B、鼓音C、实音D、水泡音E、哮呜音大叶性肺炎
制定安全生产事故应急预案时,应当遵循的原则包括()。
内部控制必须随着有关法律、法规的调整和经营方针、经营理念等外部环境的变化及时修改或完善,这体现了制定内部控制制度的()原则。
如果在国民经济繁荣阶段某行业的销售额逐年同步增长,而在国民经济处于衰退阶段该行业的销售额同步下降,说明这一行业可能是周期性行业。()
一般地,一个完整的公司信贷产品市场营销计划应包括()。
导游在行为上应注意的问题包括()。
以下折线图反映了2014~2018年间哪项收入同比增量的变化趋势?
下列选项中,属于应用法学的是()。
以下程序段的输出结果是【】。main(){inta=2,b=3,c=4;a*=16+(b++)-(++c);printf("%d",a);}
Parentsofwailing(哀号)babies,takecomfort:Youarenotalone.Chimpanzeebabiesfuss.Seagullchickssquawk.Buryingbeetle
最新回复
(
0
)