C:\ Program Files \ Java \ jdk1.6.0_05 \ CoreJava \ v1 \ v1ch2 \ WelcomeApplet> dir 驱动器C中的卷没有标签。 卷序列号是2041-64E7 C:\ Program Files \ Java \ jdk1.6.0_05 \ CoreJava \ v1 \ v1ch2 \ WelcomeApplet的目录2009-07-02 23:54。2009-07-02 23:54 ..2004-09-06 14:57 582 WelcomeApplet.html2004-09-06 15:04 1,402 WelcomeApplet.java 2个文件1,984字节 2 Dir 2,557,210,624字节免费C:\ Program Files \ Java \ jdk1.6.0_05 \ CoreJava \ v1 \ v1ch2 \ WelcomeApplet> javac WelcomeApplet.javaC:\ Program Files \ Java \ jdk1.6.0_05 \ CoreJava \ v1 \ v1ch2 \ WelcomeApplet> dir 驱动器C中的卷没有标签。 卷序列号是2041-64E7 C:\ Program Files \ Java \ jdk1.6.0_05 \ CoreJava \ v1 \ v1ch2 \ WelcomeApplet的目录2009-07-02 23:54。2009-07-02 23:54 ..2009-07-02 23:54 975 WelcomeApplet $ 1.class2009-07-02 23:54 1,379 WelcomeApplet.class2004-09-06 14:57 582 WelcomeApplet.html2004-09-06 15:04 1,402 WelcomeApplet.java 4个文件4,338字节 2 Dir 2,557,202,432字节免费C:\ Program Files \ Java \ jdk1.6.0_05 \ CoreJava \ v1 \ v1ch2 \ WelcomeApplet>这是该Java文件的内容:/** @version 1.21 2002-06-19 @author Cay Horstmann*/import javax.swing.*;import java.awt.*;import java.awt.event.*;import java.net.*;public class WelcomeApplet extends JApplet{ public void init() { setLayout(new BorderLayout()); JLabel label = new JLabel(getParameter("greeting"), SwingConstants.CENTER); label.setFont(new Font("Serif", Font.BOLD, 18)); add(label, BorderLayout.CENTER); JPanel panel = new JPanel(); JButton cayButton = new JButton("Cay Horstmann"); cayButton.addActionListener(makeURLActionListener( "http://www.horstmann.com")); panel.add(cayButton); JButton garyButton = new JButton("Gary Cornell"); garyButton.addActionListener(makeURLActionListener( "mailto:gary@thecornells.com")); panel.add(garyButton); add(panel, BorderLayout.SOUTH); }
3 回答
慕桂英4014372
TA贡献1871条经验 获得超13个赞
它来自以下“代码行”:
return new
ActionListener()
{
public void actionPerformed(ActionEvent event)
{
try
{
getAppletContext().showDocument(new URL(u));
}
catch(MalformedURLException e)
{
e.printStackTrace();
}
}
};
ActionListener每次调用该方法时,您都以自己的方式声明该匿名内部类的实例。
即使未调用该方法,上面的行仍将被编译为匿名内部类,无论如何。
添加回答
举报
0/150
提交
取消