我在这里有一个简单的代码,它在被点击后添加了一个标签。它工作正常,但为了添加标签,我必须在单击按钮后拖动或重新调整窗口。
这是我的代码:
import java.applet.*;
import java.awt.*;
import java.awt.event.*;
public class server01 extends Applet implements ActionListener {
Label helloLabel = new Label("applet v 0.0.1 | created for testing purpose");
Label hello2Label = new Label("this applet will be up-to-date.");
Button buttonButton = new Button("START" + " Button");
Label buttonLabel = new Label("Starting server...");
private static final long serialVersionUID = 1L;
public void init() {
setBackground(Color.black);
setForeground(Color.white);
buttonButton.setForeground(Color.black);
add(helloLabel);
add(hello2Label);
add(buttonButton);
buttonButton.addActionListener(this);
}
public void actionPerformed(ActionEvent e) {
if (e.getSource() == buttonButton) {
add(buttonLabel);
}
}
}