1个回答
展开全部
import javax.swing.*;
import javax.swing.text.FieldView;
import java.awt.*;
import java.awt.event.*;
public class Test2 extends JFrame{
public static void main(String[] args) {
new Test2();
}
JButton popupButton=null,sureButton=null;
JLabel label=null;
JTextField field=null;
JTextArea area=null;
public Test2() {
label=new JLabel("获取对话框中的值:");
area=new JTextArea(10,10);
area.setLineWrap(true);
popupButton=new JButton("弹出对话框");
popupButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
new MyDialog(Test2.this,"xdyuan33").setVisible(true);
}
});
Container con=getContentPane();
con.add(label,BorderLayout.WEST);
con.add(area);
con.add(popupButton, BorderLayout.SOUTH);
field=new JTextField(15);
sureButton=new JButton("确定");
setLocationRelativeTo(null);
setDefaultCloseOperation(3);
pack();
setVisible(true);
}
class MyDialog extends Dialog{
public MyDialog(Test2 test2,String title) {
super(test2,title);
field.setText("");
add(field);
add(sureButton, BorderLayout.SOUTH);
sureButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
Test2.this.area.append(field.getText());
dispose();
}
});
addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
dispose();
}
});
setLocationRelativeTo(test2);
pack();
}
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询