import java.awt.*;
import java.awt.event.*;
import java.applet.*;
import java.awt.Graphics;
import java.net.*;public class HelloApplet extends Applet implements ActionListener
{
public void init ()
{
GridLayout layout = new GridLayout (3, 4, 15, 5);
setLayout (layout);
Font font = new Font ("TimesRoman", Font.PLAIN, 24);
setFont (font);
Button button = new Button ("sun1");
button.setActionCommand ("http://www.sum.com");
button.addActionListener(this);
add (button);
}
public void paint (Graphics g)
{
g.drawString ("Hello World!", 0, 50);
}
public void actionPerformed (ActionEvent event)
{
String pageName = event.getActionCommand ();
try
{
URL url = new URL (pageName);
AppletContext context = getAppletContext ();
context.showDocument (url, "_blank");
}
catch (MalformedURLException e)
{
repaint ();
}
}
}
import java.awt.event.*;
import java.applet.*;
import java.awt.Graphics;
import java.net.*;public class HelloApplet extends Applet implements ActionListener
{
public void init ()
{
GridLayout layout = new GridLayout (3, 4, 15, 5);
setLayout (layout);
Font font = new Font ("TimesRoman", Font.PLAIN, 24);
setFont (font);
Button button = new Button ("sun1");
button.setActionCommand ("http://www.sum.com");
button.addActionListener(this);
add (button);
}
public void paint (Graphics g)
{
g.drawString ("Hello World!", 0, 50);
}
public void actionPerformed (ActionEvent event)
{
String pageName = event.getActionCommand ();
try
{
URL url = new URL (pageName);
AppletContext context = getAppletContext ();
context.showDocument (url, "_blank");
}
catch (MalformedURLException e)
{
repaint ();
}
}
}
解决方案 »
- JAVA小程序,我希望写一个窗口中出现三个球,但很囧地现在出现三个窗口,每个窗口一个球。。。这是怎么回事啊,应该怎么改?谢谢各位大侠了
- 求助~~~作业 急 哪个大虾可以帮忙
- Properties 问题 读不到 我知道路径问题!。。。
- 我写了这样一个监听
- 请用过appfuse程序的大侠进来看看!谢谢!
- 如何得到JPasswordTextField的文本内容
- C#转JAVA-up有分!
- js操作iframe的讨论,引入子页面
- 采用Lucene索引技术,糊糊搜索时只是搜索索引文件,不用再读取数据库,大大提高性能。索引文件是什么格式的?
- 关于JAVA!!!!
- 一个java文件只能声明一个类吗?
- 在jframe中怎样调用jsp页阿~~
txt.setActionCommand("ddddd");
txt.addActionListener(new ActionListener ()
{
public void actionPerformed (ActionEvent arg0)
{
System.out.println (arg0.getActionCommand());
}
});
void setActionCommand(String command)
Sets the command string used for action events.