• Post Reply Bookmark Topic Watch Topic
  • New Topic

upon close how: saved in a file(JFileChooser) since last modified  RSS feed

 
Leonidas Savvides
Ranch Hand
Posts: 403
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Upon close an app how determine AND prompt(continue or cancel =prompt), if textfields/textarea (both saved together), SAVED in a file(JFileChooser) since last CHANGED/MODIFIED?

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 http://72.5.124.55/j2se/1.4.2/docs/api/javax/swing/event/DocumentEvent.html )

for Element put displayTextArea here?

 
Rob Spoor
Sheriff
Posts: 21095
85
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You'll need to keep a flag that indicates whether or not the contents have been modified. In the document listener you set that flag to true, upon saving you set it to false.
 
Leonidas Savvides
Ranch Hand
Posts: 403
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yes I know this, that I do not know is how to compare MODIFIED/SAVED (true) or MODIFIED/NOT-SAVED (false) ? what classes/methods use ?
 
Rob Spoor
Sheriff
Posts: 21095
85
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is there a need for modified/saved? In all programs I've seen only two states - modified or unmodified. Saved falls under the last category. It's then simply a matter of using the boolean value:
 
Leonidas Savvides
Ranch Hand
Posts: 403
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yet under test, I get error 1 at:


 
Rob Spoor
Sheriff
Posts: 21095
85
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That's because line 10 is wrong. First of all, there is no method called getChange in interface DocumentEvent.ElementChange. There is one in DocumentEvent, but you still can't treat it as a static method, something you are doing now.

Try adding a DocumentListener to your text area's document (using getDocument().addDocumentListener(...)).
 
Leonidas Savvides
Ranch Hand
Posts: 403
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
IF ALSO want to check and textboxes?

There's any complete scriptlet, from ready made open source java program, about this?
 
Paul Clapham
Sheriff
Posts: 22526
43
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Leonidas Savvides wrote:IF ALSO want to check and textboxes?


But no, you are doing it the wrong way. You shouldn't be worrying about whether the user clicks a checkbox. You want to keep track of whether the model changes (that's the data you are updating) -- and not whether the view changes (that's your user interface).

So everywhere in the code where you change the data, set on the "modified" flag.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!