File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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

One strange question about listener

walter wang
Ranch Hand

Joined: Jun 02, 2001
Posts: 159
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 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() {
try {
catch(Exception e) {
/**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 );
jPanel3.add(jButton1, null);
jPanel2.add(new CallTabbedPane(), BorderLayout.CENTER);
jPanel1a.add(jPanel1aa, BorderLayout.NORTH);
jPanel1a.add(jPanel1ac, BorderLayout.SOUTH);
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
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());
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);
add(tabbedPane, BorderLayout.CENTER);
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
Ranch Hand

Joined: Nov 07, 2000
Posts: 621
I think you may have more luck with this question in the Swing... forum so I'm moving you post there.
I agree. Here's the link:
subject: One strange question about listener
It's not a secret anymore!