看板 java 關於我們 聯絡資訊
public class A extends JFrame implements ActionListener { private JLabel lbl = new JLabel("1"); private JButton btn = new JButton("傳值"); public A() { super("A視窗"); getContentPane().add(lbl, BorderLayout.NORTH); getContentPane().add(btn, BorderLayout.SOUTH); btn.addActionListener(this); pack(); setVisible(true); this.addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { System.exit(0); } }); } public void actionPerformed(ActionEvent e) { new B(lbl.getText()); } public static void main(String[] args) { new A(); } } ====================================================================== public class B extends JFrame { private JLabel lbl = new JLabel("1"); public B(String s) { super("B視窗"); lbl.setText(s); getContentPane().add(lbl, BorderLayout.NORTH); pack(); setVisible(true); this.addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { System.exit(0); } }); } } 希望對你有幫助 ^_^ -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 124.219.25.61