Results 1 to 11 of 11
  1. #1
    lse123 is offline Senior Member
    Join Date
    Oct 2008
    Posts
    116
    Rep Power
    0

    Default perform a check if chat's(edu/test/small program) textarea saved or not

    what to include below to perform a check if chat's(edu/test/small program) textarea saved or not , if saved exit, if NOT prompt to save with JOptionPane.(chat program includes other, save button)

    Java Code:
    addWindowListener(
             new WindowAdapter() 
             {
                public void windowClosing( WindowEvent e )
                {
                   [B]// here code[/B] 
                   System.exit( 0 ); 
                } 
             } 
          );

  2. #2
    lse123 is offline Senior Member
    Join Date
    Oct 2008
    Posts
    116
    Rep Power
    0

    Default

    any ready made script implement mine from it...?

  3. #3
    curmudgeon is offline Senior Member
    Join Date
    May 2010
    Posts
    436
    Rep Power
    5

    Default

    I've seen lots of examples of this in this and other forums. Which part are you having trouble with? Preventing the JFrame from exiting when the title bar's "x" button is pressed? If so then set the JFrame's default close operation to JFrame.DO_NOTHING_ON_CLOSE.

    Or is your problem elsewhere in your code such as checking to see if the data has been saved? If this, then the implementation will likely depend on your program and how it saves the data.

  4. #4
    lse123 is offline Senior Member
    Join Date
    Oct 2008
    Posts
    116
    Rep Power
    0

    Default

    I want when press X appear a modal confirm dialog saying "chat data not saved are you want to proceed and exit"?

  5. #5
    curmudgeon is offline Senior Member
    Join Date
    May 2010
    Posts
    436
    Rep Power
    5

    Default

    Quote Originally Posted by lse123 View Post
    I want when press X appear a modal confirm dialog saying "chat data not saved are you want to proceed and exit"?
    Cool, then your 90% there as my recommendation to set the JFrame's default close operation and your use of a WindowListener should do the trick. In your WindowListener/Adapter's windowClosing method, check if the data has been backed up, and if not simply call a JOptionPane.showConfirmDialog(...) and based on the response exit the program or not.

  6. #6
    lse123 is offline Senior Member
    Join Date
    Oct 2008
    Posts
    116
    Rep Power
    0

    Default

    The ONLY I do NOT know is how to: check if the data has been backed up?

  7. #7
    curmudgeon is offline Senior Member
    Join Date
    May 2010
    Posts
    436
    Rep Power
    5

    Default

    Quote Originally Posted by lse123 View Post
    The ONLY I do NOT know is how to: check if the data has been backed up?
    You're going to have to figure this one out yourself as I know of no "one-size-fits-all" solution, and it will depend on your program's structure, how it interacts with and stores the data, etc... Perhaps you should have a boolean field in your app, say called dataModified, and set it to true whenever the data has been modified, and to false when the data has been stored. Then you can ascertain the state of your data when the user tries to close.

  8. #8
    lse123 is offline Senior Member
    Join Date
    Oct 2008
    Posts
    116
    Rep Power
    0

    Default

    how understand the data modified?

  9. #9
    curmudgeon is offline Senior Member
    Join Date
    May 2010
    Posts
    436
    Rep Power
    5

    Default

    Quote Originally Posted by lse123 View Post
    how understand the data modified?
    Huh? You wrote the program, right? So if anyone is going to know when the data has been modified, I hope it is you. Do you need to add a DocumentListener to a JTextArea? I honestly don't know as it's your program.

  10. #10
    lse123 is offline Senior Member
    Join Date
    Oct 2008
    Posts
    116
    Rep Power
    0

    Default

    if have normal textarea:
    displayArea = new JTextArea(); // create textarea

    then I must use:
    public DocumentEvent.ElementChange getChange(Element elem)
    from DocumentEvent (Java 2 Platform SE v1.4.2)

    for Element put displayArea here?

  11. #11
    curmudgeon is offline Senior Member
    Join Date
    May 2010
    Posts
    436
    Rep Power
    5

    Default

    Quote Originally Posted by lse123 View Post
    if have normal textarea:
    displayArea = new JTextArea(); // create textarea

    then I must use:
    public DocumentEvent.ElementChange getChange(Element elem)
    from DocumentEvent (Java 2 Platform SE v1.4.2)

    for Element put displayArea here?
    I'm not familiar with doing anything like this, so I can't comment on whether it's right or wrong (perhaps someone else can help you here), but for my money, simply getting the Document out of the JTextArea and adding a DocumentListener may be all that's necessary to detect changes to the text.

Similar Threads

  1. Small Java program help
    By rawan in forum Java Applets
    Replies: 11
    Last Post: 03-27-2010, 07:43 PM
  2. getting java program from textarea
    By vishnukumar in forum JavaServer Pages (JSP) and JSTL
    Replies: 4
    Last Post: 06-30-2009, 11:37 AM
  3. Small yahtzee program
    By kimmelim in forum New To Java
    Replies: 20
    Last Post: 03-12-2009, 01:11 PM
  4. Please HELP Java small program
    By afrttoh in forum New To Java
    Replies: 14
    Last Post: 11-08-2008, 03:29 AM
  5. Spell check in Textarea.
    By surya_dks in forum Advanced Java
    Replies: 2
    Last Post: 08-22-2008, 01:33 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •