swing - How do you change variable value(s) in Java based on user input in a GUI? -


i designing gui farm. farm consists of 3 actors (weed, bean plant , farmer). upon running farm gui, shows movement of farmer planting , removing weed farm field. have defined probabilities actors ensure field not overpopulated.

the following declared in simulator class. probabilities follows:

    public final double farmer_creation_prob = 0.01;     public final double beanplant_creation_prob = 0.01;     public final double weed_creation_prob = 0.01; 

i designing seperate gui allows variables above (and more) changed based on user inputs. example, have jtextfield weed creation probability, if user enters 3, want farmer_creation_prob = 3;.

this how have created jtextfields 3 probabilities (declared in farmgui class):

 weedfield = new jtextfield ();  beanfield = new jtextfield ();  farmerfield = new jtextfield(); 

with limited understanding of java, have tried following:

public final double weed_creation_prob = weedfield.gettext(); 

however, states "cannot find symbol". i'm pretty sure approach not correct way go anyway.

question: how obtain user input gui , ensure changes creation probabilities user has entered?

edit:

first of all, feedback.

this gui have designed (very basic)

[img]http://i57.tinypic.com/2j63668.png[/img]

the logic of gui: whole purpose of gui enable user set values each field. upon clicking "run simulation" in gui above, gui simulation run appear on separate frame.

edit 2:

i have tried following (based on @zaibi099 suggestion), wondering if correct.

in simulator class:

    public final double weed_creation_prob; 

in farm gui class:

        run.addactionlistener(new actionlistener() {            public void actionperformed(actionevent event) {            double s = double.parsedouble(weedfield.gettext());  

mistakes making:

  1. these both not type compatible. weedfield.gettext(); returns string , assigning double
  2. you trying assign value final(constant variable) it'll not allow that.constant can assign value first time.

solution : public final double farmer_creation_prob;

and want assign :

farmer_creation_prob = weedfield.gettext();  // don't forget convert text field double 

Comments

Popular posts from this blog

python - mat is not a numerical tuple : openCV error -

c# - MSAA finds controls UI Automation doesn't -

wordpress - .htaccess: RewriteRule: bad flag delimiters -