import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
public class jj extends JFrame implements ActionListener
{
    String a="jiang chao say:hello world!";
   JButton ok=new JButton("确定");
   JButton cancel=new JButton("取消");
   JLabel  label=new JLabel("请输入姓名");
   JTextField text1=new JTextField(50);
   public jj()
   {
     super("example");
     //text.setEditable(false);
     setLayout(new FlowLayout());
     add(ok);add(cancel);
     add(label);add(text1);
     setSize(600,600);
     setLocation(100,100);
     setVisible(true);
   }
  public void actionPerformed(ActionEvent e)
  {
    if(e.getSource()==ok)
    {
     //jc wj=new jc();
    // String a="jiang chao say:hello world!";
     text1.setText(a);
    }
  }
  public static void main(String []args)
  {
    jj wj=new jj();
  }
}
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
public class jc extends JFrame implements ActionListener{
   String s="hello world!";
   JButton ok=new JButton("确定");
   JButton cancel=new JButton("取消");
   JLabel  label=new JLabel("请输入姓名");
   JTextField text=new JTextField(10);
   public jc()
   {
     super("example");
     setLayout(new FlowLayout());
     text.setEditable(false);
     add(ok);add(cancel);
     add(label);add(text);
     ok.addActionListener(this);
     setSize(600,600);
     setLocation(400,400);
     setVisible(true);
   }
   public void actionPerformed(ActionEvent e)
  {
    if(e.getSource()==ok)
    {
     jj  jx=new jj();
     jx.setVisible(true);
      setVisible(false);
      }
  }
  public static void main(String []args)
  {
    jc wj=new jc();
  }
}

解决方案 »

  1.   


    import java.awt.*; 
    import java.awt.event.*; 
    import javax.swing.*; 
    import javax.swing.event.*; 
    public class jj extends JFrame implements ActionListener 

        String a="jiang chao say:hello world!"; 
      JButton ok=new JButton("确定"); 
      
      JButton cancel=new JButton("取消"); 
      JLabel  label=new JLabel("请输入姓名"); 
      JTextField text1=new JTextField(50); 
      public jj() 
      { 
        super("example"); 
        //text.setEditable(false); 
        ok.addActionListener(this);
        setLayout(new FlowLayout()); 
        add(ok);add(cancel); 
        add(label);add(text1); 
        setSize(600,600); 
        setLocation(100,100); 
        setVisible(true); 
      } 
      public void actionPerformed(ActionEvent e) 
      { 
        if(e.getSource()==ok) 
        { 
        jc wj=new jc(); 
        // String a="jiang chao say:hello world!"; 
        text1.setText(wj.s); 
        } 
      } 
      public static void main(String []args) 
      { 
        jj wj=new jj(); 
      } 
    } 莫非你要这样 ?  
      

  2.   

    可以!谢谢你们了!顺便再问个问题:当你点击确定按钮时,会在文本框中显示字符,这时jc这个图形也出现了,如果使用setVisibel(false);jc图形虽然没出现但是很快的闪了一下,能用什么方法做到就根本不让这jc图形出现呢(包括先出现在消失)?也能达到调用jc里面的字符呢?