创 建 一 个 按 钮 咋 又 不 行 了 呢 ? 麻 烦 大 家 看 看 。 。 。 我记得ActionListener有另外的方法,都实现了吗? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 import javax.swing.*;import java.awt.*;import java.awt.event.*;public class ButtonEvent extends JFrame implements ActionListener{ JButton button = new JButton("click me"); JTextArea textArea = new JTextArea(2, 20); Container c; int clickCount = 0; public ButtonEvent() { super ("Button Event Testing"); c = getContentPane(); c.setLayout(new FlowLayout()); c.add(button); c.add(textArea); setSize(300, 120); show();//////////////////////////////////////////////////////////////////// button.addActionListener(this); // <----------* Bug1 } ///////////////////////////////////////////////////////////////////// public void actionPerformed(ActionEvent e) //<--------------* Bug2 { clickCount++; textArea.setText("You have already pressed"+clickCount+"times"); } public static void main(String[] args) { ButtonEvent app = new ButtonEvent(); //app.addWindowListener(new MyWindowListener());//不知道你这句是干什么的,MyWindowListener根本就没有这个接口 }} 我把你的程序在命令行里运行了一下,只是把import java.awt.Event.*; 改成import java.awt.event.*;就可以运行了 应把import java.awt.Event.*;改成import java.awt.event.*;JAVA区分大小写!! 这是使用素数筛法做的输出素数的java程序,不知道哪里错了,请大家帮我看一下。如果还有什么可以优化的地方,请一并踢出来啊,呵呵 TreeSet判断重复元素问题。。求助 高人看一下怎么处理这组数据 Java的新特性enhanced for loop为什么好? 这个冒泡法怎么排序? 打印不出来呀 请大家帮办我 Servlet问题 咨询下大家Java的Swing问题,关于界面按键问题: 谁有过使用Jess 的经验,帮帮忙 IP地址的获得? 请教--有关java网络编程 请教:用JAVA2D写的程序,会出现移植性问题吗? 帮忙看看哪里错了
import java.awt.*;
import java.awt.event.*;public class ButtonEvent extends JFrame
implements ActionListener
{
JButton button = new JButton("click me");
JTextArea textArea = new JTextArea(2, 20);
Container c;
int clickCount = 0;
public ButtonEvent()
{
super ("Button Event Testing");
c = getContentPane();
c.setLayout(new FlowLayout());
c.add(button);
c.add(textArea);
setSize(300, 120);
show();////////////////////////////////////////////////////////////////////
button.addActionListener(this); // <----------* Bug1
}
/////////////////////////////////////////////////////////////////////
public void actionPerformed(ActionEvent e) //<--------------* Bug2
{
clickCount++;
textArea.setText("You have already pressed"+clickCount+"times");
}
public static void main(String[] args)
{
ButtonEvent app = new ButtonEvent();
//app.addWindowListener(new MyWindowListener());
//不知道你这句是干什么的,MyWindowListener根本就没有这个接口 }
}
只是把import java.awt.Event.*;
改成import java.awt.event.*;
就可以运行了
改成import java.awt.event.*;
JAVA区分大小写!!