//下面的代码用了匿名内部类。
jButton1.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(ActionEvent e) {
jButton1_actionPerformed(e);
}
});
jButton1.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(ActionEvent e) {
jButton1_actionPerformed(e);
}
});
public class extends JApplet
{
JButton bu = new JButton("click");
pubic void init()
{
bu.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e)
{ System.out.prinltn("");}
});
}
}
但是不能有任何 修饰词,和 普通的 inner class一样用
e.g:
this.addWindowListener(new WindowAdapter (){
public void windowClosing(WindowEvent e){
System.exit(0); }});
qxjavajava(射手座 =--->听歌看海
Anubis12345(东大d徒然草)
buttonControl1.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(MouseEvent e) {
buttonControl1_mouseClicked(e);
}
});
Note the keyword new just after the first parenthesis. This indicates that an anonymous inner class is being defined within the method addMouseListener. This class could have been defined normally with a name which might make it easier for a human to read, but as no processing is done with it anywhere else, having a name does not help much.If you create such code by hand, it is easy to get confused over the number and level of brackets and parentheses. Note how the whole structure ends with a semi colon, as this is actually the end of a method call.As you might guess an anonymous class cannot have a constructor. Think about it, a constructor is a method with no return value and the same name as the class. Duh! we are talking about classes without names. An anonymous class may extend another class or implement a single interface. This peculiar limit does not seem to be tested in the exam.
我也帮你顶! 我明天再看看,然后跟你聊聊,今天先走一步~~
我看这本书的时候在这里就很困难,现在有些东西还不是很清楚