当我从Jframe传递给Jframe时,为什么我的字符串变为null?

时间:2013-12-11 00:14:43

标签: java string swing jframe arguments

我有两个JFrame,在我的第二个JFrame中我添加了一个私有String并为它创建了一个setter():

public class FProduit extends javax.swing.JFrame {

private String CAT;

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

在我的第一个JFrame中,我有这个:

FProduit Fp=new FProduit();

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

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

显示我的String cat,并调用第二个JFrame 但当我尝试在我的SECOND Jframe中显示它时,就像这样:

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

}

我得到的只是一个空字符串。

0 个答案:

没有答案