JWorld@TW the best professional Java site in Taiwan
      註冊 | 登入 | 全文檢索 | 排行榜  

» JWorld@TW » Java 新手區  

按列印兼容模式列印這個話題 列印話題    把這個話題寄給朋友 寄給朋友    訂閱主題
reply to postflat modego to previous topicgo to next topic
本主題所含的標籤
無標籤
作者 Re:[請益] 請問如何將子視窗關掉而不關掉母視窗 [Re:AirKiller2]
honeyaaa





發文: 159
積分: 0
於 2008-04-09 21:25 user profilesend a private message to userreply to postreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
 
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JTextField;
 
public class FrameA extends JFrame {
 
  private JTextField textField = null;
  private ISendObject sendObject = null;
  private JButton button = null;
  private JButton buttonClose = null ;
 
  public FrameA() {
    textField = new JTextField(20);
    textField.setText("123");
    button = new JButton("新增");
    button.addActionListener(new ActionListener() {
      public void actionPerformed(ActionEvent e) {
        if (sendObject != null)
          sendObject.getSendObject(textField.getText());
      }
    });
    buttonClose = new JButton("關閉");
   
    buttonClose.addActionListener(new ActionListener() {
      public void actionPerformed(ActionEvent e) {
        FrameA.this.dispose();
      }
    });

    setLocationRelativeTo(null);
    setLayout(new FlowLayout());
    setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
    setVisible(true);
    add(textField);
    add(button);
    add(buttonClose);
    pack();
  }
 
  public void addSendObjectListen(ISendObject sendObject) {
    this.sendObject = sendObject;
  }
}
 
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
 
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JTextArea;
 
public class FrameB extends JFrame implements ISendObject {
  private JTextArea textArea = null;
  private JButton button = null;
 
  public FrameB() {
    textArea = new JTextArea(10, 10);
    button = new JButton("開啟");
    setLayout(new FlowLayout());
    add(textArea);
    add(button);
    button.addActionListener(new ActionListener() {
      public void actionPerformed(ActionEvent e) {
        FrameA a = new FrameA();
        a.addSendObjectListen(FrameB.this);
      }
    });
    setSize(300, 400);
    setVisible(true);
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  }
 
  public void getSendObject(Object obj) {
    if (textArea.getText().length() == 0) {
      textArea.setText((String) obj);
    } else if(((String) obj).length() > 0) {
      textArea.setText(textArea.getText() + "\r\n" + (String) obj);
    }
  }
 
}
 
public class TestFrame {
  public static void main(String[] args) {
    FrameB b = new FrameB();
  }
}


這樣嗎??

我是爬文看Duncan大大舊文章的,


honeyaaa edited on 2008-04-09 22:09
reply to postreply to post
努力,是成功唯一的途徑。
話題樹型展開
人氣 標題 作者 字數 發文時間
5181 [請益] 請問如何將子視窗關掉而不關掉母視窗 AirKiller2 426 2008-04-08 23:29
4865 Re:[請益] 請問如何將子視窗關掉而不關掉母視窗 honeyaaa 50 2008-04-09 00:21
4930 Re:[請益] 請問如何將子視窗關掉而不關掉母視窗 AirKiller2 149 2008-04-09 11:53
4876 Re:[請益] 請問如何將子視窗關掉而不關掉母視窗 honeyaaa 2510 2008-04-09 21:25
4779 Re:[請益] 請問如何將子視窗關掉而不關掉母視窗 AirKiller2 9 2008-04-10 12:40
» JWorld@TW »  Java 新手區

reply to postflat modego to previous topicgo to next topic
  已讀文章
  新的文章
  被刪除的文章
Jump to the top of page

JWorld@TW 本站商標資訊

Powered by Powerful JuteForum® Version Jute 1.5.8