java - Making a Button Stay Clicked -


how make button stay clicks after user has exited program?

let's have option(as jbutton) sets jtextarea's text red. user clicks button, exits program. when user opens program up, text red - meaning button still clicked.

if don't example, let me show one:

i have jbutton, , jlabel. when button clicked, changes background of jlabel blue. user clicks button, exits program. when user opens program up, button clicked, meaning jlabel's background color blue.

is there way can that?

edit: prefer if without loading external files.

edit 2: idea of using preference. but, give me examplre me 1 of examples above? i'm kind of beginner in java, have lot of questions. like, code go in actionperformed of button? and, how save different kinds of information(jtextarea foreground red) preferences?

you should use preferences this. explanation little complex. saves values can retrieved between runs.

here's tutorial of how use jfilechooser. here's example wrote:

package com.sandbox;  import java.util.prefs.preferences;  public class sandbox {      public static void main(string[] args) {         preferences prefs = preferences.usernodeforpackage(sandbox.class);         integer counter = integer.valueof(prefs.get("counter", "0"));         system.out.println(counter);         counter++;         prefs.put("counter", string.valueof(counter));     } } 

the first time run this, it'll print "0". next time run it, it'll print "1".


Comments

Popular posts from this blog

linux - xterm copying to CLIPBOARD using copy-selection causes automatic updating of CLIPBOARD upon mouse selection -

c++ - qgraphicsview horizontal scrolling always has a vertical delta -