请问事件怎么不执行啊? 这些是jdk1.0的写法了。java2的事件处理机制要优美的多 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 其实,要是保留原来的模式,可以这样改,把if (arg.equals("OK")) setBackground(Color.red); //点击没反应啊?改为if ((arg.toString()).equals("OK"))..... /** * <p>Title: This follow is newman's writing</p> * <p>Description: I want better writing ,instead of best one!</p> * <p>Copyright: Copyright (c) 2002</p> * <p>Company: [email protected]</p> * @author Newman * @version 1.0 */import java.awt.*;import java.awt.event.*;public class ButtonTest extends Frame implements ActionListener{ Panel pPanel=new Panel (); Button b1=new Button("OK"); CircleColor color=new CircleColor(0); public boolean handleEvent(Event evt) { if (evt.id == Event.WINDOW_DESTROY) System.exit(0); return false; } public ButtonTest() { setTitle("Button Test"); setLayout(new FlowLayout()); b1.addActionListener(this) ; pPanel.add(b1); //pPanel.Size(50,80) ; pPanel.setBackground(Color.pink) ; this.add ("Center",pPanel); } public void actionPerformed(ActionEvent e){//监听实现 if(e.getSource ()==b1){ setBackground(this.color.getColor()); //点击有反应了 System.out.println("OK pressed"); } } public static void main(String[] args) { Frame f = new ButtonTest(); //changed by newman f.setSize(300, 200); f.show(); }}class CircleColor{ private int m_nValue=0; private Color[] cols={Color.BLACK ,Color.BLUE ,Color.WHITE ,Color.GREEN,Color.RED}; CircleColor(int value){ this.m_nValue =value; } private int getValue(){ return this.m_nValue ; } public int increase(){ this.m_nValue++; if(this.m_nValue>4){ this.m_nValue =0; } return this.m_nValue ; } public Color getColor(){ this.increase(); return this.cols [this.getValue()]; } } 菜鸟求助 如何解析 牛津词典 mdx文件 byte类型移位相或数据丢失 mysql无法使用update方法往数据库中插入汉字,只能插入数字!急救! 如何从一个String型的算式中获取计算结果 精英? 初学者,求几个最简单的问题 谁能告知UCS-2的中文对照码表?50分相送! 右键菜单功能 java制作的MP3播放器,如何实现时间轴功能 JComboBox下拉的那个东东的尺寸怎么改?解决立即给分。 自定义函数调用问题
if (arg.equals("OK")) setBackground(Color.red); //点击没反应啊?
改为
if ((arg.toString()).equals("OK")).....
* <p>Title: This follow is newman's writing</p>
* <p>Description: I want better writing ,instead of best one!</p>
* <p>Copyright: Copyright (c) 2002</p>
* <p>Company: [email protected]</p>
* @author Newman
* @version 1.0
*/import java.awt.*;
import java.awt.event.*;public class ButtonTest extends Frame implements ActionListener{
Panel pPanel=new Panel ();
Button b1=new Button("OK");
CircleColor color=new CircleColor(0);
public boolean handleEvent(Event evt) {
if (evt.id == Event.WINDOW_DESTROY) System.exit(0);
return false;
}
public ButtonTest() {
setTitle("Button Test");
setLayout(new FlowLayout());
b1.addActionListener(this) ;
pPanel.add(b1);
//pPanel.Size(50,80) ;
pPanel.setBackground(Color.pink) ;
this.add ("Center",pPanel);
} public void actionPerformed(ActionEvent e){//监听实现
if(e.getSource ()==b1){
setBackground(this.color.getColor()); //点击有反应了
System.out.println("OK pressed");
}
}
public static void main(String[] args) {
Frame f = new ButtonTest();
//changed by newman
f.setSize(300, 200);
f.show();
}
}class CircleColor{
private int m_nValue=0;
private Color[] cols={Color.BLACK ,Color.BLUE ,Color.WHITE ,Color.GREEN,Color.RED};
CircleColor(int value){
this.m_nValue =value;
}
private int getValue(){
return this.m_nValue ;
}
public int increase(){
this.m_nValue++;
if(this.m_nValue>4){
this.m_nValue =0;
}
return this.m_nValue ;
}
public Color getColor(){
this.increase();
return this.cols [this.getValue()];
}
}