瑞星卡卡安全论坛技术交流区系统软件 菜鸟关于监听的问题,谢谢!

1   1  /  1  页   跳转

菜鸟关于监听的问题,谢谢!

菜鸟关于监听的问题,谢谢!

写了好几个,都是同一个错误,拿个最简单的来看看
import java.awt.*;
import javax.swing.*;
import java.applet.*;
import java.awt.event.*;
class C extends JFrame
{
  JLabel lab=new JLabel("hello");
  JTextField txt=new JTextField(10);
  JButton button=new JButton("OK");
  click c=new click();
  public C(String str)
  {
    this.setTitle(str);
    Container pane=this.getContentPane();
    button.addActionListener( c );
    pane.setLayout(new FlowLayout());
    pane.setBackground(Color.blue);
    pane.add(lab);
    lab.setHorizontalAlignment(lab.CENTER);
    pane.add(txt);
    pane.add(button);
    this.setSize(150,150);
    this.setLocation(400,150);
  }
  private class click implements ActionListener
  {
    public void actionperformed(ActionEvent e)
    {
      System.out.println("yes");
    }
  }
  public static void main(String[]args)
  {
    C c=new C("test");
    c.show(true);
  }
}
C.click 不是抽象的,并且未覆盖 java.awt.event.ActionListener 中的抽象方法 actionPerformed(java.awt.event.ActionEvent)
private class click implements ActionListener
不知道什么意思啊,都是未覆盖 java.awt.event.ActionListener 中的抽象方法,怎么解决啊?在线等,谢谢了...

最后编辑2006-11-18 15:25:37
分享到:
gototop
 

ActionListener接口actionPerformed方法没实现
类首字母用大写
gototop
 

都改了,还是老样子,老大,你能做个简单的监听给我试试吗,谢谢了啊
gototop
 

引用:
【令小虎翀的贴子】都改了,还是老样子,老大,你能做个简单的监听给我试试吗,谢谢了啊
………………

import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import java.sql.*;

public class Exam extends JFrame implements ActionListener
{
    Container con;
    JLabel jl1,jl2,jl3;
    JTextField jtf1,jtf2,jtf3;
    JButton jb1,jb2,jb3;
      public Exam()
      {
          con=this.getContentPane();
          con.setLayout(null);
          jl1=new JLabel("班号");
          jl2=new JLabel("参考人数");
          jl3=new JLabel("通过认输");
          jtf1=new JTextField("");
          jtf2=new JTextField("");
          jtf3=new JTextField("");
          jb1=new JButton("输入数据");
          jb2=new JButton("通过率查询");
          jb3=new JButton("关闭");
         
          con.add(jl2);
          con.add(jl1);
          con.add(jl3);
          con.add(jtf1);
          con.add(jtf2);
          con.add(jtf3);
          con.add(jb1);
          con.add(jb2);
          con.add(jb3);
         
          jl1.setBounds(20,30,100,30);
          jtf1.setBounds(20,60,100,30);
          jl2.setBounds(150,30,100,30);
          jtf2.setBounds(150,60,100,30);
          jl3.setBounds(280,30,100,30);
          jtf3.setBounds(280,60,100,30);
          jb1.setBounds(50,150,100,30);
          jb2.setBounds(180,150,100,30);
          jb3.setBounds(130,200,100,30);
          jb3.addActionListener(this);
          jb2.addActionListener(this);
          jb1.addActionListener(this);
         
          this.setSize(400,300);
          this.setVisible(true);
      }
public void actionPerformed(ActionEvent e)
{
    if(e.getSource()==jb1)
    {
        int class_id=Integer.parseInt(jtf1.getText());
        int total=Integer.parseInt(jtf2.getText());
        int pass=Integer.parseInt(jtf3.getText());
        float ratio=((float)pass)/((float)total);
        try
        {
            SQLDemo sql=new SQLDemo();
            sql.insert(class_id,total,pass,ratio);
        }
        catch(ClassNotFoundException ee)
        {
            ee.printStackTrace();
        }
        catch(SQLException ee)
        {
            ee.printStackTrace();
        }
        JOptionPane.showMessageDialog(con,"数据添加成功","提示",JOptionPane.INFORMATION_MESSAGE);
    }
    else if(e.getSource()==jb2)
    {
        Find f =new Find();
        this.dispose();
    }
    else if(e.getSource()==jb3)
    {
        this.dispose();
    }
}

public static void main(String[] args)
{
    Exam no1=new Exam();
    no1.setTitle("考试通过率设计");
}   
}

gototop
 

我看还是你的:click c=new click();
  这里有问题 类首字母用大写 拼写是否错误

  点击上面程序的关闭按钮
gototop
 

package com.myTest;

import java.awt.*;
import javax.swing.*;

import java.awt.event.*;
class C extends JFrame
{
JLabel lab=new JLabel("hello");
JTextField txt=new JTextField(10);
JButton button=new JButton("OK");
Click c=new Click();
public C(String str)
{
this.setTitle(str);
Container pane=this.getContentPane();
button.addActionListener( c );
pane.setLayout(new FlowLayout());
pane.setBackground(Color.blue);
pane.add(lab);
lab.setHorizontalAlignment(lab.CENTER);
pane.add(txt);
pane.add(button);
this.setSize(150,150);
this.setLocation(400,150);
}
private class Click implements ActionListener
{


public void actionPerformed(ActionEvent e) {
    System.out.println("yes");
   
}
}
public static void main(String[]args)
{
C c=new C("test");
c.show(true);
}
}
gototop
 

楼上的好强啊

  我怎么没看出他的actionperformed 有错
gototop
 

哪天也要请你帮我看看好吗

附件附件:

下载次数:117
文件类型:application/octet-stream
文件大小:
上传时间:2006-11-18 13:57:08
描述:



gototop
 

我倒,迷糊我几天的东西竟然又是大小写的问题,我汗啊...
再次谢谢了啊老大!!!
gototop
 
1   1  /  1  页   跳转
页面顶部
Powered by Discuz!NT