import java.awt.*;
import java.awt.event.*;
import java.applet.*;
public class Try extends Applet implements ActionListener
{
public void init()
{
Button b=new Button("请按按钮");
b.addActionListener(this);
add(b);
}
public void actionPerformed(ActionEvent e)
{
Frame f=new Frame("警告");
f.setSize(200,100);
f.setLocation(300,300);
f.add(new Label("你按了按钮!"));
f.setVisible(true);
}
}
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
public class MyApplet extends JApplet {
public MyApplet() {
}
public void init(){
myFont = new Font("Dialog",Font.BOLD,16);
Bigger = new JButton("BIGGER");
Smaller = new JButton("Smaller");
jPanel1 = new JPanel();
jPanel2 = new JPanel();
jLabel1 = new JLabel("This is a Applet test!!");
jLabel1.setFont(myFont);
jPanel1.setLayout(new FlowLayout());
jPanel1.add(Bigger);
jPanel1.add(Smaller);
jPanel2.add(jLabel1);
Container cp= this.getContentPane();
cp.setLayout(new BorderLayout());
cp.add(jPanel1,BorderLayout.SOUTH);
cp.add(jPanel2,BorderLayout.CENTER);
Bigger.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent evt) {
BiggerActionPerformed(evt);
}
});
Smaller.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent evt) {
SmallerActionPerformed(evt);
}
});
this.setVisible(true);
}
private void BiggerActionPerformed(ActionEvent evt){
int size = myFont.getSize()+2;
myFont = new Font("Dialog",Font.BOLD,size);
this.jLabel1.setFont(myFont);
}
private void SmallerActionPerformed(ActionEvent evt){
int size = myFont.getSize()-2;
myFont = new Font("Dialog",Font.BOLD,size);
this.jLabel1.setFont(myFont);
}
private JButton Bigger,Smaller;
private JPanel jPanel1,jPanel2;
private JLabel jLabel1;
private Font myFont;
}