排错!

RedMay 2004-02-27 10:45:49
报错和程序如下,没改好,大家帮着看看,谢谢!

--------------------Configuration: j2sdk1.4.2_03 <Default>--------------------
C:\j2sdk1.4.2_03\mycode\ThreadTest\Counter2.java:48: actionPerformed(java.awt.event.ActionEvent) in cannot implement actionPerformed(java.awt.event.ActionEvent) in java.awt.event.ActionListener; attempting to assign weaker access privileges; was public
void actionPerformed(ActionEvent e)
^
C:\j2sdk1.4.2_03\mycode\ThreadTest\Counter2.java:61: actionPerformed(java.awt.event.ActionEvent) in cannot implement actionPerformed(java.awt.event.ActionEvent) in java.awt.event.ActionListener; attempting to assign weaker access privileges; was public
void actionPerformed(ActionEvent e)
^
2 errors
------------------------------------------------------------------------

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
//import java.applet.*;


public class Counter2
{
public static void main(String[] args)
{
Counter2Frame frame = new Counter2Frame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.show();
}
}


class Counter2Frame extends JFrame
{
public Counter2Frame()
{
Counter2Panel panel = new Counter2Panel();
getContentPane().add(panel);

setTitle("ThreadTest2");
setSize(300,200);

}
}


class Counter2Panel extends JPanel
{
private JTextField text;
private JButton on;
private JButton off;
private SubThread t1;

public Counter2Panel()
{
setLayout(new BorderLayout());
text = new JTextField(30);
add(text,BorderLayout.CENTER);

on = new JButton("start");
on.addActionListener(new
ActionListener(){
void actionPerformed(ActionEvent e)
{
if (t1 == null)
{
t1 = new SubThread();
t1.start();
}
}

});
off = new JButton("stop");
off.addActionListener(new
ActionListener(){
void actionPerformed(ActionEvent e)
{
if(!(t1 == null))
t1.invertFlag();
}

});

JPanel buttonPanel = new JPanel();
buttonPanel.add(on);

buttonPanel.add(off);
add(buttonPanel,BorderLayout.SOUTH);
}

private class SubThread extends Thread
{
private int counter =0;
private boolean runFlag = true;

public void run()
{
while(true)
{
try{
sleep(100);
}
catch(InterruptedException e){}
}
if(runFlag)
{
text.setText(Integer.toString(++counter));
}

}

public void invertFlag() { runFlag = !runFlag;}



}
}
-------------------------------------------------------------------------


...全文
62 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复

62,614

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