[java] a simple Applet program

//java code file

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 feeButton = new JButton("FeeLang"); feeButton.addActionListener(makeURLActionListener( "http://blog.csdn.net/FeeLang")); panel.add(feeButton); JButton mailButton = new JButton("Mail"); mailButton.addActionListener(makeURLActionListener( "mailto:[email protected]")); panel.add(mailButton); add(panel, BorderLayout.SOUTH); } private ActionListener makeURLActionListener(final String u) { return new ActionListener() { public void actionPerformed(ActionEvent event) { try { getAppletContext().showDocument(new URL(u)); } catch(MalformedURLException e) { e.printStackTrace(); } } }; } }

 

 

//html file

<html> <head> <title>WelcomeApplet</title> </head> <body> <hr/> <p> This applet is from the book <a href="http://blog.csdn.net/FeeLang" mce_href="http://blog.csdn.net/FeeLang">FeeLang </a> by <i>FeeLang</i> </p> <applet code="WelcomeApplet.class" width="400" height="200"> <param name="greeting" value="Welcome to Core Java"/> </applet> </body> </html>

 

参考资料 CoreJava

你可能感兴趣的:(java,String,url,Class,import,applet)