我有一个简单的代码在这里添加一个标签被点击后。它工作正常,但为了添加标签,我必须在点击按钮后拖动或重新调整窗口大小。Java按钮添加标签后被重新或拖动或其他东西
这里是我的代码:
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);
}
}
}
你会下载陌生人指向的文件吗?如果你想要一些帮助代码,然后将该代码作为纯文本发布。也尝试使[SSCCE](http://sscce.org/)。 – Pshemo 2013-04-06 11:59:45
我在帖子中说过,我不能因为某些原因而不愿意接受它。也许它太长或什么? – 2013-04-06 12:04:54
虐待尝试发布它 – 2013-04-06 12:05:19