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

» JWorld@TW » Java 新手區  

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





發文: 50
積分: 0
於 2008-04-08 23:29 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
我在JFRAME 中 又開了一個 自已寫的JFRAME 這個兩FRAME

一個是主CLASS 一個是innerclass

因為我用

setDefaultCloseOperation(EXIT_ON_CLOSE);

好像就是直接將整個process 關閉

而且 System.exit(0) 更不用說了 沒機會

請問要如何將開啟的子視窗關閉

而不會連帶把母視窗關掉????

謝謝大大

順帶一提

我的主class 和 innerclass 都有implements ActionListener

然後 我的innerclass 的button 好像抓不到 innerclass 裡的 ActionListener

是因為我add ActionListener的時候 是用 this 的關系嗎?!

如果是的話 inner class 要怎麼改呢?!

謝謝


AirKiller2 edited on 2008-04-08 23:32
reply to postreply to post
作者 Re:[請益] 請問如何將子視窗關掉而不關掉母視窗 [Re:AirKiller2]
honeyaaa





發文: 159
積分: 0
於 2008-04-09 00:21 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
setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);

reply to postreply to post
努力,是成功唯一的途徑。
作者 Re:[請益] 請問如何將子視窗關掉而不關掉母視窗 [Re:AirKiller2]
AirKiller2





發文: 50
積分: 0
於 2008-04-09 11:53 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
樓上大大的用法我用了

他是按右上角的x 就關掉視窗

而且母視窗不會跟著關閉

但我想說

如果 用一個butten

去觸發呢?!

換句話說就是

自製一個butten 在上面

然後按下這個buttn之後 便將視窗關閉

請問如何使用呢?!

謝謝


reply to postreply to post
作者 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
努力,是成功唯一的途徑。
作者 Re:[請益] 請問如何將子視窗關掉而不關掉母視窗 [Re:AirKiller2]
AirKiller2





發文: 50
積分: 0
於 2008-04-10 12:40 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
OK了 謝謝Cool

reply to postreply to post
» JWorld@TW »  Java 新手區

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

JWorld@TW 本站商標資訊

Powered by Powerful JuteForum® Version Jute 1.5.8