15 February 2002 - java_dev (original) (raw)
I am currently taking a Java course at a local college here and am having a problem. I usually can pick up programming languages faster, but that really isn't the point of this post. :)
We are writing an application that has several JPanels. It starts out with a JFrame with JpanelA inside it which holds JPanelB with 2 or more Panels inside that to swap out though the running of the application. I can get a label to show up in JPanelA if I call it through the JFrame class. But we need each panel to have its own class and I can't seem to get this same label to show up when JPanelA is it's own class. Here is my code:
public class B2C4 extends JFrame
{
private JButton wholesaleButton,
retailButton,
submitButton,
cancelButton,
exitButton;
private Container contentPane;
private JLabel testLabel;
public B2C4()
{
setSize(650,450);
JPanel jpanelA=new JPanelA();
getContentPane().add(jpanelA);
}
public static void main (String args[])
{
B2C4 app=new B2C4();
app.addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent e)
{
System.exit(0);
}
});
app.setVisible(true);
}
class JPanelA extends JPanel
{
public JPanelA()
{
getContentPane().add(new JLabel("Name"));
}
}
}
Any help would be great and sorry for such a probably simple question. I hope I explained myself enough. Thanks.