日期:2014-05-20 浏览次数:20730 次
import java.awt.BorderLayout; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.JButton; import javax.swing.JDialog; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.JTextField; public class SendPara { public static void main(String[] args) { JFrame jf = new JFrame(); jf.setSize(400,300); jf.add(new Pane1()); jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); jf.setVisible(true); } } class Pane1 extends JPanel implements ActionListener{ private JLabel jlb1; public Pane1(){ jlb1 = new JLabel(""); JButton jbt1 = new JButton("打开A"); setLayout(new BorderLayout()); jbt1.addActionListener(this); add(jlb1,BorderLayout.CENTER); add(jbt1,BorderLayout.SOUTH); } public void setLabelText(String message){ jlb1.setText(message); } public void actionPerformed(ActionEvent e) { A a = new A(this); a.setVisible(true); } } class A extends JDialog implements ActionListener{ private Pane1 _pan1; private JTextField jt1; public A(Pane1 pan1){ super((JFrame)null,true); setSize(400,300); _pan1 = pan1; jt1 = new JTextField(); JButton jbt1 = new JButton("确定"); jbt1.addActionListener(this); setLayout(new BorderLayout()); add(jt1,BorderLayout.CENTER); add(jbt1,BorderLayout.SOUTH); } public void actionPerformed(ActionEvent e) { _pan1.setLabelText(jt1.getText()); dispose(); } }