import java.applet.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class TestApplet extends Applet {
Button bt = null;
Label lb = null;
int squareSize = 50;
int num = 0;
private String s= null;
private TextField tf;
public void paint(Graphics g) {
Graphics graphics = g.create(50, 50, 700, 300);
String username = "xxxxxxxxxxxxxxx";
graphics.drawString("hello,"+username, 20,120);
graphics.setFont(new Font("黑體",Font.BOLD + Font.ITALIC,14));
graphics.setColor(Color.red);
graphics.drawRect(40, 40, 650, 250);
graphics.setColor(Color.green);
graphics.fillRect(42,42,648,248);
}
public void init() {
setSize (800, 400);
bt = new Button("點我一下");
add(bt,BorderLayout.CENTER);
bt.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
if (e.getSource() .equals(bt)) {
num++;
lb.setText(num+"次");
}
}
});
this.add(bt);
lb=new Label(" 次");
this.add(lb);
}
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/49329.html
標籤:Java相關
上一篇:大佬們,救急!!!
