Results 1 to 11 of 11
- 05-01-2010, 07:38 PM #1
Senior Member
- Join Date
- Oct 2008
- Posts
- 116
- Rep Power
- 0
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 ); } } );
- 05-01-2010, 07:38 PM #2
Senior Member
- Join Date
- Oct 2008
- Posts
- 116
- Rep Power
- 0
any ready made script implement mine from it...?
- 05-01-2010, 07:42 PM #3
Senior Member
- Join Date
- May 2010
- Posts
- 436
- Rep Power
- 4
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.
- 05-01-2010, 07:57 PM #4
Senior Member
- Join Date
- Oct 2008
- Posts
- 116
- Rep Power
- 0
I want when press X appear a modal confirm dialog saying "chat data not saved are you want to proceed and exit"?
- 05-01-2010, 08:10 PM #5
Senior Member
- Join Date
- May 2010
- Posts
- 436
- Rep Power
- 4
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.
- 05-01-2010, 08:50 PM #6
Senior Member
- Join Date
- Oct 2008
- Posts
- 116
- Rep Power
- 0
The ONLY I do NOT know is how to: check if the data has been backed up?
- 05-01-2010, 09:07 PM #7
Senior Member
- Join Date
- May 2010
- Posts
- 436
- Rep Power
- 4
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.
- 05-01-2010, 09:16 PM #8
Senior Member
- Join Date
- Oct 2008
- Posts
- 116
- Rep Power
- 0
how understand the data modified?
- 05-01-2010, 09:25 PM #9
Senior Member
- Join Date
- May 2010
- Posts
- 436
- Rep Power
- 4
- 05-01-2010, 09:41 PM #10
Senior Member
- Join Date
- Oct 2008
- Posts
- 116
- Rep Power
- 0
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?
- 05-01-2010, 09:51 PM #11
Senior Member
- Join Date
- May 2010
- Posts
- 436
- Rep Power
- 4
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
-
Small Java program help
By rawan in forum Java AppletsReplies: 11Last Post: 03-27-2010, 06:43 PM -
getting java program from textarea
By vishnukumar in forum JavaServer Pages (JSP) and JSTLReplies: 4Last Post: 06-30-2009, 10:37 AM -
Small yahtzee program
By kimmelim in forum New To JavaReplies: 20Last Post: 03-12-2009, 12:11 PM -
Please HELP Java small program
By afrttoh in forum New To JavaReplies: 14Last Post: 11-08-2008, 02:29 AM -
Spell check in Textarea.
By surya_dks in forum Advanced JavaReplies: 2Last Post: 08-22-2008, 12:33 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks