Solved

Once mo about text field

Posted on 2011-02-24
57
286 Views
Last Modified: 2012-05-11
Let's leave behind two previous question because they need much more time for me to study answers.
This question only about simple setting string value from PMDS class to DCC class into jTextField1.
As I understood now it doesn't need to have any action listener for just setting text from string eurusd_bid into textfield with the command - setText(), but it doesn't appear on the screen, but visible on redirected output window.
Please advice
if ("EUR/USD".equalsIgnoreCase(symbol.trim())) {
                    bid = bidPx;
                    eurusd_bid = String.valueOf(bid);

                    DecisionCenterControl.getInstance().eurUSD_bid_TextField();

                    System.out.println("   EUR/USD  string bid   " + eurusd_bid);

Open in new window

jTextField1.setBounds(new Rectangle(505, 40, 95, 40));
        jTextField1.setFont(new Font("Lucida Grande", 1, 10));
............
    public void eurUSD_bid_TextField() {

        jTextField1.setText(eurusd_bid);
    }

Open in new window

0
Comment
Question by:gbcbr
  • 32
  • 24
57 Comments
 
LVL 92

Expert Comment

by:objects
Comment Utility
are you sure you are updating the rignt variable.
need to see more of the gui code to see what the problem is
0
 
LVL 47

Expert Comment

by:for_yan
Comment Utility
Can you explain in more detail your environment; what means "it doesn't appear on the screen, but visible on redirected output window." ?
And is this something you want this way, or you have it this way?
0
 

Author Comment

by:gbcbr
Comment Utility
>> are you sure you are updating the rignt variable.

>> what means "it doesn't appear on the screen, but visible on redirected output window." ?

DCC.tiff
0
 
LVL 47

Expert Comment

by:for_yan
Comment Utility
But where do you pass string DecisionCenterControl.getInstance().eurUSD_bid_TextField();
There is no argument?
0
 
LVL 47

Expert Comment

by:for_yan
Comment Utility
where d you get this string  eurusd_bid   in  jTextField1.setText(eurusd_bid)it should be

public void eurUSD_bid_TextField(eurusd_bid) {

        jTextField1.setText(eurusd_bid);
    }
0
 
LVL 47

Expert Comment

by:for_yan
Comment Utility
So you method shoul be defined this way:
public void eurUSD_bid_TextField( String eurusd_bid) {

        jTextField1.setText(eurusd_bid);
    }

and you should call it with the actial string as argument:

  DecisionCenterControl.getInstance().eurUSD_bid_TextField(eurusd_bid);


0
 
LVL 47

Expert Comment

by:for_yan
Comment Utility
If those are two different classes then you should pass the string  to print on the textfield through the parameter, otherwise
how would it get the actual string to print.
0
 

Author Comment

by:gbcbr
Comment Utility
I try this already from the beginning, same result
public void eurUSD_bid_TextField(String eurusd_bid){

//    public void eurUSD_bid_TextField() {

        jTextField1.setText(eurusd_bid);
    }

Open in new window

try {

                if ("EUR/USD".equalsIgnoreCase(symbol.trim())) {
                    bid = bidPx;
                    eurusd_bid = String.valueOf(bid);
    //              DecisionCenterControl.getInstance().eurUSD_bid();
                    DecisionCenterControl.getInstance().eurUSD_bid_TextField(eurusd_bid);

Open in new window

0
 

Author Comment

by:gbcbr
Comment Utility
this is the reason of this question, it must to appear, but not
0
 
LVL 47

Expert Comment

by:for_yan
Comment Utility
but they both should have something inside parentheses.

This is the definition of the method:

  public void eurUSD_bid_TextField(String eurusd_bid) {

        jTextField1.setText(eurusd_bid);
    }


This is how you would use this mehod:

String eurusd_bid = "123.5";
 DecisionCenterControl.getInstance().eurUSD_bid_TextField(eurusd_bid);

Onle then you may hope to see "123.5" in your textfiled




0
 
LVL 47

Expert Comment

by:for_yan
Comment Utility
It is all strange it should not even compile if you declare method without parameter and then
use it with parameter
0
 

Author Comment

by:gbcbr
Comment Utility
String eurusd_bid printed well as a string in output window as you can see on screenshot.
If I will make it manually >> String eurusd_bid = "123.5";
What is difference, but I'll try
0
 
LVL 47

Expert Comment

by:for_yan
Comment Utility
That is how it works normally:

in one class, say class A,  you have the value of the String, say

String s = "abc";

In another class say, class B,  you have instance jTextField of JTextField  and in that second class you will have a method

public void setTextFieldValue(String s){
jTextField.setText(s);
}

then somehwre in class A you may have the code:

B b = new B();
String s = "abc";

b.setTextFieldValue(s);

then the text "abc" kind of "sent from" class A will appear in the TextFiled
in class B. But you need to pass this string as parameter.

Any questions? let me know





0
 

Author Comment

by:gbcbr
Comment Utility
DCC2.tiff
@objects
>>need to see more of the gui code to see what the problem is
please find attached class DCC
DecisionCenterControl.java
0
 
LVL 47

Expert Comment

by:for_yan
Comment Utility
Now your DCC class has correct method
----------------------
      public void eurUSD_bid_TextField(String eurusd_bid){

        jTextField1.setText(eurusd_bid);
    }
-------------------------------------------

So how do you use this method in your PMDS class?
0
 
LVL 47

Expert Comment

by:for_yan
Comment Utility
If you do not see this text appear in TextField, add printout:

      public void eurUSD_bid_TextField(String eurusd_bid){
      System.out.println("  .._bid: " + eurusd_bid);
        jTextField1.setText(eurusd_bid);
    }

Then you could see on your console  if parameter is passed to the method
0
 

Author Comment

by:gbcbr
Comment Utility
yes, it passed
EUR/USD  string bid   1.38263
  .._bid: 1.38262
   EUR/USD  string bid   1.38262
  .._bid: 1.38267
   EUR/USD  string bid   1.38267
  .._bid: 1.38266
   EUR/USD  string bid   1.38266
  .._bid: 1.38262
   EUR/USD  string bid   1.38262

Open in new window

0
 
LVL 47

Expert Comment

by:for_yan
Comment Utility
OK, and waht about TextField ?
0
 

Author Comment

by:gbcbr
Comment Utility
why this method doesn't work?
 jTextField1.setText(eurusd_bid);
maybe it just invisible and need add setVisible?
0
 

Author Comment

by:gbcbr
Comment Utility
>>waht about TextField ?
? you can see it in class
0
 

Author Comment

by:gbcbr
Comment Utility
I'll be back in 3 hours
0
 
LVL 47

Expert Comment

by:for_yan
Comment Utility
No I mean does it change immediately after you see it printed?
So now I guess what you are saying that it does not.
It is probably because you are confused which textFiled has which name, let me see
0
 
LVL 47

Expert Comment

by:for_yan
Comment Utility

I guess you don't see this jTextField1 in your GUI
and why do you set Layout(null) - ? What does this mean?
0
 
LVL 47

Expert Comment

by:for_yan
Comment Utility
This Layout stuff is very important - just one element
may be overlayed by another and you do not see it easily.
So why does it say setLayout(null).
I always use some Layout, I don't understand it

You see your puicture shows only 4 textfields, but in fact you have 5, i guess
jTextField1 is bbeyond the border - try to resize your window
0
 
LVL 47

Expert Comment

by:for_yan
Comment Utility
Any news about the fifth TextField which we do not see?
Let me know - I'm thinking about going home
0
 

Author Comment

by:gbcbr
Comment Utility
I checked all names, there are OK.
It's some general problem, because no one parameter I can set in any jTextField from this method.
Even String value.
But at the same time I can set all these parameters directly.
jTextField1.setBounds(new Rectangle(515, 180, 430, 275));
        jTextField1.setFont(new Font("Lucida Grande", 1, 10));
        jTextField1.setLayout(null);
        jTextField1.setDoubleBuffered(true);
        
        jTextField2.setBounds(new Rectangle(620, 40, 95, 40));
        jTextField2.setOpaque(true);
        jTextField2.setBorder(BorderFactory.createTitledBorder("Ask"));
        jTextField2.setText("test text");

        jTextField3.setBounds(new Rectangle(730, 40, 95, 40));
        jTextField3.setToolTipText("Support 1");
        jTextField3.setBackground(new Color(255, 82, 82));
        jTextField3.setBorder(BorderFactory.createEmptyBorder(1, 1, 1, 1));

        jTextField4.setBounds(new Rectangle(840, 40, 95, 40));
        jTextField4.setEditable(false);
        jTextField4.setBackground(new Color(99, 255, 99));
        jTextField4.setToolTipText("Resistanse 1");
        jTextField4.setOpaque(true);
        jTextField4.setBorder(BorderFactory.createEtchedBorder(EtchedBorder.LOWERED));

        jTextField5.setBounds(new Rectangle(950, 40, 95, 40));
        jTextField5.setBorder(BorderFactory.createTitledBorder(""));
..........................
    public void setTextFieldValue(String eurusd_bid) {

        System.out.println("  .._bid: " + eurusd_bid);
        if (eurusd_bid != null) {
            try {
                System.out.println(" 2 .._bid: " + eurusd_bid);

                jTextField1.setText(eurusd_bid);
                jTextField1.setBorder(BorderFactory.createTitledBorder("Bid"));
                jTextField2.setText(eurusd_bid);
                jTextField3.setText("eurusd_bid");
                jTextField4.setText(eurusd_bid);
                jTextField5.setText("test");
            } catch (Exception p) {
                p.printStackTrace();
            }
        }

Open in new window

DCC3.tiff
0
 
LVL 47

Expert Comment

by:for_yan
Comment Utility
What does this picture show?

I see only setting "test" in your program jTextField5.setText("test");
but there is also "text" and "ask" - when they are set?

And what you mean set all these parameters directly?
Do you see any Java error messages on the console?

You made simultaneously many changes - better to concentrate on one mystery
and do it stepwise.

So, exactly as I wrote you yesterday - it has to work.
The reason it does not is because you are not sure which buttnos you see
in which place. So return to yesterdays code, and if you don't see it on
jTextField1, try absolutely the same but with jTextFiel2, jTextFiled3, etc.

Another option is to chraete them in constructor
with "txt1" "txt2", etc written on them ffor testing.

But do all these testings logically one by one, it jsut has to work if you do
methodically stepwise







0
 
LVL 47

Expert Comment

by:for_yan
Comment Utility
Do you have console to see the errors?
0
Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

 

Author Comment

by:gbcbr
Comment Utility
During your sleeping I work step by step, not
>>You made simultaneously many changes - better to concentrate on one mystery
and do it stepwise.
This is final result.
I'll tell you more, I create separate JFrame class CurrentRates to exclude any influence:
public class CurrentRates extends JFrame {
    private JTextField jTextField1 = new JTextField();
    private JTextField jTextField2 = new JTextField();
    private static final CurrentRates INSTANCE = new CurrentRates();

    public static CurrentRates getInstance() {
        return INSTANCE;
    }

    public CurrentRates() {
        try {
            jbInit();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    private void jbInit() throws Exception {
        this.getContentPane().setLayout(null);
        this.setSize(new Dimension(400, 300));
        
        jTextField1.setBounds(new Rectangle(40, 80, 100, 40));
        jTextField1.setSize(new Dimension(100, 40));
        jTextField1.setText("Field 1");
        
        jTextField2.setBounds(new Rectangle(210, 80, 100, 40));
        jTextField2.setSize(new Dimension(100, 40));
        
        this.getContentPane().add(jTextField2, null);
        this.getContentPane().add(jTextField1, null);
    }

    public void setTextFieldValue(String eurusd_bid) {

        System.out.println("  .._bid: " + eurusd_bid);
        if (eurusd_bid != null) {
            try {
                System.out.println(" 2 .._bid: " + eurusd_bid);

                jTextField2.setText(eurusd_bid);

            } catch (Exception p) {
                p.printStackTrace();
            }
        }
    }
}

Open in new window

PMDS:
if ("EUR/USD".equalsIgnoreCase(symbol.trim())) {
                    bid = bidPx;
                    eurusd_bid = String.valueOf(bid);

                    DecisionCenterControl.getInstance().setTextFieldValue(eurusd_bid);
                    CurrentRates.getInstance().setTextFieldValue(eurusd_bid);

Open in new window

Result: DCC4.tiff
As you can see all String values entered at jbInit method work in both DCC and CR classes, but from setTextFieldValue(String eurusd_bid) method nothing settled, despite of normal passing parameter eurusd_bid into this method in both classes DCC and CR.
As I told, it's some general mistake, but I don't understand where.
From the morning I tried 100's combinations with the same null result.
0
 
LVL 47

Expert Comment

by:for_yan
Comment Utility
Do you see Java errors on the console?
Do you see normal Java Console, not RedirectOutput?
0
 
LVL 47

Expert Comment

by:for_yan
Comment Utility
I'm afraid that printStackTrace() does not redirect correctly.
Add some System.out.println("Error " + p.toString()); into the catch loop, maybe we;ll see something
In general, believe me,  you cannot do real debugging  without  normal console.
All these stuff adds additional uncertainty to what is a process with many uncertainties anyway
 
0
 

Author Comment

by:gbcbr
Comment Utility
RedirectOutput is a normal console view, it just redirect all messages from console into JFrame window.
If I have any error, I can think about what generate it and report here, but unfortunately it's no error messages, everything work perfect except of this b... textfields messages.
As you see I even try to set straight String in DCC
jTextField3.setText("eurusd_bid");
                jTextField4.setText(eurusd_bid);
                jTextField5.setText("test");

Open in new window

, not value of eurusd_bid, even this doesn't work.
Looks like this method - setTextFieldValue(String eurusd_bid) - can't set any parameters into jTextField, I tried different parameters, not only setText. Looks like it blind now.
0
 

Author Comment

by:gbcbr
Comment Utility
no error printed
0
 
LVL 47

Expert Comment

by:for_yan
Comment Utility
It cannot be any mystery - it is always stupid mistake. Add System.println into the catch loop.
 
0
 

Author Comment

by:gbcbr
Comment Utility
>>It cannot be any mystery - it is always stupid mistake.
100000% agree
0
 
LVL 47

Expert Comment

by:for_yan
Comment Utility
Can you post the code in such a way that I can compile it - at least part of it buut self sufficient?
0
 

Author Comment

by:gbcbr
Comment Utility
which classes you want?
0
 

Author Comment

by:gbcbr
Comment Utility
Main.java PMDS.java CurrentRates.java
check if it's enough
0
 
LVL 47

Expert Comment

by:for_yan
Comment Utility
No I of course don't have all those com.fxcm....

If you can strip it to barebone stuff without sthat specifics  and make sure it still does not set the textfiled,
then you can send it to me. If in the process it starts working you can
then identify the step which is the culprit - so I suggest that you start removing all dependencies,
which are not genereal - when you come to layout and njust 2-3 classes of general type wthout com.fxm, etc.
then send to me It is difiicult to find somthing just lookin at the code.
When compiling and running I'm sure we'll find
0
 

Author Comment

by:gbcbr
Comment Utility
I can provide you access to my demo account, otherwise you can't get stream data and test this code. Just give me your private e-mail, Skype or whatever, so I'll not publish this data in public place. It's demo account with fake money, but anyway better don't live open access for everybody.
0
 
LVL 47

Expert Comment

by:for_yan
Comment Utility
You know CurrentRates seems self-sufficient
Let me try
0
 

Author Comment

by:gbcbr
Comment Utility
Anyway, I don't think that you can test it without stream data.
This is a key-point, to get into the field live data.
0
 
LVL 47

Expert Comment

by:for_yan
Comment Utility
This works for me I see one box with Filed1, another box with 1.25 - try if these exact files (without a single change) if they work for you
UseCurrentRates.java
CurrentRates.java
0
 
LVL 47

Expert Comment

by:for_yan
Comment Utility
No, if you see the string before you use setText in one class with System.out.println, then it does not matter wher it came before - stream or no stream
0
 

Author Comment

by:gbcbr
Comment Utility
Yes, this code works properly, as I suppose it should work.
Why mine not?
Looks exactly the same.
0
 
LVL 47

Expert Comment

by:for_yan
Comment Utility
try adding your stuff gradullay to this code stewise - and checking if it works - you'll track the moment when it breaks.
0
 

Author Comment

by:gbcbr
Comment Utility
what you mean gradually?
We have only one similar executing line >>jTextField2.setText(eurusd_bid);
In your case it works, in mine not.
0
 
LVL 47

Expert Comment

by:for_yan
Comment Utility
Well, thats impossible - if so use these files istead of yours - rename the main class into yours and there you go - it works.
0
 

Author Comment

by:gbcbr
Comment Utility
The difference only that you call >>
CurrentRates.getInstance().setTextFieldValue(eurusd_bid);
from the main method
0
 
LVL 47

Expert Comment

by:for_yan
Comment Utility
It works equally well from any place; check this code
UseCurrentRates.java
0
 
LVL 47

Expert Comment

by:for_yan
Comment Utility
Or even this way - without static String
UseCurrentRates.java
0
 

Author Comment

by:gbcbr
Comment Utility
Yes, looks nice, I was expected this output in my code, Why I don't have it?
0
 
LVL 47

Expert Comment

by:for_yan
Comment Utility
At this point it becomes a little metaphysical - you have exactly the same codes and they give differen results - that is impossible.
0
 
LVL 47

Accepted Solution

by:
for_yan earned 500 total points
Comment Utility
Compare two codes - you must see the difference
0
 

Author Comment

by:gbcbr
Comment Utility
The biggest difference what I found is that in your code you don't create new class CR from the main method, just call the instance, but anyway it appear as visible with value of eurusd_bid. If I comment from my main
//        cr = new CurrentRates();
//        cr.setVisible(true);
this window doesn't appear at all.
Looks like you initiate this class by calling instance from the method, but I can't do it.
0
 

Author Comment

by:gbcbr
Comment Utility
Let's drink 100 grams for solution.
I've commented from my main
//        cr = new CurrentRates();
//        cr.setVisible(true);
and add to CR/jbInit/this.setVisible(true);
and as soon new data arrive, it starts to appear into textfield2.
Now is my shift to sleep.
Thank you for the help!
0
 
LVL 47

Expert Comment

by:for_yan
Comment Utility
OK. Good it finally worked!
0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
The viewer will learn how to implement Singleton Design Pattern in Java.

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now