Re: [J2SE] SWT視窗傳值問題...

看板java作者 (我書讀得少 你不要騙我)時間14年前 (2010/03/12 13:24), 編輯推噓0(000)
留言0則, 0人參與, 最新討論串2/2 (看更多)
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
文章代碼(AID): #1BcT07ae (java)
文章代碼(AID): #1BcT07ae (java)