Applet1.html:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=GBK">
<title>
HTML Test Page
</title>
</head>
<body>
untitled12.Applet1 will appear below in a Java enabled browser.<br>
<applet
codebase = "."
code = "untitled12.Applet1.class"
name = "TestApplet"
width = "400"
height = "300"
hspace = "0"
vspace = "0"
align = "middle"
>
</applet>
</body>
</html>Applet1.java
package untitled12;import java.awt.*;
import java.awt.event.*;
import java.applet.*;
import javax.swing.*;
import javax.swing.border.*;/**
* <p>Title: </p>
* <p>Description: </p>
* <p>Copyright: Copyright (c) 2003</p>
* <p>Company: </p>
* @author unascribed
* @version 1.0
*/public class Applet1 extends Applet
{
private boolean isStandalone = false;
private JTextField jTextField1 = new JTextField();
private JLabel jLabel1 = new JLabel();
private JButton OK = new JButton();
private TitledBorder titledBorder1;
//Get a parameter value
public String getParameter(String key, String def)
{
return isStandalone ? System.getProperty(key, def) :
(getParameter(key) != null ? getParameter(key) : def);
} //Construct the applet
public Applet1()
{
}
//Initialize the applet
public void init()
{
try
{
jbInit();
}
catch(Exception e)
{
e.printStackTrace();
}
}
//Component initialization
private void jbInit() throws Exception
{
titledBorder1 = new TitledBorder("");
jTextField1.setBounds(new Rectangle(129, 70, 99, 21));
this.setLayout(null);
jLabel1.setBorder(titledBorder1);
jLabel1.setBounds(new Rectangle(128, 119, 106, 29));
OK.setBounds(new Rectangle(131, 170, 108, 29));
OK.setText("OK");
OK.addActionListener(new Applet1_OK_actionAdapter(this));
this.add(jTextField1, null);
this.add(jLabel1, null);
this.add(OK, null);
}
//Start the applet
public void start()
{
}
//Stop the applet
public void stop()
{
}
//Destroy the applet
public void destroy()
{
}
//Get Applet information
public String getAppletInfo()
{
return "Applet Information";
}
//Get parameter info
public String[][] getParameterInfo()
{
return null;
}
//Main method
public static void main(String[] args)
{
Applet1 applet = new Applet1();
applet.isStandalone = true;
Frame frame;
frame = new Frame();
frame.setTitle("Applet Frame");
frame.add(applet, BorderLayout.CENTER);
applet.init();
applet.start();
frame.setSize(400,320);
Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
frame.setLocation((d.width - frame.getSize().width) / 2, (d.height - frame.getSize().height) / 2);
frame.setVisible(true);
} void OK_actionPerformed(ActionEvent e)
{
jLabel1.setText(jTextField1.getText()+",java欢迎你");
}
}class Applet1_OK_actionAdapter implements java.awt.event.ActionListener
{
private Applet1 adaptee; Applet1_OK_actionAdapter(Applet1 adaptee)
{
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e)
{
adaptee.OK_actionPerformed(e);
}
}
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=GBK">
<title>
HTML Test Page
</title>
</head>
<body>
untitled12.Applet1 will appear below in a Java enabled browser.<br>
<applet
codebase = "."
code = "untitled12.Applet1.class"
name = "TestApplet"
width = "400"
height = "300"
hspace = "0"
vspace = "0"
align = "middle"
>
</applet>
</body>
</html>Applet1.java
package untitled12;import java.awt.*;
import java.awt.event.*;
import java.applet.*;
import javax.swing.*;
import javax.swing.border.*;/**
* <p>Title: </p>
* <p>Description: </p>
* <p>Copyright: Copyright (c) 2003</p>
* <p>Company: </p>
* @author unascribed
* @version 1.0
*/public class Applet1 extends Applet
{
private boolean isStandalone = false;
private JTextField jTextField1 = new JTextField();
private JLabel jLabel1 = new JLabel();
private JButton OK = new JButton();
private TitledBorder titledBorder1;
//Get a parameter value
public String getParameter(String key, String def)
{
return isStandalone ? System.getProperty(key, def) :
(getParameter(key) != null ? getParameter(key) : def);
} //Construct the applet
public Applet1()
{
}
//Initialize the applet
public void init()
{
try
{
jbInit();
}
catch(Exception e)
{
e.printStackTrace();
}
}
//Component initialization
private void jbInit() throws Exception
{
titledBorder1 = new TitledBorder("");
jTextField1.setBounds(new Rectangle(129, 70, 99, 21));
this.setLayout(null);
jLabel1.setBorder(titledBorder1);
jLabel1.setBounds(new Rectangle(128, 119, 106, 29));
OK.setBounds(new Rectangle(131, 170, 108, 29));
OK.setText("OK");
OK.addActionListener(new Applet1_OK_actionAdapter(this));
this.add(jTextField1, null);
this.add(jLabel1, null);
this.add(OK, null);
}
//Start the applet
public void start()
{
}
//Stop the applet
public void stop()
{
}
//Destroy the applet
public void destroy()
{
}
//Get Applet information
public String getAppletInfo()
{
return "Applet Information";
}
//Get parameter info
public String[][] getParameterInfo()
{
return null;
}
//Main method
public static void main(String[] args)
{
Applet1 applet = new Applet1();
applet.isStandalone = true;
Frame frame;
frame = new Frame();
frame.setTitle("Applet Frame");
frame.add(applet, BorderLayout.CENTER);
applet.init();
applet.start();
frame.setSize(400,320);
Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
frame.setLocation((d.width - frame.getSize().width) / 2, (d.height - frame.getSize().height) / 2);
frame.setVisible(true);
} void OK_actionPerformed(ActionEvent e)
{
jLabel1.setText(jTextField1.getText()+",java欢迎你");
}
}class Applet1_OK_actionAdapter implements java.awt.event.ActionListener
{
private Applet1 adaptee; Applet1_OK_actionAdapter(Applet1 adaptee)
{
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e)
{
adaptee.OK_actionPerformed(e);
}
}
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货