在为组件创建监听器时,监听器不是应该继承相应接口的所有的方法吗?为什么下面的这个不用呀?
新手不懂的啦
import java.awt.*;
import java.awt.event.*;
public class Ak extends Frame implements ActionListener{
Label label1,label2;
TextField text1,text2,text3;
Button button1;
public static void main(String args[]){
Ak fr=new Ak();
fr.setTitle("aaa");
fr.setSize(300,300);
fr.setBackground(Color.red);
fr.setLayout(new FlowLayout());
fr.setVisible(true);
fr.go();
}
public void go(){
label1=new Label("haha");
label1.setBackground(Color.green);
text1=new TextField(10);
text1.setSize(2,4);
label2=new Label("haha");
text2=new TextField(10);
button1=new Button("haha");
text3=new TextField(10);
add(label1);
add(text1);
add(label2);
add(text2);
add(button1);
add(text3);
button1.addActionListener(this);
}
public void actionPerformed(ActionEvent e){
float c;
int a,b;
a=Integer.parseInt(text1.getText());
b=Integer.parseInt(text2.getText());
c=a*b;
text3.setText(String.valueOf(c));
}
}
新手不懂的啦
import java.awt.*;
import java.awt.event.*;
public class Ak extends Frame implements ActionListener{
Label label1,label2;
TextField text1,text2,text3;
Button button1;
public static void main(String args[]){
Ak fr=new Ak();
fr.setTitle("aaa");
fr.setSize(300,300);
fr.setBackground(Color.red);
fr.setLayout(new FlowLayout());
fr.setVisible(true);
fr.go();
}
public void go(){
label1=new Label("haha");
label1.setBackground(Color.green);
text1=new TextField(10);
text1.setSize(2,4);
label2=new Label("haha");
text2=new TextField(10);
button1=new Button("haha");
text3=new TextField(10);
add(label1);
add(text1);
add(label2);
add(text2);
add(button1);
add(text3);
button1.addActionListener(this);
}
public void actionPerformed(ActionEvent e){
float c;
int a,b;
a=Integer.parseInt(text1.getText());
b=Integer.parseInt(text2.getText());
c=a*b;
text3.setText(String.valueOf(c));
}
}
解决方案 »
- 有人看过李刚写的《轻量级Java EE企业应用实战》第3版么?有个问题困扰
- 给位大侠帮我解决个问题
- Tomcat启动问题!急急急~
- Web Services 问题,接口数据发送时,报“p”的错误,我看没有什么<p>的节点呀,也没有为结束的节点
- dsfsdf
- 谁有spring+struts+ibatis源代码???小弟谢谢了!!
- 关于Hibernate学习的讨论(欢迎正在学习、已经学完和大牛们进来讨论下)
- 各位: 请问找工作时 公司是否看重证书的威力? Java 程序员应该考哪个认证??
- 关于HIBERNATE的入门问题,很简单快来拿分了
- 想请问各位朋友一个问题
- MyEclpse中文乱码
- JNI如何传递vc中带指针的参数和函数的问题
你不是已经实现了ActionListener吗
* @(#)ActionListener.java 1.18 06/04/13
*
* Copyright 2006 Sun Microsystems, Inc. All rights reserved.
* SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
*/package java.awt.event;import java.util.EventListener;/**
* The listener interface for receiving action events.
* The class that is interested in processing an action event
* implements this interface, and the object created with that
* class is registered with a component, using the component's
* <code>addActionListener</code> method. When the action event
* occurs, that object's <code>actionPerformed</code> method is
* invoked.
*
* @see ActionEvent
* @see <a href="http://java.sun.com/docs/books/tutorial/post1.0/ui/eventmodel.html">Tutorial: Java 1.1 Event Model</a>
*
* @author Carl Quinn
* @version 1.18 04/13/06
* @since 1.1
*/
public interface ActionListener extends EventListener { /**
* Invoked when an action occurs.
*/
public void actionPerformed(ActionEvent e);
}