Solved

Where's the System.out.println() disappeared to?

Posted on 2002-05-08
38
181 Views
Last Modified: 2010-03-31
Can anyone tell me why this prog doesnt print "Goodbye"?

import java.awt.*;
import java.awt.event.*;
import java.net.*;
import java.io.*;
import java.util.*;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowListener;


public class EmptyFrame extends Frame{

public thisWindowListener winlisna;


public EmptyFrame(){
this.addWindowListener(winlisna = new thisWindowListener());
}


public class thisWindowListener extends WindowAdapter{

public thisWindowListener(){
System.out.println("Hi again");
}

public void windowClosing(WindowEvent e){
System.out.println("Goodbye");

}

}//end class


public static void main(String args[])
{

System.out.println("HEY");

EmptyFrame aFrame = new EmptyFrame();

aFrame.show();

}

}
0
Comment
Question by:afterburner
  • 17
  • 14
  • 6
  • +1
38 Comments
 
LVL 16

Expert Comment

by:heyhey_
ID: 6996317
on my system it prints

HEY
Hi again
Goodbye
0
 
LVL 35

Expert Comment

by:girionis
ID: 6996320
 Hmmm... This is really weird. I have just tried it on my machien (copied/pasted your code) and it works fine... Tt prints "Goodbye" everytime I attempt to close the window. I am using JDK1.4 (even though it would not matter).

  I am running out of ideas. Try restarting your computer or recompiling...

  Hope it helps.
0
 

Author Comment

by:afterburner
ID: 6996482
heyhey; girionis;

done those ideas too. Deleted all class files, renamed the class, rebooted, cold booted ...

The idea of getting the "Goodbye" to print was that it was a placeholder for testing why the shutdown routine from my reall app stopped writing out some data to a disk file. But now, not only did the real app not do that writeout, java is now not even calling windowClosing on my machine.

Would it make any difference having Forte on the same machine? I'm a bit unsure of whether there could be any conflicts somewhere.
afterbr
0
 
LVL 16

Expert Comment

by:heyhey_
ID: 6996495
maybe your CLASSPATH got messed. try running the app in 'clear' environment.
0
 
LVL 35

Expert Comment

by:girionis
ID: 6996545
 > Would it make any difference having Forte on the same machine? I'm a bit unsure of whether there could
be any conflicts somewhere.

  I would be surprised it it were making any difference. No, it should not make any difference regardless if you have Forte, JBukder, Visual Cafe or whatever else. Try to run the application from the command prompt. I have done it and I am getting exactly the same results: "Goodbye" everytime I try to close the window.

  I have never encountered a problem like this. To be able to call a class and not a method in the class without getting the NoSuchMethodException.
0
 
LVL 16

Expert Comment

by:heyhey_
ID: 6996552
it's possible that Forte (wich is java based) changes Windows events behaviour so that it can control its enviroment.
0
 

Author Comment

by:afterburner
ID: 6996824
I reinstalled Java; checked the classpath in Autoexec.bat; rebooted; recompiled, and still no "Goodbye".
Its driving me nuts. How can this happen/ The only things I ever changed were to use the file that
 "goodbye" represents, over in the Forte project. But that's not there now (I removed it, so thats OK). Furthermore,
 whenever I used the command line compiler and interpreter, the app always loaded the contents of the text file into the
Hashtable waiting for it - as it should.

But really, none of that matters here because I cant get into the windowClosing event. There must be something else
doing some listening, do you think, and grabbing that event like HeyHey mentioned, But how can Forte be doing this when it isnt running?
0
 
LVL 16

Expert Comment

by:heyhey_
ID: 6997041
> But how can Forte be doing this when it isnt running?

this may be a CLASSPATH problem - i.e. Java VM loads some Forte (or whatever) classes. But this may be even some Windows base problem - i.e. your windows GUI .DLLs have been damaged and clicking on 'x' does not generate approptiate event ...

I cannot help you without any access to your machine.
0
 

Author Comment

by:afterburner
ID: 6997078
heyhey
>I cannot help you without any access to your machine

Netmeeting?
0
 
LVL 35

Expert Comment

by:girionis
ID: 6997082
 Try to run the same source code on one of your colleague's/friend's computer and see what happens. Also if you have access to a Unix/Linux box try it as well.
0
 

Author Comment

by:afterburner
ID: 6997731
Well we alreaady saw that it works because you ran it yourself and so did heyhey and I am not sure that the symptoms that I have experienced on my machine will be reproducible on another which has not had the gubbins on it that this one has.

