Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

using custom JPanel class in JApplet  RSS feed

 
Alex Kravets
Ranch Hand
Posts: 476
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey,
I created a class that extends JPanel. This class (tPanel) I want to use in my JApplet (ft). But when I make an instance of tPanel and add it to a container of ft, it does not show up in the applet. What's going on here?
Here is the code:
tPanel.java:
------------
import java.applet.*;
import java.awt.*;
import java.awt.event.*;
import java.net.*;
import javax.swing.*;
public class tPanel extends JPanel{
private JButton button;
private JPanel jp;
public tPanel(){
jp = new JPanel();
button = new JButton("GO");
button.setBackground(new Color(255,255,255));
jp.add(button);
add(jp);
}
public void testStr(){
System.out.println("Testing tPanel...");
}
}
ft.java
-------
public class ft extends JApplet{
public void init(){
container = getContentPane();
tPanel uf = new tPanel();
JPanel p2 = new JPanel();
uf.testStr(); // it does print this out in console
p2.add(uf);
container.add(p2);
JPanel p = new JPanel();
p.add(new JLabel("BOO")); // shows this 'BOO' in applet, but not tPanel
container.add(p);
}
}
 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, the first thing I notice is that you have: container = getContentPane() and you never declare container. The second thing is the fact that you never add uf (tPanel) to anything. You instantiate it, but then never do anything with it,
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!