Deciding what to do if user closes window(JDialog)

I am drawing shapes- Rectangle, Ellipse, Trianlge...I have big class that implements JFrame and it is used to draw the draw the shapes on the its content pane. Inside this class, I have an inner class that draws a custom JDialog frame. A user selects a shape from a MenuItem and the cuztom dialog frame pops up. This inner cuztom frame basically has textfields for user to enter specifications and it has a button for user to press if he/she finishes enterring the data. So user enters data in the inner frame and clicks on enter, then the Bigger(Outer) class draws the shape.
The problem is Even if the user clicks on close to close to the custom dialog, the shape is drawn. This is what I want to control. The Shape should only be drawn if the user clicks on enter.
Couls some guys offer help???
This is the code in the Outer Class. It calls the inner class so that the custom frame is popped up
if(e.getActionCommand().equalsIgnoreCase("Rectangle")) {
              showDialog() ;
              list.myList.add(new Rectangle( x, y, w, h, x3, y3, Fill, Outline)) ;
              model.addElement((list.myList.size()-1) + ": Rectangle ");
              repaint() ;
This is the inner class, but inside a method, so that I can call it in the outer class
public void showDialog() {
         class GetName extends JDialog 
           JPanel textF = new JPanel(new GridLayout(0,1)) ;
           JPanel labelF = new JPanel(new GridLayout(0,1)) ;
           JLabel XL1 = new JLabel("Add Xpos/X1") ; // the rest deleted because of space
           // the rest deleted because of space
           JFormattedTextField XT1 = new JFormattedTextField(new Integer("100"));
           public GetName() 
             setModal(true); 
             Container cont = getContentPane() ;
            //I have labels here but deleted them
             //because of the size limit to send here
          lebalF.addXL1) ; // the rest deleted because of space
             textF.add(XT1) ;
             cont.add(labelF, BorderLayout.CENTER) ;
             cont.add(textF, BorderLayout.LINE_END) ;
             JButton mybutt = new JButton("DrawShape"); 
             mybutt.addActionListener(new ActionListener(){ 
             public void actionPerformed(ActionEvent e){
                 x = Integer.parseInt(XT1.getText()) ;
                 y = Integer.parseInt(XT2.getText() ) ;
                 w = Integer.parseInt(XT3.getText() ) ;
                 ih = Integer.parseInt(YT1.getText() ) ;
                 x3 = Integer.parseInt(YT2.getText() ) ;
                 y3 = Integer.parseInt(YT3.getText() ) ;
                 // some deleted because of space
                 if(FilText.getText().equals("white"))       {Fill = Color.white;  }
                 else if(FilText.getText().equals("black"))  {Fill = Color.black;  }
                 else if(FilText.getText().equals("magenta")){Fill = Color.magenta;}
          // some deleted because of space
                 if(OutText.getText().equals("white"))       {Outline = Color.white;  }
                 else if(OutText.getText().equals("black"))  {Outline = Color.black;  }
                 else if(OutText.getText().equals("cyan"))   {Outline = Color.cyan;   }
                 dispose();}}); 
             cont.add(mybutt, BorderLayout.SOUTH) ;
             pack(); 
             setVisible(true); 
         } //End of internal class GetName
         new GetName();
     } //End of Public Method showTriDialog

