没有什么是出现在Java相当新,我已经创建了一个主页和几个按钮,当我点击其中一个按钮时,它将主页面板可见性设置为false,打开一个新类并设置该类的Jpanel可见。当我切换JPanels
homePanel.setVisible(false);
Goodsin Barcode = new Goodsin();
Goodsin.setVisible(true);
但是,一旦它打开新的类“Goodsin”它不会显示任何按钮或TextFileds。我知道它是打开新的类作为System.out.println打印到控制台,但没有显示在JFrame中,我不知道为什么。
这是我的新类
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
public class Goodsin {
public JPanel Goodsin;
public JTextField item1;
public String code;
public JButton btn1;
public Goodsin() {
System.out.println("TEST");
Goodsin = new JPanel();
item1 = new JTextField(10);
btn1 = new JButton("Look up Barcode");
Goodsin.setVisible(true);
Goodsin.add(item1);
item1.setSize(80, 30);
Goodsin.add(btn1);
btn1.setSize(80, 30);
}
public void getString(String code) {
System.out.println(code);
}
}
我敢肯定,我没有做与Jpanel正确的东西或添加的文本框或按钮,但我已经看到了所有的答案至今havnt工作的代码。
如何创建一个名为Goodsin的属性? – Leo
如果Goodsin尚未添加,则设置其可见性将无意义。 – Neil