extends JPanel

Hi all,

I'm using JPanel's in my code. But now i wanna make a class a JPanel like: public [class] extends JPanel.

But how can i use the JPanel in a another code? I tried this:

//In main-class with frame

new Times_of_War_Menu();

//And in the 'extends JPanel' class

import java.awt.*;

import java.awt.event.*;

import javax.swing.*;

publicclass Times_of_War_Ingameextends JPanel

{

public Times_of_War_Ingame()

{

this.setLayout(new BorderLayout());

//Background for status bar//

JPanel Status_Panel =new JPanel();

Status_Panel.setLayout(new FlowLayout(0, 0, 0));

Icon status_1 =new ImageIcon("C:\\Program Files\\xampp\\htdocs\\xampp\\Templates\\Java\\Times_of_War\\materials\\status_bar\\status_background.jpg");

JLabel status_label_1 =new JLabel(status_1);

Status_Panel.add(status_label_1);

this.add(Status_Panel, BorderLayout.PAGE_START);

//Bars ready//

//Content//

JPanel Content_Panel =new JPanel();

Content_Panel.setLayout(new FlowLayout(0, 0, 0));

Icon background =new ImageIcon("C:\\Program Files\\xampp\\htdocs\\xampp\\Templates\\Java\\Times_of_War\\materials\\backgrounds\\dirt.jpg");

JLabel background_label =new JLabel(background);

Content_Panel.add(background_label);

this.add(Content_Panel, BorderLayout.LINE_START);

//Content ready//

}

}

But i didn't work! Could anyone fix it for me?!

Thx,

Jasper

[2370 byte] By [Jasper91a] at [2007-11-26 16:29:10]
# 1

> But i didn't work! Could anyone fix it for me?!

>

"didn't work" doesn't tell us much. What happened? Did it not compile? If not, what was the compilation error? Did it compile, but the program did not behave as expected when you ran it? Did it throw an exception when you ran it? If so, what did the exception stack trace say?

With that rant out of the way (*), can it have something to do with the fact that your class, as posted, is called "Times_of_War_Ingame", and not "Times_of_War_Menu"?

(*) And I'm not even going to start on the next rant, the why-are-you-extending-JPanel one.

Torgila at 2007-7-8 22:53:33 > top of Java-index,Desktop,Core GUI APIs...
# 2

1) Respond to your old postings before creating new postings (if you want help in the future)

> I tried this new Times_of_War_Menu();

Thats not even the name of your class

By the way I would read the Swing tutorial on "How to Use Icons" for a better way of loading images. The file path is a little bit long and hardcoded.

camickra at 2007-7-8 22:53:33 > top of Java-index,Desktop,Core GUI APIs...
# 3
Hi,There are 2 classes (menu and ingame) with the same content (still have to change it).And yes, it compile's and there are no Exceptions! But, it doesn't show anything:sGr,Jasper
Jasper91a at 2007-7-8 22:53:33 > top of Java-index,Desktop,Core GUI APIs...
# 4
I'm assuming its not something as simple as .setVisible(true) ...you haven't mentioned that line above?
AberStudenta at 2007-7-8 22:53:33 > top of Java-index,Desktop,Core GUI APIs...