当前位置: 代码迷 >> Java相关 >> ,上面这个程序的有关问题出在那里
  详细解决方案

,上面这个程序的有关问题出在那里

热度:507   发布时间:2013-02-25 21:44:10.0
求助,下面这个程序的问题出在那里
package interfaces;
import javax.swing.*;
import java.awt.event.*;

public class HandleEvent extends JFrame{

public HandleEvent()
{
JButton jbtOK = new JButton("OK");
JButton jbtCancel = new JButton("Cancel");
 
JPanel panel = new JPanel();
panel.add(jbtOK);
panel.add(jbtCancel);
 
add(panel);
 
OKListenerClass listener1 = new OKListenerClass();
CancelListenerClass listener2 = new CancelListenerClass();
jbtOK.addActionListener(listener1);
jbtCancel.addActionListener(listener2);
}
 
public static void main(String[] args) {
JFrame frame = new HandleEvent();
frame.setTitle("Handle Event");
frame.setSize(200,150);
frame.setLocation(200,100);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);

}

}

class OKListenerClass implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
System.out.println("OK button clicked");
}
}

class CancelListenerClass implements ActionListener
{
public void actionPerfermed(ActionEvent e)
{
System.out.println("Cancel button clicked");
}
}


------解决方案--------------------------------------------------------
Java code
class CancelListenerClass implements ActionListener{public void actionPerfermed(ActionEvent e){System.out.println("Cancel button clicked");}}
  相关解决方案