0

I have two JFrames, in my second one I added a private String and made a setter() for it:

public class FProduit extends javax.swing.JFrame {

private String CAT;

public void setCAT(String C) {
    this.CAT = C;
}
/*
***
*/
}

in my First JFrame, I have this:

FProduit Fp=new FProduit();

String cat=ButtonDisplay.getText().toString();
JOptionPane.showMessageDialog(null,cat);

Fp.setCAT(cat);
Fp.setVisible(true);

Which displays my String cat,and calls the second JFrame but when I try to display it in my SECOND Jframe, like this:

public FProduit() {
initComponents();
JOptionPane.showMessageDialog(null,this.CAT);

}

all I get is a null String.

Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
user3089045
  • 199
  • 1
  • 4
  • 12
  • your code doesn't make sense. u used cat in a first section which looks like your main program and u reused it in the constructor of JFrame again?!!!how these are 2 different jframes?!!!!! – Kick Buttowski Dec 11 '13 at 00:24
  • 2
    If your neighbor buys a big-screen TV and sets it up in his living room, does a matching one magically appear in your living room? – Hot Licks Dec 11 '13 at 01:13
  • 1) For better help sooner, post an [SSCCE](http://sscce.org/). 2) See [The Use of Multiple JFrames, Good/Bad Practice?](http://stackoverflow.com/a/9554657/418556) 3) Use a consistent and logical indent for code blocks. The indentation of the code is intended to help people understand the program flow. – Andrew Thompson Dec 11 '13 at 01:13
  • I actually referred to this: http://stackoverflow.com/a/10509413/3089045 I did exactly the same, in my code: 'cat' is a local variable in my first JFrame, and CAT is ANOTHER private variable in the class FProduit (which is my SECOND JFrame). I did exactly the same as the answer I linked above, only using strings not ints. Sorry me if I can't explain well enough my question (english is my third language) – user3089045 Dec 11 '13 at 09:17

0 Answers0