My problem is solved.
I used a boolean variable and test : if(e.getSource() instanceof JButton && (JButton)e.getSource() == mybutt), then my boolean is set to true. So before I draw, i test of the boolean variable to see if it is true(meaning the button was clicked), if the boolean returns false, i skip the code that draws.
Thanks for response anyway.
//This code is in the inner class
if(e.getSource() instanceof JButton && (JButton)e.getSource() == mybutt) {
                  eventCheck = true ; //Check if user clicked on the button or closed the window
//This one in the outer class
public void actionPerformed(ActionEvent e)  {
           if(e.getActionCommand().equalsIgnoreCase("Ellipse")) {
              showDialog() ;
              if(eventCheck == true) {
              list.myList.add(new Ellipse( x, y, w, h, x3, y3, Fill, Outline)) ;
              model.addElement((list.myList.size()-1) + ": Ellipse ");
              repaint() ;
              eventCheck = false ;
            else return ;
          }

Similar Messages

  • Ending session when user closes window w/o logging out

    Hi,
    I tried looking everywhere for a solution to this problem and was unable to do so. I'm running tomcat 4.0.5 on win2k and am trying to prevent multiple user logging capability, but the listeners that I implemented for the session can only detect the creation of the session, and the destruction after the pre-set session invalidation time. So if the user closes the window 15 minutes into the session, the server still has the flag for "logged in" in place and the user cannot log in for the remainded of the session time (which is another 15 minutes).
    Can anyone please help me with this problem?
    Thank you very much,
    Lior

    How can I do that? Do you have any code I could take a look at. Thanks a lot.

  • Force end of session when user closes window without logging out

    I want to protect sensitive employee data. Does anyone know how to force a user's portal session to be terminated after a user closes a window with the "X" instead of logging out?

    Web application is connectionless. So there is no way to tell if a user has disconnected. If the user diligently logout, then invalidating a session is no problem. However, if you wish to invalidate the user upon closing of window, I suggest you drop that idea and change to different approach.
    1. If you are trying to impose single logon policy, you may consider invalidate an existing session if the same user login again.
    2. If you really need to invalidate a user session as soon as he is inactive (or closes window). I suggest you set a very small timeout interval (maybe 3 minutes). Then for all the pages, implement a simple invisible IFRAME that will keep refreshing itself (say every 2 minutes) on a dummy JSP/servlet URL. The fact that this IFRAME always hit the URL at 2 mins interval will keep the user session valid. Once the browser window is closed, the session will be invalidated in max 3 mins time.
    The final suggestion is to drop that idea altogether, the point is ... implement such feature is like twisting web application to do something that it is not design to do naturally.

  • How to close a HTTP session when a user closes the window

    Hi,
    I am having problems when closing the browser of a BW web report. After I closed the browser by going File->close, I ran SM04 and found out the Plugin HTTP session hangs at the server side.
    How can we terminate the Plugin HTTP session at the server side when user closes the internet browser?
    I did implement a logoff function at my web template and this was implimented on the Menu page, if user clicks on the logoff, the Plugin HTTP session is terminated at server side correctly.
    If user navigates to the other pages from the main page... then the logoff function was not implimented in the other pages. So many of the users are closing the windows directly. Eevn if we impliment logoff in all the subpages, As you know, 50% of time user will close the report by closing the internet browser instead of clicking the logoff. That leaves lots of hanging Plugin HTTP sessions at our server side.
    Regards,
    Tony

    Hi,
    And also take a look on the Genral property of the web template. We solved this problem by changing only this property (no extra things).
    <b>Property:                            Value</b>
    Automatic Session Management:           Active
    With rgds,
    Anil Kumar Sharma .P
    Message was edited by: Anil Kumar Sharma

  • Why can't I install iTunes on windows RT? Is Microsoft deciding what software I can use?

    Why can't I install iTunes on Windows RT? Is Microsoft deciding what software I can use?

    Welcome to Apple Support Communities
    Theoretically, Microsoft is deciding what apps you can install. In Windows RT, you can only install apps from the Windows Store and they must be ARM-based, things that Apple and iTunes don't meet, so you can't use iTunes in Windows RT

  • End-user closes the Web browser's window...

    Hi ,
    I have an Exit_Form selection on a menu.....
    Is it possible the code being there to be executed whenever the end-user closes the web-browser's window.....???
    I use Dev10g.
    Thanks , a lot
    Simon

    Unfortunately... is is not applicable....because:
    1) Many users(application users) connect via a db user to the database.... , so i cannot relate each application user to a db session.
    2) The trigger on_logoff can not be used because of the first note....
    3) As i have written in my previous post the "exit_form" is not 'pure PL/SQL' code but 'forms' code.... It contains some 'erase(global_variables)' which are unknown to the db......
    Thanks , anyway...
    Simon

  • What tool should mac users recommend for convertng ulaw to .mp3 files. I used to use Goldwave on windows to convert ulaw to .mp3 files

    Hi,
    I recently switched to mac and I am not used to which applications to use
    What tool should mac users recommend for convertng ulaw to .mp3 files. I used to use Goldwave on windows to convert ulaw to .mp3 files
    Thanks,
    SK

    Congrats on switching!  You won't regret it.
    Try Google.  There appear to be options to do what you want.

  • Force code execute when user closes OOB lightswitch app using the windows close red X

    I've created a lightswitch app using Forms Authentication.  If the user closes the application using the window close red 'X', I need to update a custom user profile table.  Is this possible?

    I use this code and it works!
    I handle the closing event of the user and I break it, execute my code ed after closing the application.
    Under you see the code that I use in my application.vb :
    Public Class Uscita
    ' Dichiara un evento per la classe
    Public Event Event1()
    ' Definisce un metodo per richiamare l'evento
    Sub CausaEvento()
    RaiseEvent Event1()
    End Sub
    End Class
    Protected Sub EsceAPP()
    Dim Obj As New Uscita
    AddHandler Obj.Event1, AddressOf Me.EventoUscita
    ' Provoca l'esecuzione dell'evento
    Obj.CausaEvento()
    End Sub
    Sub Eventouscita()
    Dispatchers.Main.BeginInvoke(Sub()
    RemoveHandler _mainWindowClose.Closing, AddressOf MainWindow_Closing
    System.Windows.Application.Current.MainWindow.Close()
    End Sub)
    End Sub
    Private Sub Application_loggedin()
    Try
    Dispatchers.Main.BeginInvoke(Sub()
    _mainWindowClose = System.Windows.Application.Current.MainWindow
    AddHandler _mainWindowClose.Closing, AddressOf MainWindow_Closing
    End Sub)
    Catch ex As Exception
    MessageBox.Show(ex.Message)
    End Try
    End Sub
    Private Sub MainWindow_Closing(ByVal sender As Object, ByVal e As ClosingEventArgs)
    If MessageBox.Show("Vuoi Veramente uscire?", "Conferma", MessageBoxOption.OkCancel) = Windows.MessageBoxResult.Cancel Then
    'Elimina l'uscita utente
    e.Cancel = True
    Else
    'Interrompe momentaneamente l'uscita dell'utente per eseguire l'aggiornamento della tabella utenti loggati
    e.Cancel = True
    'Aggiorna la tabella utenti loggati ed esce dall'applicativo
    Me.Details.Dispatcher.BeginInvoke(Sub()
    Dim ws = CreateDataWorkspace()
    Dim query = ws.ApplicationData.UtentiLoggatis.Where(Function(c) c.UserName = Me.User.FullName).FirstOrDefault
    query.OnLineImage = MyImageHelper.GetImageByName("RedLight.png")
    query.OnLIne = "OFF"
    query.Logout = Now
    ws.ApplicationData.SaveChanges()
    'Chiama la routine per uscire dall'applicazione
    EsceAPP()
    End Sub)
    End If
    End Sub

  • Illustrator CS2 Doesn't Start For User on Windows 2000

    I've recently installed Adobe Illustrator CS2 on a Windows 2000 system. When I start the product when logged in as the Administrator, it starts fine. However, when I start the product logged in as a user, it goes thru the startup process, displays all of the various tool windows, and then before it gets to the first time window, it just closes. No error messages, nothing in the Windows system or application log, it just closes the same windows it just opened and then exits.
    I've tried setting the permissions on the folders listed in the Windows Rights KB entry, with no effect. I've tried installing a postscript printer, setting full rights on it, and using it as the default for the user.
    Does anyone know what file right, user priviledge, or other feature might be causing the problem? Thanks.

    I wasn't aware that it required Power User rights. This is somewhat of a high security environment, and that can be difficult.
    Do you, by chance, know what features of Power User rights are needed? I can perhaps grant those to this user, and make it work.
    Do you think it is having a problem accessing portions of the registry, or files in certain folders, or something else?
    Thanks for your help.

  • Open PDF in browser - but cant control/close window from javascript

    Hi
    I hope I picked the correct forum
    Basically I have a site in asp classic. From a button I opens 2
    windows via javascript.
    One contains info, one shows a related file ( could be tiff or pdf ).
    When user closes info-window, I also close the file window via javascript, so that user only hav to click once.
    That works with tiff, but not with pdf, '!file.closed' returns that window are already closed.
    Somehow I simply loose contact to that window when I open pdf.
    My Adobe is set  with "open pdf in browser", version 10.1.2
    Any Ideas ?
    Overview what I do:
    function openTwoWindows(jnr,vikar,hvorfra){
              var left, top,vikar;
              width = (window.screen.availWidth/2)+80;
              width2 = (window.screen.availWidth/2)-80;
              height  = (window.screen.availHeight);
              info = window.open('info.asp'','top=0,left=0,height='+height+',width='+width+',resizable=yes,scr ollbars=yes,status=yes');
              var settings= 'toolbar=no,location=no,directories=no,'+
              'status=no,menubar=no,scrollbars=no,resizable=yes, top=0, left='+width+', height='+height+',width='+width2;
              file = window.open('showfile.asp?strJnr='+jnr+'&print=false','file',settings);
              info.focus();
    function closeFileWindow(){
                if(file && !file.closed){
                             file.close();
    if the file is a pdf -> showfile code in asp classic:
    Response.AddHeader "Content-Disposition","inline;filename=filename.pdf"
    Response.ContentType = "Application/pdf"
    'Response.Clear
    Response.Buffer = true
    // fetch file from database
    Response.BinaryWrite rsTmp("Fil")
    Response.Flush
    Response.End

    Read this:
    http://forums.adobe.com/thread/535609?tstart=0

  • Unix command to click button on dialog box and close windows?

    I administer an elementary school computer lab of 35 eMacs all with OS 10.4.7 and with ARD 3.0. Our network server configuration requires a mounted server on each desktop in order to administer certain software packages we use. Every morning at start-up I have to walk around and manually click "Connect" on the dialog boxes. Then, with this configuration, each time a server is mounted, it opens up a Finder Window on the host machine so I've got to walk around and close windows on all the machines. I'm sure there must be an AppleScript or Unix command that I can set up to do these two tasks but I've not found it (or learned how to write it) in a few days of searching. Any suggestions?
    Thanks,
    Dan

    OK guys,
    I just succeeded in saving the AppleScript command as an application. I put it in the Login Items just after the servers. It worked beautifully! No more open windows exposing sensitive files to the risks of elementary students (how come the mounted volumes always appear on the desktop even when the "hide" button is checked?). It would be great if the mounted volumes were not showing at least in a setting like a school computer lab.
    Now, I'm still dealing with the mounting process requiring me to manually click on "Connect" every time. The Student account doesn't even have a password just to make such things easier. Still the process displays this:
    (Oh well, I guess I can't insert a ScreenShot.)
    Here's what it says: Connect to the file server "server name."
    Connect as: Registered User
    Name: "account name"
    √Remember password in keychain
    (and then two buttons) Cancel or Connect
    That's where I'm at right now. My district Tech. Support folks say that there's no way to avoid the dialog box but John seems to do it OK. They also pointed me to an online source (www.bombich.com) that I haven't yet checked out.
    Thanks again,
    Dan

  • How to wire into that close window x button

    I want when the end user click the program's x red button at the top right, a dialog box with two buttons will pop out and say "are you sure?", if the end user click Ok, the program will shut off and close its window, if the end user click cancel, the program continues to run.
    So I start building the vi, refer attached, but I was flipping the help search without knowing what is the name of that red x button, and i cant find the function block!
    So, my question is:
    1. I want to wire into that x red close window button event to control my case structure, but where is that function block?
    2. Where is the function block that shut off the program as well as close the program window?
    Thanks.
    Solved!
    Go to Solution.
    Attachments:
    2.vi ‏7 KB

    I would add, by way of explanation, that you don't actually "tie into the button", you tie into the event that it represents.
    That means that if you add an event for PANEL CLOSE?, that event gets triggered by all the things that would close the window: Clicking the CLOSE box (as mentioned), but also typing CTRL-W, selecting CLOSE from the FILE menu (if that's available), aborting the program from the TASK MANAGER (ctrl-alt-delete), and script operations on OS X.
    Usually, that's what you want. The point is you're being asked if it's OK to close and you get a chance to say "no".  But it doesn't necessarily come from the CLOSE box.
    Steve Bird
    Culverson Software - Elegant software that is a pleasure to use.
    Culverson.com
    Blog for (mostly LabVIEW) programmers: Tips And Tricks

  • Coding to allow the X (Close Window icon) to close a window.

    I have coded a number of Modal screens called from a main screen.  I can't seem to find what allows the windows Close Window icon (X) to close the screen.  The user must hit my exit button to leave, and I want to keep that as an option, but also allow the X to close the window and be able to handle it in my User Command module.
    Thanks in advance

    Hi Paul,
    First set the PF-status with CANCEL and activate it
    for the model screen.
    in PAI.
    module leave_screen.
    in program
    case ok_code
    when 'CANCEL'.
    leave to screen 0.
    endcase.
    Best Regards
    Ramchander Rao.K
    Edited by: Ramchander Krishnamraju on Dec 23, 2008 11:06 AM

  • What do I do to close eform on screen and display response of web service in another screen.?

    Hi,
    I am trying to build following functionality.
    I want to submit form to a web service through SOAP request on click of a button.
    I want to display response of web service like “form has been submitted successfully” on screen.
    What has been achieved.
    I am able to submit form to an adobe web service passing base64 string to adobe process.(see the script in image#1).
    When I receive base64 string in adobe process, I am able to re-generate document (using getDocFromBase64(/process_data/@inputStr) ).
    After that I am returning a message string to as response “Form submitted successfully”.
    When I get the response I populate response to a text field variable (Out Str). See image#2
    Problem/Desirable functionality.
    I want to close this eform and display the message “form has been submitted successfully” on another page in browser so that it depicts to end user that form has been submitted successfully with confirmation.
    What do I do to close eform on screen and display response of web service in another screen.?
    Image#1
    Image#2

    Method1: This method only works in same PDF window.
    On the click of the submit button, based on the webservice result we can close the PDF. As you already having in the "Out Str", this variable having detailed message kind of thing, so it would be easier if you have one more output variable to know if this submission is success or failure or can use the "Out Str", it self to compare and close the PDF.
    Here i am using "strResult" to hold webservice success or failure using true/ false values.
    Get the "strResult" value from binded field of webservice response and compare and close or display messages based on requirement.
    var strResult = YourFieldname.rawValue;
                        if(strResult != "" && strResult != null){
                                  if(strResult.toUpperCase() == "TRUE"){
                                            xfa.host.messageBox("Successfully Saved the Data.", "Submit Confirmation", 3,0);
                                            //Close the PDF
                                            app.execMenuItem("Close");
                        else{
                                  xfa.host.messageBox("Failed to Save the Data.", "Submit Confirmation", 3,0);
    If the result need to show in separate window and having LiveCycle process connected to PDF via. webservice or REST:
    Method2. If the PDF inside the browser
    Type1 - You can set the process output is document variable, this PDF may contain your static/dynamic message and this PDF. But with this method result PDF opens in same window, host pdf will be disappeared.
    Type2 - You can set the process output is string variable, this STRING may contain your static/dynamic message. In this method the string will be appered in the same PDF window, host pdf will be disappeared.
    Method3. If the PDF is stand alone (not opend in any browser)
    Type1 - You can set the process output is document variable, this PDF may contain your static/dynamic message and this PDF. But with this method result PDF opens in new window, host pdf will be also stayed and may make readonly after submission success.
    Type2 - If the process output is string, it cannot handle this situation, may get the content type exception while receiving the result string, because.
    Used all of the above methods in various situations and it worked without any issues.
    -Raghu.

  • Javascript Open and Close window

    I am creating a new website and am having problems getting
    the open window and close window to work. I want this window to
    open a new window (NOT a popup window used with the "onload"
    option). I am using an img tag so that when you click on the image
    thumbnail this new window opens. It is my understanding in order to
    use the window.close option, you must have the javascript in the
    header of the html document for the close to work. In the heading
    of the document that contains the link to open a new window I have
    the following:
    <SCRIPT language="JavaScript1.2">
    function popuponclick()
    Cellex = window.open("products/cellex.htm",
    "console","status=1,width=350,height=150");
    function closepopup()
    if(false == cellex.closed)
    cellex.close ();
    else
    alert('Window already closed!');
    </SCRIPT>
    Then I have this in the body:
    <img src="images/thumbnails/dermalogicath.jpg"
    alt="Dermalogica" width="94" height="84" border="0"
    /></a></td>
    <td><a href="products/mdskin.htm"
    onclick="window.open('products/mdskin.htm','mdskin',width=610,height=780,scrollbars=yes') ;return
    false; target="_blank">
    However, I'm getting script errors when opening the window on
    the lines in the body Unterminated error. I have tried using the
    help in Dreamweaver as well as many docs posted, but still cannot
    get this to work. Once I get the script errors resolved, the when
    the window opens, it will not close. I get the message that a
    window is trying to be closed and do I want to close the window
    which closes internet explorer entirely. I'm using IE 7.0 as well
    as foxfire and have the same issue on both. If I use the
    dreamweaver behaviors to call a javascript, it puts "onload" and if
    I change to "onclick" then the script will not work. When I use the
    behavior "open window" it still doesn't work. I'm totally lost as
    to what I'm doing wrong as I have followed about 10 papers all
    using the same instructions.
    Hopefully some one can help me, I'm getting fustrated as this
    seems to be pretty straight forward.
    Thanks, vienie

    Try this on for size:
    I have included two functions.
    windowRebuild() - opens a new window, maximizes it based on the screen size, removes all toolbars, and then closes the old window.
    myLocation(appName, pageName) - builds a url referencing an HTMLDB application, specfic to what server you are currently on. Very useful when you have an application on 3 different servers(dev, test, prod servers), you wouldn't want the server name hardcoded if you plan to export the app to another server.
    Also, you need to be careful when using &APP_ID. I am not completely certain how that is resolved at runtime, but I've found it only works when the javascript is in the HTML Header of a page and not stored in the template of the page.
    <script language="JavaScript1.1" type="text/javascript">
      This functions is for internal application use.
      Examples of myLocation:
      url = myLocation('&APP_ID.', 'APP_PUBLIC_PAGE');
      url = myLocation('MY_APP_ALIAS', 'MY_PAGE_ALIAS');
      url = myLocation('184', '10');
    function myLocation(myApp, myPage){
      var myHost = location.host;
      var newURL;
      newURL = 'http://'+myHost+'/pls/htmldb/f?p='+myApp.toString()+':'+myPage.toString();
      return newURL;
    /*  Function windowRebuild()
    *   This function will open a new window and close the old window.
    *   This function will also maximize the new window and remove all toolbars.
    function windowRebuild(){
       if(window.name != 'myAppWin'){
        var url = myLocation('&APP_ID.', 'PAGE_ALIAS');
        var myWin = window.open(url,'myAppWin','toolbar=0,scrollbars=1,menubar=0,status=1,resizable=1,location=0');
        window.opener = 'x';
        window.close();
       if(window.name == 'myAppWin'){
        window.moveTo(0,0);
        window.resizeTo(screen.availWidth,screen.availHeight);
    </script>Let me know if that works or you need some more explanation.
    Chris

Maybe you are looking for