Why the code doesn't work???

addWindowListener(new WindowAdapter(){public void windowClosing(){System.exit(0);}});
when I press the x button ,it doesn't work as expected!!

What are you expecting it to do? I should close the window and then exit the application. This is the code I use for all my applications and it does exactally that. Are you using it with a JFrame? or a JDialog?
JFrame test = new JFrame();
test.addWindowListener(new WindowAdapter() {
            public void windowClosing(WindowEvent evt) {
                System.exit(0);

Similar Messages

  • How to use documentbeforesaved method? And why my code doesn't work in template files?

    Can someone help me with these two codes?
    ----Beginning of code 1-------------
    Private WithEvents App As Word.Application
    Private Sub Document_Open()
    Set App = Word.Application
    End Sub
    Private Sub App_DocumentBeforeSave(ByVal Doc As Document, SaveAsUI As Boolean, Cancel As Boolean)
    MsgBox("BeforeSave")
    End Sub
    --------------End of the code----------------
    Beginning of code 2--------------- Code 2 is from https://msdn.microsoft.com/en-us/library/office/ff838299(v=office.15).aspx
    Public WithEvents appWord as Word.Application 
    Private Sub appWord_DocumentBeforeSave _ 
     (ByVal Doc As Document, _ 
     SaveAsUI As Boolean, _ 
     Cancel As Boolean) 
     Dim intResponse As Integer 
    Private Sub App_DocumentBeforeSave(ByVal Doc As Document, SaveAsUI As Boolean, Cancel As Boolean)
    MsgBox("BeforeSave")
    End Sub
    In the first code, they have:
    Private Sub Document_Open()
    Set App = Word.Application
    End Sub
     I test these two codes in "This document" object, and I find out the first code works but the second code are not!
    Why second code doesn't work?
    Extra question: I am using microsoft 2013. I insert this code into a macro-enabled template. But when I am about to save my file I am expecting these code works. However, they didn't work!
    Thank you for solving these problem for me!

    Hello,
    Please note that the code snippet 2 in your post is different from the code snippet in the MSDN document. Also please read the comments of the MSDN code sample:
    This example prompts the user for a   yes or no response before saving any document.
    This code must be placed in a   class module, and an instance of the class must be correctly initialized to   see this example work; see
    Using Events with the Application Object for   directions on how to accomplish this.
    Public WithEvents appWord   as Word.Application
    Private Sub   appWord_DocumentBeforeSave _
     (ByVal Doc As Document, _
     SaveAsUI As Boolean, _
     Cancel As Boolean)
     Dim intResponse As Integer
     intResponse = MsgBox("Do you really   want to " _
     & "save the document?", _
     vbYesNo)
     If intResponse = vbNo Then Cancel = True
    End Sub
    So the problem in your code snippet 2 is that you didn't put it into a class module and initialize the class module. If you just put it into ThisDocument, you have to initialize the word application object.
    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click
    HERE to participate the survey.

  • Why the preloader doesn't work in IE 8 but works in FireFox?

    Why the preloader doesn't work in IE 8 but works in FireFox?
    Please see the attached files.  Thanks in advance.

    Why doesn't the preloader work in IE8?
    What's "virtual sandbox"?

  • Why the imsg doesn't work without a sim card with iOS 7???

    Why the imsg doesn't work without a sim card with iOS 7???

    If it worked for you using iOS 6, then it appears iOS 7 has made some changes.  Was it working before?

  • Hi there, i have a ipod nano general 7, just used one year. Now can't charge battery. When charging, the icon shows full power, but disconnect it. It becomes dark, no power. Why, the battery doesn't work ?

    I've a ipod nano general 7, I've just used it one year. Now, I can't charge the battery. When charging, the icon shows full power. But when I disconnect, the ipod becomes dark, no power is keeped. Why, the battery doesn't work ? the life of my ipod's battery is too short ? 

    Howdy tamsg,
    Welcome to Apple Support Communities.
    The article linked below provides a lot of great troubleshooting tips that can help you resolve the issue with your iPod nano charging or displaying a blank black screen.
    iPod nano (7th generation): Hardware troubleshooting - Apple Support
    So long,
    -Jason

  • Why the style doesn't work?

    It's my very second test using Flex.
    quote:
    <mx:Application ...>
    <mx:Style>
    Text{
    backgroundColor:#FFFFFF;
    </mx:Style>
    <mx:HBox>
    <mx:Text />
    </mx:HBox> ...
    </mx:Application>
    This code doesn't work. I'd like to set my text control's
    background to white. Why is it wrong?
    Thanks.

    Because mx:Text does not have a backgroundColor
    style/property.
    Tracy

  • Why the wifi doesn't work after the upgrade to iOS 5?

    The problem is that after the upgrade to iOS 5 the wifi doesn't work. I mean, iPad is connected to the wifi but not to the internet and also the connection on the other device doesn't work. So I had to turn off the router and then turn it on.

    Try a hard reset first to see if that does any good.  To do this, press and hold both the Sleep/Wake and Home buttons together long enough for the Apple logo to appear.
    If no luck with that, you'll need to manually connect your iPod to your iTUnes library in recovery mode using the instructions in the Apple support document below. Doing so will allow you to bypass the passcode and restore the iPod.
    iOS: Unable to update or restore
    B-rock

  • Who knows why the "repaint()"doesn't work when ....?

    I use a "while(threadgroup.activeCount()!=0){} "to block the sentence below
    from being excecuted before I finish the thread above, however since this "while"
    the repaint() in the thread above doesn't work , but I have evidence that the thread
    is really going on ( I use Sytem.out.print() to prove this)

    I'm not sure I follow. Try providing a snippet of the relevant code, and we'll see if anybody on the forum can figure it out for you.

  • Bug in Adobe Flash ? The code doesn't work if I add a symbol

    Hi,
    Here's my code :
      import flash.text.TextField;
    qtte_t1.addEventListener(Event.CHANGE,changeHandler);
    qtte_t2.addEventListener(Event.CHANGE,changeHandler);
    qtte_t3.addEventListener(Event.CHANGE,changeHandler);
    qtte_t4.addEventListener(Event.CHANGE,changeHandler);
    qtte_t5.addEventListener(Event.CHANGE,changeHandler);
    qtte_t16.addEventListener(Event.CHANGE,changeHandler);
      function changeHandler(event:Event):void
      calculatePayCheck();
      function calculatePayCheck():void{
      var tome1:Number = 0;
      var tome2:Number = 0;
      var tome3:Number = 0;
      var tome4:Number = 0;
      var tome5:Number = 0;
      var tome16:Number = 0;
      var global:Number = 0;
      tome1 = Number(qtte_t1.text);
      tome2 = Number(qtte_t2.text);
      tome3 = Number(qtte_t3.text);
      tome4 = Number(qtte_t4.text);
      tome5 = Number(qtte_t5.text);
      tome16 = Number(qtte_t16.text);
      tome17 = Number(qtte_t17.text);
      tome18 = Number(qtte_t18.text);
      tome19 = Number(qtte_t19.text);
      tome20 = Number(qtte_t20.text);
      tome21 = Number(qtte_t21.text);
      tome22 = Number(qtte_t22.text);
      tome23 = Number(qtte_t23.text);
      tome24 = Number(qtte_t24.text);
      global = Number(prix_global.text);
      prix_t1.text = String(Math.round(tome1*1200));
      prix_t2.text = String(Math.round(tome2*1200));
      prix_t3.text = String(Math.round(tome3*1200));
      prix_t4.text = String(Math.round(tome4*1200));
      prix_t5.text = String(Math.round(tome5*1200));
      prix_t16.text = String(Math.round(tome16*1200));
      prix_global.text = String(Math.round((tome1+tome2+tome3+tome4+tome5+tome16)*1200));
    Everything is working great, but if I add a symbol on stage the calculs are completly buggy ! (no error message but I can't add the number I want and the calculs are wrong)
    Do you know why ?
    I can't add a form, a symbol, NOTHING. just bitmap. If I'm adding something, the sums are wrong.
    Thank you,
    steph

    like i said, you showed a lot of superfluous code and incomplete code, but that by itself wouldn't cause what you describe.
    so, something other than what you indicated is happening.  i don't know what that is but i suspect you are not doing what you think you are doing.
    to debug, copy just the code you showed (or should have showed) to a new fla that contains only the needed textfields and mouse listeners and test.

  • Why the picking doesn't work

    Hi everybody:
    i am working on a java 3d demo which uses picking as the collision avoidance utility.the code below is quite simple but in fact it cant pick anything. the problem has made me crazy for quite a long time and i still not find out the correction answer.if anyone could solve this problem ,i will be very thankful~ :)
    public class TestBound extends Applet {
    BranchGroup root;
    public void createBranchGraph() {
    root = new BranchGroup();
    TransformGroup rootTG = new TransformGroup();
    rootTG.addChild(new ColorCube(0.4));
    root.addChild(rootTG);
    //root.setPickable(true);
    //root.setCapability(Node.ALLOW_BOUNDS_READ);
    //root.setCapability(Node.ENABLE_PICK_REPORTING);
    root.compile();
    public TestBound() {
    setLayout(new BorderLayout());
    Canvas3D canvas = new
    Canvas3D(SimpleUniverse.getPreferredConfiguration());
    add("Center",canvas);
    createBranchGraph();
    SimpleUniverse su = new SimpleUniverse(canvas);
    su.getViewingPlatform().setNominalViewingTransform();
    su.addBranchGraph(root);
    //System.out.println(new BoundingBoxGenerator(scene).getBounds());
    public static void main (String[] args) {
    TestBound tb = new TestBound();
    new JMainFrame (tb,256,256).setVisible(true);
    PickTool tool = new PickTool(tb.root);
    tool.setShapeRay(new Point3d(1000,0,0),new Vector3d(-1,0,0));
    System.out.println(tool.pickAny() == null);
    the picking ray should intersect with the color cube,but in fact it cant pick anything and returns null always.

    Have you tried reducing the distance to the point3d in your picktool - it looks like it is outside of the bounds for the cube. Have you looked at the picking demos that you downloaded with the j3d distribution? They are often a good starting point for picking up this kind of technique.

  • I've bought a gift card but the code doesn't work. What do I have to do now?

    Somebody told me to send an email to Apple but I don't really know how. What should I say and where can I do that? Also, what should I write? I'd go back to the store but they couldn't do abything so they threw it away. That means I don't have the code anymore. What should I do now? Help me please.
    Friendly greetings,
    J. Paalman

    See here: iTunes Store: Invalid, inactive, or illegible codes
    B-rock

  • Why the comparison doesn't work?!

    my code is:
    <text>
      <boundAttribute name="text">
       <if>
         <comparison  type="greaterThanOrEquals">
           <fixed javaType="int" text="10"/>
           <fixed javaType="int" text="8"/>
         </comparison> 
         <fixed javaType="string" >aaaa</fixed>
         <fixed javaType="string">bbbb</fixed>
       </if>
      </boundAttribute>
    </text>whenever the comparison type is "greaterThan" or "lessThan" ,the result always is bbbb.
    i use jdev10g.
    thanks.

    thanks for your answer.it does work well.
    however,i want to compare a value of pageProp and a value of bc4j:attrValue,like following:
    <text>
      <boundAttribute name = "text">
        <if>
           <comparison type="greaterThanOrEquals">
              <dataObject select="SetPayDate" source="${uix.pageProp}"/>
              <bc4j:attrValue name=DateDue"/>
           </comparison>
        <fixed javaType="string"> aaa </fixed>
        <fixed javaType="string"> bbb </fixed>
        </if>
       </boundAttribute>
    </text>
    i have ever seen that it worked well. The second day,it didn't work. :(.
    thanks.best regards.

  • Why the dispose() doesn't work

    I have these code which pop up a dialog window for adding new record to my table but after that the dialog box stay there eventhough I call the dispose() funtion for closing dialog window. How can I make it work.
    public void AddRecord()
    JButton Done;
    final int r = Postings.getRowCount();
    final UnitDiaryPosting udp = new UnitDiaryPosting(editFrame);
    Done = udp.getAction();
    Done.setText("Done");
    Done.addActionListener(new ActionListener(){
    public void actionPerformed(ActionEvent e)
    String t[] = udp.getInformation();
    mytable.addRow(t);
    mytable.fireTableRowsInserted(0,r+1);
    udp.dispose();
    }

    dispose () does not close windows! dispose () attempts to release resources held by the window. Try calling hide () or setVisible (false) before calling dispose ()

  • Why the autobrigtness doesn't work as it should, all it does is just turns brightness on 10% and that all

    When the keyboard will be improved because android has swiftkey 3 and its way better than this one

    In this line , it was returning ORA-00904 but it was fixed by using =: operator instead of = operator.
    There's no "=:" operator.
    The colon character ':' is used to defined a bind variable (placeholder) in the query string.
    The value for that variable must be passed ("bound") after parse and before execute step so that the query is executed correctly. That's what the USING clause does in your code.
    So, it works as =+  operator trick that is defined in other high programming language such as C# ...etc.
    Example:  
    int a = 0; 
    a =+ 1;    //  a was declared as an integer that has value 0 
            // then  we tried to increment by 1 or add by one 
             // so it would be  a=a+1;   
                    //which is  a=0+1; 
    Does it work the same?
    No, nothing to do with that.

  • Why the script doesn't work

    I installed solaris 8 and got a problem. I can use unix commands like ls, mkdir, cp, mv,.... But when I created a script and try to run it, I got the message says "That command doesn't exist." I check the persion and owner, they are OK. Also I use admintool to add a user, I try to put a user's home directory /usr/eric/, when I submit it, I got message "don't have permission" (I am a super user). When I exit from admintool and check /etc/passwd file, that user is already there.
    anyone response is appreciate.

    Hi,
    Is your PATH variable set to point to the directory
    which has this script ?
    Set the PATH variable and try (if itis not already set).
    Pls follow the steps below:
    o In your shell, set the environment variable PATH as:
    On Bourne/Korn shell:
    #PATH=/usr/bin:/usr/sbin:.
    On C-shell:
    %setenv PATH /usr/bin:/usr/sbin:.
    Append (with a ":" prefix) the directory having your script to the
    above PATH variable.
    You can make this change permanent by having this variable set
    through your ".profile" file for sh and ksh, and ".cshrc" for
    csh (in your home directory).
    Please refer to man pages of login(1) for more information.
    Thanks,
    Gopinath.
    Sun - DTS.

Maybe you are looking for

  • SNP Planned Order

    Hello Experts, Scenario: we plan finished goods in SNP & for component level we run MRP in ECC. I need to understand how MRP does planning in ECC based on SNP Planned order. Why MRP run does detailed scheduling on Finished goods planned order which r

  • Issue with Value Help not showing in Portal screen Please Help

    Hello Guru's, What is the best practice for doing ESS/MSS upgrade. Since everytime we upgrade the BP we need to redo all the customizations again in the new track and deploy. I have gone through Note 872892 and read the NWDI cookbook. I feel there sh

  • Problem while update and insert data in table

    Hi All, I have problem while save line data.... I have an advance table.I take remove and duplicate line in message choice of advance table action layout. Also there is one temp table to save Po number data which is populated in advance table accordi

  • Updating to Jaguar from 9.2; but no DVD drive

    My Granny has a B/W G3 Mac OS 9.2 and it has no DVD drive. I have a Jaguar install DVD. I also have a iMac G5 iSight with SuperDrive on it. I am told you can use a FireWire cable to use my iMac as a host or something like that. How do I do that? Than

  • File Adapter - Native format Builder button not Appearing

    Hi, When We go through the file adapter wizard and on the screen where we define the schema, there is a button 'Native format builder'. But on Jdeveloper Version - 11.1.1.3.0, it is not appearing. Has this been removed in this release? regards, Rajes