首页 > 编程语言 >[java] a simple Applet program

[java] a simple Applet program

时间:2023-01-04 14:36:34浏览次数:46  
标签:makeURLActionListener java simple add Applet program new JButton panel


//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(
);
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=mce_href=">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

标签:makeURLActionListener,java,simple,add,Applet,program,new,JButton,panel
From: https://blog.51cto.com/u_15929756/5988608

相关文章