62,612
社区成员
发帖
与我相关
我的任务
分享
import java.applet.Applet;
import java.awt.BorderLayout;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JLabel;
public class DialogTest extends Applet {
protected JButton ok = new JButton("OK");
private JLabel fl = new JLabel("哈哈");
public void init() {
setLayout(new BorderLayout());
setSize(200, 200);
add(fl, BorderLayout.CENTER);
add(ok, BorderLayout.SOUTH);
ok.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
fl.setFont(new Font("宋体", Font.ITALIC, 20));
// FontMetrics fm = fl.getFontMetrics(fl.getFont());
// int width = fm.stringWidth(fl.getText());
// fl.setPreferredSize(new Dimension(width, fl.getHeight()));
fl.repaint();
}
});
setVisible(true);
}
public static void main(String[] args) {
DialogTest app = new DialogTest();
}
}
JLabel labTest = new Label("test");
JButton btnTest = new JButton("hello");
btnTest.addActionListener(this);
public void actionPerformed(ActionEvent e) {
String strCmd = e.getActionCommand();
if (strCmd.equals("hello")) {
System.out.println("happen");
labTest.setText("test ok!");
labTest.repaint();
}
}