当前位置: 技术问答>java相关
applet中如何打开一个新网页?
来源: 互联网 发布时间:2014-12-25
本文导语: applet中如何打开一个新网页? | (COPY) type a new URL in a textfield, and press a button to go to that page. import java.applet.*; import java.awt.*; import java.awt.event.*; import java.net.*; public class GotoURLButton...
applet中如何打开一个新网页?
|
(COPY)
type a new URL in a textfield, and press a button to go to that page.
import java.applet.*;
import java.awt.*;
import java.awt.event.*;
import java.net.*;
public class GotoURLButton extends Applet implements
ActionListener {
Button b;
TextField t;
public void init() {
t = new TextField(20);
add(t);
b = new Button("Go to this URL");
add(b);
b.addActionListener(this);
}
public void actionPerformed(ActionEvent ae) {
if (ae.getSource() == b) {
try {
getAppletContext().showDocument(new URL(t.getText()));
}
catch (Exception e) {
e.printStackTrace();
}
}
}
}
type a new URL in a textfield, and press a button to go to that page.
import java.applet.*;
import java.awt.*;
import java.awt.event.*;
import java.net.*;
public class GotoURLButton extends Applet implements
ActionListener {
Button b;
TextField t;
public void init() {
t = new TextField(20);
add(t);
b = new Button("Go to this URL");
add(b);
b.addActionListener(this);
}
public void actionPerformed(ActionEvent ae) {
if (ae.getSource() == b) {
try {
getAppletContext().showDocument(new URL(t.getText()));
}
catch (Exception e) {
e.printStackTrace();
}
}
}
}