Does any idea spring to mind of process(es) running that could intercept the windowClosing event. For example, could a maverick applet that was (in)advertently picked up on the web, be responsible for this? I have noticed that some pop-up windows often refuse to go away before you have bought something, even when crushed repeatedly, and some scripts in web pages fall over with runtime errors, but seem undaunted by this and carry on regardless. Can they leave half-dead "calls" lying around somehow? Bring back the abacus.
0
 
LVL 16

Expert Comment

by:heyhey_
ID: 6998254
get AdAware from http://www.lsfileserv.com/ and see if it detects something unusuall on your machine.
0
 

Expert Comment

by:kamaljeets
ID: 6998459
how r u trying to close the application window,
is it tht u click on the close(X) button on the right hand corner to close the window(in this case the event should be fired), but if u try some other way then the event may not be getting fired.
-kjs
0
 

Author Comment

by:afterburner
ID: 6998579
>how r u trying to close the application window,

Am always closing it with the "x" button. I also tried it with the Close option from the menu. Dozens and dozens of times.

There is no way that the windowClosing event is being called at all, otherwise it would print "Goodbye". There must be an object somewhere back up the tree that is taking the event, but how can that happen. Anyone out there got Netmeeting can take a look on my machine if they wish.
0
 
LVL 16

Expert Comment

by:heyhey_
ID: 6998667
can you install VNC server ?
0
 

Author Comment

by:afterburner
ID: 6998852
heyhey

whats that? If I can,I will.
0
 
LVL 16

Expert Comment

by:heyhey_
ID: 6998914
OpenSource tool for accessing remote desktops (like PCAnywhere)

you can download it from

http://www.uk.research.att.com/vnc/download.html
0
 

Author Comment

by:afterburner
ID: 6999164
heyhey

right ive got vnc now. cant make head or tail of it; can you kindly bullet what i need to aim at?

thnx
aftrbrnr
0
 
LVL 16

Expert Comment

by:heyhey_
ID: 6999175
I wanted to see the situation on your desktop, but I am leaving the office in 10 minutes.

we can probably arrange something for tomorrow - e-mail me at heyhey_@iname.com.
0
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 
LVL 16

Expert Comment

by:heyhey_
ID: 7007814
after some investigations we found that this is a CLASSPATH error - EmptyFrame was in fact extending some other class named Frame (not java.awt.Frame), which was blocking some events.

0
 
LVL 16

Accepted Solution

by:
heyhey_ earned 140 total points
ID: 7007817
so it's time for answer :)
0
 
LVL 35

Expert Comment

by:girionis
ID: 7007942
>  after some investigations we found that this is a CLASSPATH error - EmptyFrame was in fact extending
> some other class named Frame (not java.awt.Frame), which was blocking some events.

  Interesting...
0
 
LVL 16

Expert Comment

by:heyhey_
ID: 7007966
I had VNC access to afterburner's machine - after cleaning the PATH and CLASSPATH variables and recompiling the .java file, everything was ok. I didn't have time to search for Frame.java file (connection was very, very slow)
0
 

Author Comment

by:afterburner
ID: 7008627
Hi;

This is difficult.

First, I am going to give the points to heyhey because he spent a long time on my PC remotely troubleshooting this. However, the problem has not gone away, and I do not know how to say this without giving offence where no offence is meant, because Heyhey is a superb expert.

But what I now have is that the EmptyFrame programme still does not work. The app that EmptyFrame was boiled-down to illustrate however DOES work; but only after I deleted a file called Frame.class from the compile directory, and then recompiled the app. That file called Frame.class was, I am sure, never there in the early days when I first made the app, and when it "wrote out" Goodbye correctly. I am pretty sure that the Frame.class file (and also one called Frame$1.class) only appeared after I installed Forte Java. The reason that I installed Forte was to give the app a better chance of life than simply constructing it over in a non-IDE environment where it worked fine. I left that old environment where it was, and used it to prototype the odd new method or change to the programme, before I would attempt to transfer the ideas over to the Forte IDE.

I did not make any changes to the Path or Classpath variables myself at any time. The old IDE was an installation that came on CD from the UK Open University on CD ROM. Forte obviously was installed somewhere else on my PC, but should have taken care of its own path and classpaths (IMHO).

Here is my path:
SET Path=C:\;C:\gbjunk;C\WINDOWS;C:\MYDOCU~2\M874\Java\bin;C:\MYDOCU~2\M874\M874Software;C:\MYDOCU~2\M874\M874Programs;"C:\MYDOCU~2\M874\Java\bin";

