Problem with WindowAdapter, why doesnt this work ?

Hi
I have created a source file with the following code:
import java.awt.* ;
import java.awt.event.* ;
import javax.swing.* ;
public class EventDemo3 extends JFrame
     EventDemo3()
          // Setter tittel, st�rrelse og gj�r det synlig
          setTitle("EventDemo3 - lukking av vindu") ;
          this.addWindowListener(new WindowAdapter() {
               public void windowClosed(WindowEvent e)
                    System.exit(0) ;
          setSize(300, 300) ;
          setVisible(true) ;
     public static void main(String[] args)
          new EventDemo3() ;
}It compiles and runs, but when i close the window the JVM is still running and i cant figure out why, does someone know why this doesnt work ?
Message was edited by:
icebyte

Perhaps you want this instead:
import java.awt.* ;
import java.awt.event.* ;
import javax.swing.* ;
public class EventDemo3 extends JFrame
     EventDemo3()
          // Setter tittel, st�rrelse og gj�r det synlig
          setTitle("EventDemo3 - lukking av vindu") ;
          this.addWindowListener(new WindowAdapter() {
                        @Override
               public void windowClosing(WindowEvent e)
                    System.exit(0) ;
          setSize(300, 300) ;
          setVisible(true) ;
     public static void main(String[] args)
          new EventDemo3() ;
}

Similar Messages

  • Why doesnt this work, its so simple

    The following piece of code I guess should print "THEY ARE EQUAL" but it doesnt. I dont know why???????????? anybody help.
    String check = new String("new���".getBytes("iso-8859-1"), "iso-8859-1");
    for(int i =0 ; i< check.length(); i++)
    if(check.charAt(i)=='���') System.out.println("THEY ARE EQUAL");
    }

    You aren't comparing whether the two strings contain
    the same data, you are comparing whether the two
    references point to the same objects. Try it again
    using the .equals() method to compare the contents of
    the two strings instead of using ==.For the first time in my life have I seen DrClap err. So he is human too. amit234 is comparing characters and not Strings
    I found the solution to your problem your the corresponding line in your code with this one and it would work
    if(check.charAt(i)=='\u20AC') System.out.println("THEY ARE EQUAL");
    happy coding

  • Problem with File.copy() -- should this work?

    I'm trying to copy a number of script files (I'm testing with just one) out of one folder into another. Here's the code:
    (function() {
      var myFolder = Folder(getScriptPath().parent + "/disabled");
      if (myFolder.exists) {
        var myScripts = myFolder.getFiles("*.jsx");
          for (var j = 0; myScripts.length > j; j++) {
          if (myScripts[j].copy("../enabled")) {
            myScripts[j].remove();
      function getScriptPath() {
        // This function returns the path to the active script, even when running ESTK
        try {
          return app.activeScript;
        } catch(e) {
          return File(e.fileName);
      } // end getScriptPath
    What's happening is that the file in the disabled folder is simply being deleted. This means that the copy method is returning true and yet the copy didn't happen. Perhaps my URI is wrong, but if so, the copy should have failed. The file is not in either the InDesign or ESTK packages, which seem to be the only two worth looking in -- I was running from ESTK with InDesign CS4 targeted.
    Dave

    You can set the current folder like this:
    Folder.current = "/d/test1/test2"
    Then change to that current folder's parent using
    Folder.current = ".."
    But you can't use .. in file masks. This won't work:
    var myFiles = Folder.cuttent.getFiles ("../*.jsx")
    The only way of using .. (as far as I can see) is with literal filenames:
    myFile = '../nonsense.txt'
    which points to nonsense.txt in current folder's parent folder. But this is unclear as you dont't have a reference to the current folder in your statement. I agree that using relative file paths is vague and it looks as if they're best avoided.
    Why copy() returns true when in fact it hasn't worked looks like a bug. I've tried it a couple of times and on Windows it gives the same results as with you: copy() says true when nothing's happened.
    Peter

  • Why doesnt this work??

    Hi All,
    Im tryin to design a website to take an image out of the database and display it on the jsp page.
    I call the image using:
    <img src="ImageServlet?id=3" width="250" height="250" align="top">
    This calls the servlet that displays the image. The first time i call this the image is displayed. I dont store the image in the session.
    My problem is when i click a link to another page and then come back to the original page the image doesnt display. If i refresh the page it wont display. It will display when i manually right click the image and show the picture.
    What could be the cause of this. The image is their it just wont display the second time the page is called.
    Thanks for any help in advance.

    I changed the way the servlet handled the image and got it to print any error instead of throwing them. This is what is coming up.
    java.io.IOException: Stream closed
    at java.io.BufferedInputStream.ensureOpen(BufferedInputStream.java:120)
    at java.io.BufferedInputStream.available(BufferedInputStream.java:336)
    at ImageServlet.doGet(ImageServlet.java:36)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:740)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(Appl
    icationFilterChain.java:247)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationF
    ilterChain.java:193)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperV
    alve.java:260)
    at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContex
    t.invokeNext(StandardPipeline.java:643)
    at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.jav
    a:480)
    at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextV
    alve.java:191)
    at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContex
    t.invokeNext(StandardPipeline.java:643)
    at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.jav
    a:480)
    at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
    at org.apache.catalina.core.StandardContext.invoke(StandardContext.java:
    2396)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.j
    ava:180)
    at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContex
    t.invokeNext(StandardPipeline.java:643)
    at org.apache.catalina.valves.ErrorDispatcherValve.invoke(ErrorDispatche
    rValve.java:170)
    at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContex
    t.invokeNext(StandardPipeline.java:641)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.j
    ava:172)
    at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContex
    t.invokeNext(StandardPipeline.java:641)
    at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.jav
    a:480)
    at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineVal
    ve.java:174)
    at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContex
    t.invokeNext(StandardPipeline.java:643)
    at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.jav
    a:480)
    at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
    at org.apache.coyote.tomcat4.CoyoteAdapter.service(CoyoteAdapter.java:22
    3)
    at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java
    :405)
    at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.proce
    ssConnection(Http11Protocol.java:380)
    at org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java
    :508)
    at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadP
    ool.java:533)
    at java.lang.Thread.run(Thread.java:536)
    This is the servlet that generates the error.
    import javax.servlet.*;
    import javax.servlet.http.*;
    import ProductDetails.*;
    import java.io.*;
    import java.util.*;
    import java.awt.image.*;
    public class ImageServlet extends HttpServlet {
    public void init(ServletConfig config) throws ServletException {
    public void destroy() {
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, java.io.IOException {
    try
    HttpSession session = request.getSession(false);
    Product p = (Product) session.getAttribute("prod"+request.getParameter("id")+"");
    int i = p.getID();
    //if( i == Integer.parseInt(request.getParameter("id")) )
    InputStream in = p.getImage();
    response.setContentType("image/jpg"); // or whatever type of file it is.
    response.setHeader("Cache-Control","no-cache");
    response.setHeader("Expires", "0");
    response.setHeader("Pragma", "No-cache");
    response.addHeader("Cache-control", "no-store"); // tell proxy not to cache
    response.addHeader("Cache-control", "max-age=0"); // stale right away
    ServletOutputStream sout = response.getOutputStream();
    int c;
    int b = in.available();
    while((c = in.read()) != -1)
    sout.write(c);
    int imad = 0;
    System.out.println("Image called. "+ imad + " Available: " + b);
    in.close();
    in = null;
    sout.flush();
    sout.close();
    return;
    catch (Exception e)
    e.printStackTrace();
    throw new ServletException(e);
    protected void doPost(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, java.io.IOException {
    doGet(request, response);
    Product stores an Inputstream that is gotten from the database.

  • Map map = new HashMap(); -why doesnt this work in jdk 1.8.1

    Hi there,
    I'm trying to use a hashmap like this below:
    Map map = new HashMap();
    map.put("Carrots", new Integer(12));
    map.put("Potatoes", new Integer(30));
    map.put("Onions", new Integer(15));
    map.put("Apples", new Integer(40));
    map.put("Cherries", new Integer(300));
    the HashMap() does not exist in my API for some reason.
    Can anyone tell me why this may be?
    i'm using the hashmap with a stringtokenizer to search a text file line by line and increment how many times each keyword occurs.Sound efficient way of doing it?
    cheers,

    do you mean jdk 1.1.8?
    Map and the other Collections API were added in JDK 1.2. for JDK < 1.2, use Hashtable instead.

  • Why doesnt this work ( 10 line program ) ?

    import java.lang.Math;
    public class DeckTester{
         public static void main ( String[] args ){
              Deck threeOfClubs = new Deck (0, 3);
              System.out.println( threeOfClubs.suit );
              System.out.println( threeOfClubs.rank );
    class Deck
    int suit, rank;
    public Card () {
    this.suit = 0; this.rank = 0;
    public Card (int suit, int rank) {
    this.suit = suit; this.rank = rank;
    It tells me i need a return statement or something but i dont really think that is my problem. Bascially i am jsut trying to figure out how to make an object, put data int, then take out the data and print it.
    Any help appreciated. And please dont tell me "go look at tutorials" like people did last time because that doesn help. thanks

    Just have one more question for people that also know
    VB: Is useing an object to store data just like a user
    defined data type in VB?Repeat after me: Objects are not used to store data, they are used to organize related information in a meaningful way, and to represent real-life or abstract things. In this case, your object has a suit and a rank, which implies it a playing card, so your class should be called Card (not Deck!).

  • Hi! I am having a problem with my dictation. It works fine with Greek but it does not work at all with English. Anyone knows why?

    hi! I am having a problem with my dictation. It works fine with Greek but it does not work at all with English. Anyone knows why?

    Have you changed the system voice to an English one in system preferences?

  • I updated my browser to the last versoin of firefox (31). But I have a problem with mozilla. why tha toolbar of alexa does not work on it?

    Hello...
    I updated my browser to the last versoin of firefox (31). But I have a problem with mozilla. why tha toolbar of alexa does not work on it?

    After a quick search in the addon.mozilla.org page, it looks like that add on is still compatible with version 31. Please try to [[Re-enable add-ons that were disabled when updating Firefox]] or make a back up of the add on folder in the profile folder and reinstall the add on. [[Back up and restore information in Firefox profiles]]

  • Hi, I have a problem with getting my apple Id working for me. It's been 2 months since it happened and Apple failed to act. I can tell my story proerly, but am not sure, you guys can help, so I just copy my message to them today, I am trying to get it acr

    Hi, I have a problem with getting my apple Id working for me. It's been 2 months since it happened and Apple failed to act. I can tell my story proerly, but am not sure, you guys can help, so I just copy my message to them today, I am trying to get it across all the places around to pay their attention. This is a desperate move, so if you are not the right people to help me to get my message accross, may be you can advise where can I go.
    Thank you, and sorry for the language.
    Vitas Dijokas
    I am sorry to say that, but your security makes my life miserable – it’s been 2 months since my Apple ID account got stuck, and since then I cannot update 37 applications (to date), i.e. most of my applications. Half of them I bought. I also paid for iCloud, and it is not working. I paid money and I am stuck with old applications and no iCloud. Your security *****. Your service ***** too. It took your service 1 month to finally understand why this happened to me, and it took me tens of emails to you and 3 hours of telephone conversation to find out the reason for my problem. And the problem is still not fixed. NOT FIXED. You just leave your customer – the one who paid you money and spent so much time with you trying to help you help me – and nothing. You tell me:  “Vitas, Stick your stinky iphone in your *** and enjoy life, we do not care!” *************.
    It is ******* outrageous, and you should know that,  guys. Get into the ******* database and correct the bug. Get someone in the partners-telephone carriers company (it is Orange as carreer and Cellcom as seller of the phone)  authorized to Identify me in personal encounter in one of the branches in Israel (where I live) and make sure it is really me, and get the ******* system accept my password and let me use my phone.
    Otherwise **** off. None of my friends will get my advise to buy an iphone or any of apple products. And I think you should be very attentive to cases like this, guys. Do your work for the money we pay, or disappear. There are many others eager to take your place, and if the problem is not fixed I will eventually go to the others. My patience is lost, and as soon as I can afford another phone I will change it. AND I WILL TRY TO GIVE BAAAAAD PUBLICITY TO APPLE – I am threatening here, so ACT NOW.
    Vitas Dijokas

    Well, it seems waiting is not my strong suit..! I renamed a javascript file called recovery to sessionstore. This file was in the folder sessionstore-backups I had copied from mozilla 3 days ago, when my tabs were still in place. I replaced the sessionstore in mozilla's default folder with the renamed file and then started mozilla. And the tabs reappeared as they were 3 days ago!
    So there goes the tab problem. But again when I started mozilla the window saying "a script has stopped responding" appeared, this time the script being: chrome//browser/contenttabbrowser.xml2542
    If someone knows how to fix this and make firefox launch normally, please reply! Thank you

  • Why isnt this working urgent please help

    why isnt this working im trying to connect a panel to a scrollpane the panel will contain several dozen text fields
    the scrollpane shouls be about 350, 450 , but the pane is 350
    by 1200 the problem now is that the scorllbar isnt created and even when I explictly create it it contains no knob, and it will
    not scroll up or down please someone help this is urgent
    import java.awt.*;
    import com.sun.java.swing.*;
    public class ScrollDemo extends JPanel {
         private Rule columnView;
         private Rule rowView;
         private ScrollablePicture picture;
         class UnitsListener implements ItemListener {
              public void itemStateChanged(ItemEvent e) {
                   if (e.getStateChange() == ItemEvent.SELECTED) {
                        // Turn it to metric.
                        rowView.setIsMetric(true);
                        columnView.setIsMetric(true);
                   } else {
                        // Turn it to inches.
                        rowView.setIsMetric(false);
                        columnView.setIsMetric(false);
                   picture.setMaxUnitIncrement(rowView.getIncrement());
    public ScrollDemo() {
         Two t = new Two(columnView.getIncrement());
              JScrollPane pictureScrollPane = new JScrollPane(t);
              pictureScrollPane.setPreferredSize(new Dimension(300, 250));
              pictureScrollPane.setColumnHeaderView(columnView);
              pictureScrollPane.setRowHeaderView(rowView);
         public static void main(String s[]) {
              JFrame frame = new JFrame("ScrollDemo");
              frame.setContentPane(new ScrollDemo());
              frame.setVisible(true);
    import java.awt.*;
    import com.sun.java.swing.*;
    public class Two extends JPanel implements Scrollable{
    private JPanel ivjJPanel3 = null;
         private JScrollPane ivjJScrollPane1 = null;
         private int maxUnitIncrement = 1;
    public Two(int m)
         getJPanel1();
         maxUnitIncrement = m;
         setSize(300,1200);
    private void getJPanel1() {
                   setLayout(null);
                   setSize(250,1200);
                   add(getJLabel1(), getJLabel1().getName());
    public Dimension getPreferredScrollableViewportSize() {
              return getPreferredSize();
         public int getScrollableBlockIncrement(Rectangle visibleRect, int orientation,
         int direction) {
              if (orientation == SwingConstants.HORIZONTAL)
                   return visibleRect.width - maxUnitIncrement;
              else
                   return visibleRect.height - maxUnitIncrement;
         public boolean getScrollableTracksViewportHeight() {
              return false;
         public boolean getScrollableTracksViewportWidth() {
              return false;
         public int getScrollableUnitIncrement(Rectangle visibleRect,
                                                      int orientation,
                                                      int direction) {
              //Get the current position.
              int currentPosition = 0;
              if (orientation == SwingConstants.HORIZONTAL)
                   currentPosition = visibleRect.x;
              else
                   currentPosition = visibleRect.y;
              //Return the number of pixels between currentPosition
              //and the nearest tick mark in the indicated direction.
              if (direction < 0) {
                   int newPosition = currentPosition -
                                       (currentPosition / maxUnitIncrement) *
                                       maxUnitIncrement;
                   return (newPosition == 0) ? maxUnitIncrement : newPosition;
              } else {
                   return ((currentPosition / maxUnitIncrement) + 1) *
                        maxUnitIncrement - currentPosition;
         public void setMaxUnitIncrement(int pixels) {
              maxUnitIncrement = pixels;

    I personally didn't play with swing components when they were in the com.sun.java.swing state, but I have a strong feeling it is very buggy and could be causing your problem.
    Before posting gui issues, please use a newer API, even jdk1.1 would be fine, anything would be better than what your using.
    you wrote: I dont care if its javax.swing or
    com.sun.java.swing
    I would also gather from this statement that your attitude could be one of your other issues.

  • Skype 6.11- I was thinking of downloading Maverick, but I am seeing that Skype is having problems with it. Is this still true. I am on snow leopard 10.6.8 now

    I was thinking of downloading Maverick, but I am seeing that Skype is having problems with it. Is this still true. I am on snow leopard 10.6.8 now

    Hi,
    I'm using Mavericks and there are no issues with SKYPE.
    I using SKYPE 6.9 and this version is working well without issue.
    For some reason I didn't downloaded SKYPE 6.11 I don't know why anymore ... but I'm sure I hat my reasons not to do so.
    Dimaxum

  • Just moved my email from entourage to Mail. Having real problems with getting my signatures to work properly. When adding in a small company logo, windows computers only receive signature as an attachment. Am sending email as Rich Text. Any ideas on a fix

    Just moved my email from Entourage to Mail. Having real problems with getting my signatures to work properly despite sending email as Rich Text.
    When adding in a small company logo to the signature, PC's / windows computers only receive signature and logo as attachments.
    I've tried all possible fixes I can find including getting a PC user to format the logo but no joy. Has anyone experienced this and any ideas on a fix gratefully received.

    Send it as html so the signature is an image source URL

  • Problem with *serial no. profile* in work sheduling view of material master

    Hi ! !
    I am here with a problem with serial no. profile in work sheduling view of material master.
    By mistake for some FHMI type ( PRODUCTION RESOURCE TOOLS )materials, serial no profile exist in 'work sheduling' view. Due to that we are facing problem in GRN.
    when I am trying to remove that with MM02. i m getting a message as Serial numbers already assigned to this material
    Please suggest how to remove serial no. profile.
    Thanks in advance,
    Prab

    Hi,
    go to MMBE and check the Current Serial number...for  FHMI type
    and go to IQ02 and close the Serial number range at the Current number range...
    Now you can assign this serial number range to another material type...
    Thx
    Raju

  • I have a problem with my iPhone 5 stopped working the sleep / power and simultaneously refused to obey the HOME button. I can not use either one or the other. I can not enable or disable the device, display lights up when you plug the charger. same displa

    I have a problem with my iPhone 5 stopped working the sleep / power and simultaneously refused to obey the HOME button. I can not use either one or the other. I can not enable or disable the device, display lights up when you plug the charger. same display works fine as it is surprising. or maybe someone knows what is the reason for this? is there any way to solve this problem?

    More than likely its a hardware issue, I have never encountered such a problem and best bet is to just go get it replaced. If you have insurance on your device apple will replace it as long as there was no water damage, if you dont have insurance they will charge $200 more or less. Hope you get it fixed

  • Problem with Silverlight 5, version 4 worked great on my IMAC.

    Problem with Silverlight 5, version 4 worked great on my IMAC.  Since I updated all my movies shutter or they stop to refresh.  No one from Netflix or Microsoft can solve this problem.  Please advise if there is a fix, maybe drop the silverlight plugin and contract with Flash Player plugin it works with everything.
    Please don't advise me to uninstall and re-install the silverlight plugin I wrote a paper on un-installinging this plugin.
    Please advise, I know there is an army of frusrated Netfix members out there.

    The solution is to download and install the latest version of Flip4Mac, which now includes a Silverlight component:
    http://dynamic.telestream.net/downloads/download-flip4macwmv.htm
    But the latest news is that Microsoft will probably abandon Silverlight in favour of HTML5:
    http://www.appleinsider.com/articles/10/10/29/apples_ios_pushes_microsoft_to_dia l_down_silverlight_for_html5.html  and
    http://www.bbc.co.uk/news/technology-11673384
    If you want to remove Silverlight the instructions are here:
    http://support.microsoft.com/kb/970064

Maybe you are looking for

  • ITunes Wont Update My iPod Touch Or iPad.

    When I try to restore or update my iPad or iPod touch, iTunes tells me it can't connect to the server. Anyway of fixing this?

  • Cant find printer driver for CANON E510. Anyone can help me?

    Good day everyone. i am new user for Mac's family. I have google and find driver for printer CANON E510 and wish to install in my Mac. Unfortunately I unable to find it. I have try a the link based on search. However it does not fit to OS 10.9.5. Any

  • Error in the iTunes Store

    This needs a new thread. I am another Windows XP user who, after trying all manner of diagnostics & checks, has determined that the Apple Store is on the fritz. I have not been able to download & now the iTunes store is completely unavailable to me (

  • Synchronizing on an int shouldn't be necessairy, should it?

    The following example consists of 2 threads that both increment a static int by 1 and decrement it by 1. Both threads are stopped abruptly after half a second. What i don't understand is why there are other results possible than 0, 1 or 2. Synchroniz

  • Aperture not creating previews - one reason

    I've been investigating why Aperture is failing to create previews. In my system it will only create previews for a specific set of images and not matter what I do it's always the same images. So I looked at the difference between the images it would