哪位大虾帮忙做做这个程序要对的哦
来源:百度知道 编辑:UC知道 时间:2024/05/15 08:05:09
import java.awt.*;
import java.awt.event.*;
public class MyPanel extends Frame {
Button b = new Button("ButtonName");
double heigth, weigth;
double x, y;
TextField tf1 = new TextField(null, 10);
public MyPanel() {
super("MyPanel");
setLayout(new FlowLayout(FlowLayout.LEFT));
add(tf1);
add(b);
pack();
setVisible(true);
addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});
b.addActionListener(new ButtonListener());
}
class ButtonListener implements ActionListener {
public void actionPerformed(ActionEvent e) {
if (tf1.getText() != null) {
try {
b.setLabel(tf1.getText());
} catch (NumberFormatException ex) {
b.setLabel("ButtonName");
}
}
}
}