and classpath:

SET CLASSPATH=C:\MYDOCU~2\M874\Java\bin;c:\gbjunk;C:\MYDOCU~2\M874\M874Software;C:\MYDOCU~2\M874\M874Programs


I dont see any reference for Forte to hang on to here, but I do know that if I do not point to these directories then the old IDE obviously dont work.

I dont know what the path and classpath were changed to by heyhey. But If the windowClosing event works on my real app, and not on the EmptyFrame, what is happening? In FOrte, when I try the same sort of Goodbye write to disk I get a NullPOinterException every time.

I need to solve this fundamental prolem before I can be really sure that I have found the answer.

0
 
LVL 16

Expert Comment

by:heyhey_
ID: 7010387
> But If the windowClosing event works on my real app, and not on the EmptyFrame, what is happening?

I would like to see this.

change the class declaration to

public class EmptyFrame extends java.awt.Frame


0
 

Author Comment

by:afterburner
ID: 7010457
Heyhey

Yep, that works. Now it prints Goodbye, but the app window will not close.

Aftrbrn
0
 
LVL 16

Expert Comment

by:heyhey_
ID: 7010459
public void windowClosing(WindowEvent e)
{
System.out.println("Goodbye");

}
0
 
LVL 16

Expert Comment

by:heyhey_
ID: 7010460
you have to call System.exit() yourself

public void windowClosing(WindowEvent e)
{
  System.out.println("Goodbye");
  System.exit(0);
}
0
 

Author Comment

by:afterburner
ID: 7010655
heyhey

System.exit(0);

Yeah, that was really stupid of me.
0
 

Author Comment

by:afterburner
ID: 7010661
Heyhey:

Many thanks.

If you have an idea of why EmptyFrame was using Frame.class, what Frame.class is, and how this can interpose itself as java.awt.Frame, I would be really interested to know, because either something is wrong still on my machine, or I am not up to speed with how something involved in generation of class files is meant to work.

Best regards

afterburner.
0
 
LVL 16

Expert Comment

by:heyhey_
ID: 7013181
let's take this class definition

import java.awt.*;
import com.mypackage.*;

public class MyFrame extends Frame
{
}

if you have following three classes in the classpath

java.awt.Frame.class
com.mypackage.Frame.class
Frame.class

compiling MyFrame.java will result in MyFrame.class extends Frame.class
if you delete Frame.class and and complie MyFrame.java compiler dislays error. pretty strange on first glance, but I suppose that Java Language definition defines precisely this behaviour.
0
 
LVL 35

Expert Comment

by:girionis
ID: 7013207
> if you delete Frame.class and and complie MyFrame.java compiler dislays error

  I guess it is the same when you are importing the java.util.Date and java.sql.Date. The Java compiler throws an "ambiguous class" error.
0
 

Author Comment

by:afterburner
ID: 7013245
Thanks all;

Maybe I will return to this in another question one day as I cant still understand where Frame.class comes from, and assume that if it comes from Java that it shouldnt have been mixed up with awt.Frame Anyway thanks for all the help!

Aftrb.
0
 
LVL 16

Expert Comment

by:heyhey_
ID: 7013385
yes, the stange thing is that when you have additional class named Frame.class error is not displayed
0
 
LVL 35

Expert Comment

by:girionis
ID: 7013417
 I guess when a class with the same name as another one is in the same package then the Java compiler does not display any error message, since by default is loading the class in the same package first.
0
 

Author Comment

by:afterburner
ID: 7013571
OK, but I didnt make the Frame class anytime as far as I am aware. Or is that the only way it could have happened?
0
 
LVL 16

Expert Comment

by:heyhey_
ID: 7013574
>  Or is that the only way it could have happened?

yes.

> OK, but I didnt make the Frame class anytime as far as I am aware.

I am not sure who created this Frame.class and I didn't have time to get the file and decompile it so that we can see what's inside :(
0
 

Author Comment

by:afterburner
ID: 7013585
>I am not sure who created this Frame ...

no thats fine I am not asking for that. All I want to make sure about is that that is the only way it could have happened. I need to know this because sometimes when I try things out, I use variable names that are not well thought out probably, and I have a feeling that this could have been one such case, but I cant exactly remember. But the mystery to me is why when I recompile my class as a subclass of awt.Frame, does the compile process still go and create a Frame.class and put it amongst the source files. I can understand it would do it first time if I had subclassed Frame.class, but after I changed it to subclass awt.Frame ... ???

0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Suggested Solutions

Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now