Why do you want to update the state of that text field? Why do you need to do it from the utils class (which should start U not u)? Why are you returning a panel? Why do you appear to be setting up the GUI is a method not specifically designed for setting up GUIs? I think you need to explain what you want to do, before anybody can work out how to do it.
Campbell Ritchie wrote:Welcome to the Ranch
Why do you want to update the state of that text field? Why do you need to do it from the utils class (which should start * not *)? Why are you returning a panel? Why do you appear to be setting up the GUI is a method not specifically designed for setting up GUIs? I think you need to explain what you want to do, before anybody can work out how to do it.
Hi, sorry what I should have said that I want to update the TEXT in the JField from another class. The ServiceMonitor class is used to create a panel and fill it will values.. I just need to be able to update certain JFields that are in the panel from another java.class file.
please note the code in this post is extracts from the actual code.. I also typed some of it in so there will be punctuation issues.
Campbell Ritchie wrote:I am afraid that doesn't explain anything new. I already presumed you wanted to update the text.
I thought what I asked for would be straight forward.
Basically I have a JPanel that has some JTextfields in it.. this JPanel was created in a Class (e.g. Class1)
I need to be able to update the JTextfields in this JPanel from Class1 in Class2 as there is a timer1 event in Class2 that I want one of the functions to update the field in the panel.
Fred Kleinschmidt wrote:First of all, you need to re-design the ServiceMonitor class. The getLegend method should not be static, and it probably should not be public. The GUI items (especially "green" should be private instance variables, and then you call getLegend() from the constructor to create the GUI. You also create a public method setGreenText(). So if your Util class has a reference to a ServiceMonitor instance, it can call
Sorry, I'm very new to java and OO so dont understand this.
Campbell Ritchie wrote:Unless you need specific graphics to appear on the panel, you can probably do it without extending any Component classes at all.
so this brings me back to my issue.. how do I control the text in the Jfield within the JPanel from another class without extending it.
I tried changing the JPanel code from static JPanel getLegend() to public JPanel getLegend() but I still cannot control the JFields.
ServiceMonitor Class -
Utils Class -
You tried to do the second part of that, but since you didn't do the first part properly you can't make it work.
I expect you could do that by extending JFrame too, although it's a bad practice and is universally recommended against (except in innumerable web tutorials who copied their code from 1999).