编写一个图形界面的Application程序,其外观是一个窗框,其中包括一个按钮和一个标签,当用户单击按钮时,

编写一个图形界面的Application程序,其外观是一个窗框,其中包括一个按钮和一个标签,当用户单击按钮时,弹出一个标题为“我的对话框”的无模式对话框,对话框中包括一个文本框和一个按钮,当用户单击此按钮时,对话框关闭,其文本框中的内容被复制到窗框的标签中(为窗框编写一种关闭方法,菜单、按钮、图标均可)
请看清楚题目,一楼的有问题

import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;

import javax.swing.WindowConstants;
import javax.swing.JFrame;

public class ButtonTest extends javax.swing.JPanel implements ActionListener {
private JButton button;
public static void main(String[] args) {
JFrame frame = new JFrame();
frame.getContentPane().add(new ButtonTest());
frame.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
frame.pack();
frame.setVisible(true);
}

public ButtonTest() {
super();
initGUI();
}

private void initGUI() {
try {
setPreferredSize(new Dimension(400, 300));
{
button = new JButton();
this.add(button);
button.setText("Click Me");
button.addActionListener(this);
}
} catch (Exception e) {
e.printStackTrace();
}
}

public void actionPerformed(ActionEvent e) {
if(button.getText().equals("Click Me")){
button.setText("Click Me Again");
}else{
button.setText("Click Me");
}
}

}
温馨提示:答案为网友推荐,仅供参考
相似回答