| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 623 人关注过本帖
标题:背景为什么没有变化?
只看楼主 加入收藏
zzxwill
Rank: 1
等 级:新手上路
帖 子:398
专家分:0
注 册:2007-8-15
收藏
 问题点数:0 回复次数:1 
背景为什么没有变化?

package applet;
import java.awt.*;
import java.awt.event.*;
//背景为什么没有变化?
public class MyChoice extends Frame implements TextListener {

Choice chc=new Choice();
//实例化
public MyChoice(){
setTitle("A new Choice!");
chc.add("yellow");
chc.add("orange");
chc.add("red");
setSize(200,150);
add(chc);
setVisible(true);
chc.addItemListener((ItemListener)this);
}

public void textValueChanged(TextEvent e){
if(chc.getSelectedItem()=="yellow"){
this.setBackground(Color.yellow);
}
else if(chc.getSelectedItem()=="orange"){
this.setBackground(Color.orange);
}
else {
this.setBackground(Color.red);
}

}
public static void main(String args[]){
new MyChoice();



}

}

搜索更多相关主题的帖子: package yellow public Choice import 
2007-11-18 16:09
csight
Rank: 1
等 级:新手上路
威 望:1
帖 子:293
专家分:0
注 册:2006-6-11
收藏
得分:0 

import java.awt.*;
import java.awt.event.*;
public class MyChoice extends Frame{
Choice chc=new Choice();
Container container;

public MyChoice(){
container=this;
setTitle("A new Choice!");
chc.add("yellow");
chc.add("orange");
chc.add("red");
setSize(200,150);
add(chc);
setVisible(true);
chc.addItemListener(new MyListener());
}
class MyListener implements ItemListener
{
public void itemStateChanged(ItemEvent e){
if(chc.getSelectedItem().equals("yellow")){
container.setBackground(Color.yellow);
}
else if(chc.getSelectedItem().equals("orange")){
container.setBackground(Color.orange);
}
else {
container.setBackground(Color.red);
}

}
}
public static void main(String args[]){
new MyChoice();
}
}


头可断,发型不可乱;血可流,皮鞋不可不擦油;
2007-11-18 16:55
快速回复:背景为什么没有变化?
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.025756 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved