我想在主窗口中点击个button,弹出一个对话框,中间有个jTextField,可以输入数据,然后点击ok,把输入的数据返回给主窗口,程序该怎么写啊,谢谢

解决方案 »

  1.   

    好像很简单哦但是我没有  gui 的代码了google一下 很多
      

  2.   

    import java.awt.FlowLayout;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;import javax.swing.*;/**
     * 
     *//**
     * @author sunsnowad
     *
     */
    public class Demo extends JFrame{
    JButton button;
    JLabel labelResult;
    public Demo(){
    super();
    init();
    }

    private void init() {
    this.setLayout(new FlowLayout());
    this.setSize(400, 300);
    this.setLocation(0, 0);

    button = new JButton("test");
    button.addActionListener(new CustomActionListener(this));
    this.add(button);

    labelResult = new JLabel("show result");
    this.add(labelResult);
    }
    /**
     * @param args
     */
    public static void main(String[] args) {
    Demo frame = new Demo();
    frame.setVisible(true); }}
    class CustomActionListener implements ActionListener {
    Demo demo;
    public CustomActionListener(Demo demo) {
    this.demo = demo;
    } /* (non-Javadoc)
     * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
     */
    public void actionPerformed(ActionEvent e) {
    // TODO Auto-generated method stub
    demo.labelResult.setText(JOptionPane.showInputDialog(""));
    }}
      

  3.   

    谢谢,还有点问题,我弹出的dialog上面需要有图片,然后输入图片的数字,所以不能直接JOptionPane.showInputDialog("")
      

  4.   

    想用javaapplication做个开心网的外挂,在frame1中启动个thread,这个thread把下载个远程的校验图片(这个可以假设下载到本地了),然后弹出个对话框,里面包含图片和Input框,让人输入验证码,点击确认把输入的数据返回thread后,thread继续运行,现在就碰到个难点,怎样将数据传到thread