Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 194
  • Last Modified:

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

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
afterburner
Asked:
afterburner
  • 17
  • 14
  • 6
  • +1
1 Solution
 
heyhey_Commented:
on my system it prints

HEY
Hi again
Goodbye
0
 
girionisCommented:
 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
 
afterburnerAuthor Commented:
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
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 
heyhey_Commented:
maybe your CLASSPATH got messed. try running the app in 'clear' environment.
0
 
girionisCommented:
 > 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
 
heyhey_Commented:
it's possible that Forte (wich is java based) changes Windows events behaviour so that it can control its enviroment.
0
 
afterburnerAuthor Commented:
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
 
heyhey_Commented:
> 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
 
afterburnerAuthor Commented:
heyhey
>I cannot help you without any access to your machine

Netmeeting?
0
 
girionisCommented:
 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
 
afterburnerAuthor Commented:
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
 
heyhey_Commented:
get AdAware from http://www.lsfileserv.com/ and see if it detects something unusuall on your machine.
0
 
kamaljeetsCommented:
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
 
afterburnerAuthor Commented:
>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
 
heyhey_Commented:
can you install VNC server ?
0
 
afterburnerAuthor Commented:
heyhey

whats that? If I can,I will.
0
 
heyhey_Commented:
OpenSource tool for accessing remote desktops (like PCAnywhere)

you can download it from

http://www.uk.research.att.com/vnc/download.html
0
 
afterburnerAuthor Commented:
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
 
heyhey_Commented:
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
 
heyhey_Commented:
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
 
heyhey_Commented:
so it's time for answer :)
0
 
girionisCommented:
>  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
 
heyhey_Commented:
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
 
afterburnerAuthor Commented:
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
 
heyhey_Commented:
> 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
 
afterburnerAuthor Commented:
Heyhey

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

Aftrbrn
0
 
heyhey_Commented:
public void windowClosing(WindowEvent e)
{
System.out.println("Goodbye");

}
0
 
heyhey_Commented:
you have to call System.exit() yourself

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

System.exit(0);

Yeah, that was really stupid of me.
0
 
afterburnerAuthor Commented:
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
 
heyhey_Commented:
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
 
girionisCommented:
> 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
 
afterburnerAuthor Commented:
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
 
heyhey_Commented:
yes, the stange thing is that when you have additional class named Frame.class error is not displayed
0
 
girionisCommented:
 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
 
afterburnerAuthor Commented:
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
 
heyhey_Commented:
>  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
 
afterburnerAuthor Commented:
>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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 17
  • 14
  • 6
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now