Java program problem ?

2008-05-07 10:13 pm
import java.awt.*;
import java.awt.event.*;
import java.util.Random;
public class SevenNumber extends Frame implements ActionListener {
public void main(String args[])
{
int p=0;

Panel panel=new Panel();
TextArea ta = new TextArea();
Button btn=new Button("OK");
btn.addActionListener(this);
TextField tf=new TextField(5);
SevenNumber SN=new SevenNumber();

panel.add(new Label("how many times you want: "));
panel.add(tf);
SN.add(btn,BorderLayout.SOUTH);
SN.add(panel,BorderLayout.NORTH);
SN.add(ta,BorderLayout.CENTER);
for (int i=1; i< 8 ;i++)
{
Random rand= new Random();
p=rand.nextInt(48);
ta.append(" number "+i+" =" +p+"\n");

}


SN.setSize(300,300);
SN.setVisible(true);
}
}


public void actionPerformed(actionEvent e)
{
//incomplete Code
}


Error: C:\jpro\chap9\SevenNumber.java:36: class, interface, or enum expected
public void actionPerformed(actionEvent e)
^
1 error

i want to use Action listener to detect people press the button , however it keep coming error and dont let me add actionlistener , wht is my problem

回答 (1)

2008-05-08 5:08 am
✔ 最佳答案
Two wrong things here:-

1) the method actionPerformed should be declare inside of class SevenNumber

2) wrong spelling of type object actionEvent. First character should be uppercase as below:
public void actionPerformed(ActionEvent e)


收錄日期: 2021-04-20 20:39:50
原文連結 [永久失效]:
https://hk.answers.yahoo.com/question/index?qid=20080507000051KK00977

檢視 Wayback Machine 備份