作者在 2010-06-03 20:34:40 发布以下内容
import java.applet.*;
import java.awt.Button;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.MouseMotionAdapter;
import java.net.MalformedURLException;
import java.net.URL;
public class AppletTest1_1 extends Applet{
String str;
int xOpoint,yOpoint;
public void init() {
str=this.getParameter("Msg");
import java.awt.Button;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.MouseMotionAdapter;
import java.net.MalformedURLException;
import java.net.URL;
public class AppletTest1_1 extends Applet{
String str;
int xOpoint,yOpoint;
public void init() {
str=this.getParameter("Msg");
//转到别一个网页
Button b=new Button("链接");
add(b);
b.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e) {
try {
getAppletContext().showDocument(new URL("http://www.baidu.com"), "_blank");
} catch (MalformedURLException e1) {
// TODO 自动生成 catch 块
e1.printStackTrace();
}
}
});
Button b=new Button("链接");
add(b);
b.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e) {
try {
getAppletContext().showDocument(new URL("http://www.baidu.com"), "_blank");
} catch (MalformedURLException e1) {
// TODO 自动生成 catch 块
e1.printStackTrace();
}
}
});
//画直线
/*addMouseListener(new MouseAdapter(){
public void mousePressed(MouseEvent e) {
xOpoint=e.getX();
yOpoint=e.getY();
}*/
/* public void mouseReleased(MouseEvent e) {
Graphics g=getGraphics();
g.setColor(Color.red);
g.drawLine(xOpoint, yOpoint, e.getX(), e.getY());
}
});*/
}
public void paint(Graphics g) {
g.drawString(str, 0, 30);
}
}
/*addMouseListener(new MouseAdapter(){
public void mousePressed(MouseEvent e) {
xOpoint=e.getX();
yOpoint=e.getY();
}*/
/* public void mouseReleased(MouseEvent e) {
Graphics g=getGraphics();
g.setColor(Color.red);
g.drawLine(xOpoint, yOpoint, e.getX(), e.getY());
}
});*/
}
public void paint(Graphics g) {
g.drawString(str, 0, 30);
}
}