呵呵,试验成功,只要在init中加载applet即可。
package test;
import javax.swing.JApplet;
import java.awt.Dimension;
import javax.swing.JButton;
import javax.swing.JPanel;
import java.awt.Rectangle;
import javax.swing.JTextArea;
public class FirstTest extends JApplet{
/**
*
*/
private static final long serialVersionUID = 5936617821137135838L;
private JButton bt1 = null;
private JApplet jApplet = null; // @jve:decl-index=0:visual-constraint="8,8"
private JPanel jContentPane = null;
private JButton bt11 = null;
private JButton bt2 = null;
private JTextArea jTextArea = null;
/**
* This method initializes
*
*/
public FirstTest() {
super();
}
/**
* This method initializes this
*
*/
public void init() {
this.setSize(new Dimension(253, 157));
getContentPane().add(getJApplet());
}
/**
* This method initializes jApplet
*
* @return javax.swing.JApplet
*/
private JApplet getJApplet() {
if (jApplet == null) {
jApplet = new JApplet();
jApplet.setSize(new Dimension(257, 159));
jApplet.setContentPane(getJContentPane());
}
return jApplet;
}
/**
* This method initializes jContentPane
*
* @return javax.swing.JPanel
*/
private JPanel getJContentPane() {
if (jContentPane == null) {
jContentPane = new JPanel();
jContentPane.setLayout(null);
jContentPane.add(getBt11(), null);
jContentPane.add(getBt2(), null);
jContentPane.add(getJTextArea(), null);
}
return jContentPane;
}
/**
* This method initializes bt11
*
* @return javax.swing.JButton
*/
private JButton getBt11() {
if (bt11 == null) {
bt11 = new JButton();
bt11.setBounds(new Rectangle(21, 18, 92, 26));
bt11.setText("添加文字");
bt11.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent e) {
getJTextArea().setText("添加了一行文字!");
}
});
}
return bt11;
}
/**
* This method initializes bt2
*
* @return javax.swing.JButton
*/
private JButton getBt2() {
if (bt2 == null) {
bt2 = new JButton();
bt2.setBounds(new Rectangle(127, 21, 91, 26));
bt2.setText("删除文字");
bt2.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent e) {
getJTextArea().setText("这个按键用来删除这行文字!");
}
});
}
return bt2;
}
/**
* This method initializes jTextArea
*
* @return javax.swing.JTextArea
*/
private JTextArea getJTextArea() {
if (jTextArea == null) {
jTextArea = new JTextArea();
jTextArea.setBounds(new Rectangle(35, 65, 193, 77));
}
return jTextArea;
}
} // @jve:decl-index=0:visual-constraint="10,10"