java 的疑问——关于事件监听程序的代码
importjava.awt.*;importjavax.swing.*;importjava.awt.event.*;publicclassTestActionEven...
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
public class TestActionEvent extends JFrame{
private JButton jbtOk=new JButton("OK");
private JButton jbtCancel=new JButton("Cancel");
public TestActionEvent(){
setTitle("TestActionEvent");
getContentPane().setLayout(new FlowLayout());
getContentPane().add(jbtOk);
getContentPane().add(jbtCancel);
ButtonListener btListener=new ButtonListener();
jbtOk.addActionListener(btListener);
jbtCancel.addActionListener(btListener);
}
public static void main(String args[]){
TestActionEvent frame=new TestActionEvent();
frame.setSize(400,300);
frame.setVisible(true);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
}
class ButtonListener implements ActionListener{
public void actionPerformed(ActionEvent e){
System.out.println("The "+e.getActionCommand()+" button is "+"clicked at\n "+new java.util.Date(e.getWhen()));
}
}
如果把import java.awt.event.*;删去为什么编译会出错呢?
不是java.awt.*;已经包括了上面的了吗?
大家出谋划策啊! 展开
import javax.swing.*;
import java.awt.event.*;
public class TestActionEvent extends JFrame{
private JButton jbtOk=new JButton("OK");
private JButton jbtCancel=new JButton("Cancel");
public TestActionEvent(){
setTitle("TestActionEvent");
getContentPane().setLayout(new FlowLayout());
getContentPane().add(jbtOk);
getContentPane().add(jbtCancel);
ButtonListener btListener=new ButtonListener();
jbtOk.addActionListener(btListener);
jbtCancel.addActionListener(btListener);
}
public static void main(String args[]){
TestActionEvent frame=new TestActionEvent();
frame.setSize(400,300);
frame.setVisible(true);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
}
class ButtonListener implements ActionListener{
public void actionPerformed(ActionEvent e){
System.out.println("The "+e.getActionCommand()+" button is "+"clicked at\n "+new java.util.Date(e.getWhen()));
}
}
如果把import java.awt.event.*;删去为什么编译会出错呢?
不是java.awt.*;已经包括了上面的了吗?
大家出谋划策啊! 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询