aspose file tools*
The moose likes Java in General and the fly likes One strange question about listener Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "One strange question about listener" Watch "One strange question about listener" New topic
Author

One strange question about listener

walter wang
Ranch Hand

Joined: Jun 02, 2001
Posts: 156
My question is ::
I regiester windowsEvent two times
one is from baseclass JFrame( all windowsEvent will be
caught and process by processWindowEvent which is
JFrame's method
second i register windows by a anonymous class in line 94)
why if i comment out CallInterface.java line 105
then line 97 will not be invoked when window was closed,
only line 106 will be invoked?
thx for attention
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class CallInterface extends JFrame {
JPanel contentPane;
JPanel jPanel1 = new JPanel();
//jpanel1 contains jpanel1a,
//jpanel1a contains jpanel1aa,jpanel1ab,jPanel1ac jpanelaa
//add label,jpanelab add label and textfields jpanelac add
//label and textfields
JPanel jPanel1a= new JPanel(new BorderLayout());
JPanel jPanel1aa=new JPanel();
JPanel jPanel1ab=new JPanel();
JPanel jPanel1ac=new JPanel();
JLabel label=new JLabel("Please Enter IP address and Port Number ");
JLabel audiolabel=new JLabel("Audio");
JLabel vediolabel=new JLabel("Vedio");
JLabel portlabel1 = new JLabel("Port");
JLabel portlabel2 = new JLabel("Port");
JTextField jTextField1 = new JTextField(5);
JTextField jTextField2 = new JTextField(5);
JTextField jTextField3 = new JTextField(5);
JTextField jTextField4 = new JTextField(5);
JTextField jTextField5 = new JTextField(5);
JPanel jPanel2 = new JPanel(new BorderLayout());
JTextField jTextField6 = new JTextField(5);
JTextField jTextField7 = new JTextField(5);
JTextField jTextField8 = new JTextField(5);
JTextField jTextField9 = new JTextField(5);
JTextField jTextField10 = new JTextField(5);
JPanel jPanel3 = new JPanel();
JButton jButton1 = new JButton();
JButton jButton2 = new JButton();
/**Construct the frame*/
public CallInterface() {
enableEvents(AWTEvent.WINDOW_EVENT_MASK);
try {
jbInit();
setVisible(true);
}
catch(Exception e) {
e.printStackTrace();
}
}
/**Component initialization*/
private void jbInit() throws Exception {
//setIconImage(Toolkit.getDefaultToolkit().createImage(Frame1.class.getResource("[Your Icon]")));
contentPane = (JPanel) this.getContentPane();
contentPane.setLayout(new BorderLayout());
this.setSize(new Dimension(450, 500));
this.setTitle("Call Setting Interface");
jButton1.setText(" Connect ");
contentPane.add(jPanel1, BorderLayout.NORTH);
contentPane.add(jPanel2, BorderLayout.CENTER);
contentPane.add(jPanel3, BorderLayout.SOUTH );
jPanel1.add(jPanel1a);
jPanel1a.add(jPanel1aa,BorderLayout.NORTH);
jPanel1a.add(jPanel1ab,BorderLayout.CENTER);
jPanel1a.add(jPanel1ac,BorderLayout.SOUTH);
jPanel3.add(jButton1, null);
jPanel2.add(new CallTabbedPane(), BorderLayout.CENTER);
//jPanel2.setSize(400,300);
jPanel1a.add(jPanel1aa, BorderLayout.NORTH);
jPanel1a.add(jPanel1ac, BorderLayout.SOUTH);
jPanel1aa.add(label);
jPanel1ab.add(vediolabel);
jPanel1ab.add(jTextField1, null);
jPanel1ab.add(jTextField2, null);
jPanel1ab.add(jTextField3, null);
jPanel1ab.add(jTextField4, null);
jPanel1ab.add(portlabel2, null);
jPanel1ab.add(jTextField5, null);
jPanel1ac.add(audiolabel, null);
jPanel1ac.add(jTextField6, null);
jPanel1ac.add(jTextField7, null);
jPanel1ac.add(jTextField8, null);
jPanel1ac.add(jTextField9, null);
jPanel1ac.add(portlabel1, null);
jPanel1ac.add(jTextField10, null);

addWindowListener // Line 94
(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.out.println("windowClosing was invoked");//line 97
e.getWindow().dispose();
}
});
}
protected void processWindowEvent(WindowEvent e) {
//if commenet out this line,why windowClosing method will not be invoke?
super.processWindowEvent(e);//line 105
System.out.println("processWindowEvent was invoked");//line 106
}
public static void main(String args[]){
new CallInterface();
}
}

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
/**
* @version 1.1 06/02/99
*/
public class CallTabbedPane extends JPanel {
public CallTabbedPane() {
setLayout(new BorderLayout());
UIManager.put("TabbedPane.selected",null);
JTabbedPane tabbedPane = new JTabbedPane();
String tabs[] = {"Vedio", "Audio"};
Color[] colors = {null, null};
for (int i=0;i<tabs.length;i++) {>
tabbedPane.addTab(tabs, createPane(tabs));
tabbedPane.setBackgroundAt(i, colors);
}
tabbedPane.setSelectedIndex(0);
add(tabbedPane, BorderLayout.CENTER);
//setSize(350,250);
}
JPanel createPane(String s) {
JPanel p = new JPanel();
p.add(new JLabel(s));
return p;
}
}


public class Walter { public boolean is_Working_Now (boolean is_boss_Coming) { return is_boss_Coming; }
Sean MacLean
author
Ranch Hand

Joined: Nov 07, 2000
Posts: 621
Walter,
I think you may have more luck with this question in the Swing... forum so I'm moving you post there.
Sean
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: One strange question about listener