As stated in the title i need to move the label for the text box to be above the box and not to the side. attached i have a picutres of what i mean. what i have vs what i want i have tried searching for it but i cannot seem to find the answer im looking for/not exactly sure what to look up. I have tried using JFrame but it made a separate window unless i need to make the entire GUI a JFrame for me to get the result i want?
Also the actionPerformed method has things but it is irrelevant to the question but displays correctly still.
import java.awt.event.\*;
import javax.swing.\*;
import java.text.DecimalFormat;
public class Project4 extends JFrame implements ActionListener {
private JTextArea taArea = new JTextArea("", 30, 20);
ButtonGroup group = new ButtonGroup();
JTextField name = new JTextField(20);
boolean ch = false;
boolean pep = false;
boolean sup = false;
boolean veg = false;
DecimalFormat df = new DecimalFormat("##.00");
double cost = 0.0;
public Project4() {
initUI();
}
public final void initUI() {
JPanel panel1 = new JPanel();
JPanel panel2 = new JPanel();
JPanel panel3 = new JPanel();
JPanel panel4 = new JPanel();
JPanel panel5 = new JPanel();
getContentPane().add(panel1, "North");
getContentPane().add(panel2, "West");
getContentPane().add(panel3, "Center");
getContentPane().add(panel4, "East");
panel4.setLayout(new BoxLayout(panel4, BoxLayout.Y_AXIS));
getContentPane().add(panel5, "South");
JButton button = new JButton("Place Order");
button.addActionListener(this);
panel5.add(button);
JButton button2 = new JButton("Clear");
button2.addActionListener(this);
panel5.add(button2);
panel3.add(taArea);
JCheckBox checkBox1 = new JCheckBox("Cheese Pizza") ;
checkBox1.addActionListener(this);
panel4.add(checkBox1);
JCheckBox checkBox2 = new JCheckBox("Pepperoni Pizza");
checkBox2.addActionListener(this);
panel4.add(checkBox2);
JCheckBox checkBox3 = new JCheckBox("Supreme Pizza");
checkBox3.addActionListener(this);
panel4.add(checkBox3);
JCheckBox checkBox4 = new JCheckBox("Vegetarian Pizza");
checkBox4.addActionListener(this);
panel4.add(checkBox4);
JRadioButton radioButton1 = new JRadioButton("Pick Up");
group.add(radioButton1);
radioButton1.addActionListener(this);
panel1.add(radioButton1);
JRadioButton radioButton2 = new JRadioButton("Delivery");
group.add(radioButton2);
radioButton2.addActionListener(this);
panel1.add(radioButton2);
JLabel name_label = new JLabel("Name on Order");
name.addActionListener(this);
panel5.add(name_label);
panel5.add(name);
setSize(600, 300);
setTitle("Pizza to Order");
setDefaultCloseOperation(EXIT_ON_CLOSE);
}
public void actionPerformed(ActionEvent action) {
}
public static void main(String[] args) {
Project4 ex = new Project4();
ex.setVisible(true);
}
}
You can use a nested JPanel with another layout in order to achieve that. I would go with BorderLayout here. You can also other layouts that allow vertical orientation. Visiting the visual guide to Layout Managers will help you spot them.
JLabel name_label = new JLabel("Name on Order");
name.addActionListener(this);
JPanel verticalNestedPanel = new JPanel(new BorderLayout());
verticalNestedPanel.add(name_label, BorderLayout.PAGE_START);
verticalNestedPanel.add(name, BorderLayout.PAGE_END);
panel5.add(verticalNestedPanel);
Essentially, I am trying to add a home screen with 4 buttons, 3 difficulty buttons and a play button. I add the buttons to a JPanel and add the JPanel with a BoxLayout of Center. Why does the buttons still go all the way off to the right? Setting the icon for a JLabel on and adding it to the home screen JPanel is a possible mess up the flow of components? I want the difficulty buttons to be on top of the of the gif with the Play button at the bottom. Thanks for your help.
//container
snake = new JFrame();
snake.setLayout(new BorderLayout());
//home screen panel
homeScreen = new JPanel();
homeScreen.setLayout(new BoxLayout(homeScreen, BoxLayout.X_AXIS));
homeScreen.setPreferredSize(new Dimension(320, 320));
JLabel bg = new JLabel();
ImageIcon icon = new ImageIcon("HomeBG.gif");
icon.getImage().flush();
bg.setIcon(icon);
homeScreen.add(bg);
easy = new JButton("Easy");
medium = new JButton("Medium");
hard = new JButton("Hard");
play = new JButton("Play");
//button listeners code here
homeScreen.add(easy);
homeScreen.add(medium);
homeScreen.add(hard);
homeScreen.add(play);
snake.add(homeScreen, BorderLayout.CENTER);
snake.setTitle("Snake Game");
snake.pack();
snake.setVisible(true);
snake.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
You need to change your code as shown below.
snake = new JFrame();
snake.setLayout(new BorderLayout());
//home screen panel
homeScreen = new JPanel(new BorderLayout());
//homeScreen.setLayout(new BoxLayout(homeScreen, BoxLayout.X_AXIS));
homeScreen.setPreferredSize(new Dimension(320, 320)); // probably you need to remove this line!
JLabel bg = new JLabel();
ImageIcon icon = new ImageIcon("HomeBG.gif");
icon.getImage().flush();
bg.setIcon(icon);
homeScreen.add(bg);
easy = new JButton("Easy");
medium = new JButton("Medium");
hard = new JButton("Hard");
play = new JButton("Play");
//button listeners code here
JPanel buttonsPanel = new JPanel(new FlowLayout(FlowLayout.CENTER));
buttonsPanel.add(easy);
buttonsPanel.add(medium);
buttonsPanel.add(hard);
buttonsPanel.add(play);
homeScreen.add(buttonsPanel, BorderLayout.NORTH);
snake.add(homeScreen, BorderLayout.CENTER);
snake.setTitle("Snake Game");
snake.pack();
snake.setVisible(true);
snake.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
I would use a compound layout for this. Put the level buttons in a (panel in a) FlowLayout. Put the play button in a 2nd FlowLayout. Add those panels to the PAGE_START and PAGE_END of a BorderLayout. Add a label containing the GIF to the CENTER of the same border layout.
BTW - the level buttons should be radio buttons (in a button group - BNI).
import java.awt.*;
import java.awt.image.BufferedImage;
import javax.swing.*;
import javax.swing.border.EmptyBorder;
public class LayoutManagersWithIcon {
private JComponent ui = null;
LayoutManagersWithIcon() {
initUI();
}
public void initUI() {
if (ui!=null) return;
ui = new JPanel(new BorderLayout(4,4));
ui.setBorder(new EmptyBorder(4,4,4,4));
JPanel levelPanel = new JPanel(new FlowLayout(FlowLayout.CENTER, 5, 5));
ui.add(levelPanel, BorderLayout.PAGE_START);
levelPanel.add(new JRadioButton("Easy"));
levelPanel.add(new JRadioButton("Medium"));
levelPanel.add(new JRadioButton("Hard"));
JPanel startPanel = new JPanel(new FlowLayout(FlowLayout.CENTER, 5, 5));
ui.add(startPanel, BorderLayout.PAGE_END);
startPanel.add(new JButton("Play"));
JLabel label = new JLabel(new ImageIcon(
new BufferedImage(400, 100, BufferedImage.TYPE_INT_RGB)));
ui.add(label);
}
public JComponent getUI() {
return ui;
}
public static void main(String[] args) {
Runnable r = new Runnable() {
#Override
public void run() {
try {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
} catch (Exception useDefault) {
}
LayoutManagersWithIcon o = new LayoutManagersWithIcon();
JFrame f = new JFrame(o.getClass().getSimpleName());
f.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
f.setLocationByPlatform(true);
f.setContentPane(o.getUI());
f.pack();
f.setMinimumSize(f.getSize());
f.setVisible(true);
}
};
SwingUtilities.invokeLater(r);
}
}
I'm a third grade computer engineer student and I'm trying to do a game project. I added a background image to my JFrame. And I tried to make the other panels transparent which I added to frame. I use alpha value for this, Ex: new Color(0,0,0,125). I olso use cardLayout in my program and for every calling a new segment or new page at the center panel; alphavalue takes the whole panels transparency and implement it to the selected panel and it creates a problem. Example : I have 7 buttons at left panel and when I click crimes button, crime panel comes to the center panel and left panel comes inside of center panel with buttons again(transparently).
I have 16 classes, so I only added main class.
Sorry for bad grammar. I hope you can understand me and help me.
import java.util.*;
import javax.swing.*;
import javax.swing.border.*;
import java.awt.*;
import java.awt.event.*;
public class TheMafia {
public static ImageIcon scale(ImageIcon i,int x,int y) {
Image img = i.getImage();
Image newimg = img.getScaledInstance(x,y,Image.SCALE_SMOOTH);
i = new ImageIcon(newimg);
return i;
}
public static void setButton (JButton b,int x,int y) {
b.setPreferredSize(new Dimension(x,y));
b.setBackground(Color.gray);
b.setForeground(Color.white);
b.setBorder(new LineBorder(Color.black,1));
b.setFont(new Font("Serif",Font.BOLD,18));
}
public static void main(String[] args) {
ImageIcon home2 = new ImageIcon("home.jpg");
home2 = scale(home2,1366,768);
JFrame theMafia = new JFrame();
theMafia.setTitle("The Mafia Game - Best game in the world!");
JPanel p1 = new JPanel();
JPanel p2 = new JPanel();
theMafia.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
theMafia.setContentPane(new JLabel(home2));
theMafia.setLayout(new BorderLayout());
//theMafia.setLayout(new FlowLayout());
//theMafia.setExtendedState(JFrame.MAXIMIZED_BOTH);
theMafia.setSize(800,700);
theMafia.setLocationRelativeTo(null);
theMafia.setVisible(true);
p1.setBackground(new Color(0,0,0,35));
p2.setBackground(new Color(0,0,0,65));
p1.setPreferredSize(new Dimension(250,150));
p2.setPreferredSize(new Dimension(250,150));
//theMafia.add(p1);
//theMafia.add(p2);
// kullanıcı oluşturuldu
User u1 = new User();
// suçlar oluşturuldu
Crime c1 = new Crime();
c1.setName("Yaşlı Kadın");
c1.setDifficulty(5);
c1.setStrength(1);
c1.setMoney(11);
Crime c2 = new Crime();
c2.setName("Dükkan Hırsızlığı");
c2.setDifficulty(10);
c2.setStrength(3);
c2.setMoney(67);
Crime c3 = new Crime();
c3.setName("Araba Hırsızlığı");
c3.setDifficulty(20);
c3.setStrength(6);
c3.setMoney(133);
// suçun seçilmesi
final JPanel crimes = new JPanel(new CardLayout());
//crimes.setBackground(new Color(0,0,0,65));
ImageIcon suçişle = new ImageIcon("suçişle.jpg");
suçişle = scale(suçişle,50,50);
JButton yap = new JButton("Suçu işle!",suçişle);
setButton(yap,100,65);
JPanel crime1 = new JPanel(new GridLayout(2,1));
crime1.setBackground(new Color(0,0,0,35));
crime1.setForeground(Color.white);
JLabel crime1Info = new JLabel("Suç : "+c1.getName()+"\n Para : "+c1.getMoney()+"\n Yapabilme ihtimali : "+c1.getCapable()+"\n Güç : "+c1.getStrength());
crime1Info.setFont(new Font("Serif",Font.BOLD,15));
crime1.add(crime1Info);
crime1.add(yap);
JPanel crime2 = new JPanel(new GridLayout(2,1));
crime2.setBackground(new Color(0,0,0,35));
crime2.setForeground(Color.white);
JLabel crime2Info = new JLabel("Suç : "+c2.getName()+"\n Para : "+c2.getMoney()+"\n Yapabilme ihtimali : "+c2.getCapable()+"\n Güç : "+c2.getStrength());
crime2Info.setFont(new Font("Serif",Font.BOLD,15));
crime2.add(crime2Info);
crime2.add(yap);
JPanel crime3 = new JPanel();
crime3.setBackground(new Color(0,0,0,35));
crime3.setForeground(Color.white);
JLabel crime3Info = new JLabel("Suç : "+c3.getName()+"\n Para : "+c3.getMoney()+"\n Yapabilme ihtimali : "+c3.getCapable()+"\n Güç : "+c3.getStrength());
crime2Info.setFont(new Font("Serif",Font.BOLD,15));
crime3.add(crime3Info);
crime3.add(yap);
crimes.add(crime1,c1.getName());
crimes.add(crime2,c2.getName());
crimes.add(crime3,c3.getName());
String crimesNames [] = {c1.getName(),c2.getName(),c3.getName()};
JComboBox crimesbox = new JComboBox(crimesNames);
crimesbox.setEditable(false);
crimesbox.addItemListener(new ItemListener() {
public void itemStateChanged(ItemEvent evt) {
CardLayout cl = (CardLayout) (crimes.getLayout());
cl.show(crimes,(String)evt.getItem());
}
});
// menu
final JPanel menus = new JPanel(new CardLayout());
//menus.setBackground(new Color(0,0,0,35));
// crime
JPanel crime = new JPanel(new BorderLayout());
crime.setBackground(new Color(0,0,0,35));
crime.add(crimesbox,BorderLayout.PAGE_START);
crime.add(crimes,BorderLayout.SOUTH);
ImageIcon crimeimage = new ImageIcon("thief.png");
crimeimage = scale(crimeimage,50,50);
final JButton crimeButton = new JButton("Suçlar",crimeimage);
setButton(crimeButton,178,76);
crimeButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
CardLayout cl = (CardLayout) (menus.getLayout());
if (e.getSource() == crimeButton) {
cl.show(menus,"suç");
}
}
});
// weapon shop
JPanel weaponShop = new JPanel();
//weaponShop.setBackground(new Color(0,0,0,125));
final JButton weaponShopButton = new JButton("Silah Dükkanı");
setButton(weaponShopButton,178,76);
// building
JPanel buildingPanel = new JPanel();
//buildingPanel.setBackground(new Color(0,0,0,125));
final JButton buildingButton = new JButton("Binalar");
setButton(buildingButton,178,76);
// nightlife
JPanel nightLife = new JPanel();
//nightLife.setBackground(new Color(0,0,0,35));
final JButton nightLifeButton = new JButton("Gece Hayatı");
setButton(nightLifeButton,178,76);
// treatment center
JPanel treatmentCenter = new JPanel();
//treatmentCenter.setBackground(new Color(0,0,0,35));
final JButton treatmentCenterButton = new JButton("Tedavi Merkezi");
setButton(treatmentCenterButton,178,76);
// casino
JPanel casinoPanel = new JPanel();
//casinoPanel.setBackground(new Color(0,0,0,35));
final JButton casinoButton = new JButton("Gazino");
setButton(casinoButton,178,76);
// home page
JPanel home = new JPanel();
home.setBackground(new Color(0,0,0,35));
ImageIcon homeimage = new ImageIcon("home.jpg");
homeimage = scale(homeimage,1200,800);
JLabel homelabel= new JLabel();
home.add(homelabel);
ImageIcon homeicon = new ImageIcon("home_icon.png");
homeicon = scale(homeicon,50,50);
final JButton homeButton = new JButton("Home",homeicon);
setButton(homeButton,178,76);
homeButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
CardLayout cl = (CardLayout) (menus.getLayout());
if (e.getSource() == homeButton) {
cl.show(menus,"home");
}
}
});
menus.add(home,"home");
menus.add(crime,"suç");
menus.add(weaponShop,"silahDükkanı");
menus.add(buildingPanel,"bina");
menus.add(nightLife,"geceHayatı");
menus.add(treatmentCenter,"TedaviMerkezi");
menus.add(casinoPanel,"gazino");
Color grisi=new Color(13,13,13);
JPanel menusButton = new JPanel(new GridLayout(10,1));
//menusButton.setBackground(grisi);
menusButton.add(homeButton);
menusButton.add(crimeButton);
menusButton.add(weaponShopButton);
menusButton.add(buildingButton);
menusButton.add(nightLifeButton);
menusButton.add(treatmentCenterButton);
menusButton.add(casinoButton);
menusButton.setOpaque(false);
theMafia.add(menusButton,BorderLayout.WEST);
theMafia.add(menus,BorderLayout.CENTER);
}
}
Swing does not handle transparent background properly. Swing expects components to be either opaque or non-opaque and the transparency causes a problem because the component is neither.
Check out Background With Transparency for more information and a couple of solutions to solve the problem.
UPDATE UPDATE UPDATE
thank you :))) I did What u told me
I put frame.add(FirstScreen) first
they appeared .....
but now the events are not working , why???????
Can u help me again???
I'm sorry ........
..................
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
public class InterFace extends JFrame implements ActionListener,ItemListener
{
JFrame frame = new JFrame("Al-murshed Dictionary");
JPanel FirstScreen = new JPanel();
JPanel SecondScreen = new JPanel();
JPanel ThirdScreen = new JPanel();
JPanel ForthScreen = new JPanel();
JButton Translate = new JButton ("Translate");
JButton About = new JButton ("About");
JButton Help= new JButton ("Help");
JButton Quit= new JButton ("Quit");
JButton Quit1= new JButton ("Quit");
JButton Quit2= new JButton ("Quit");
JButton Back= new JButton ("Back");
JButton Back1= new JButton ("Back");
JTextField WordField = new JTextField("Write Your Word Here",50);
JTextArea ArbField = new JTextArea(40,40);
JTextArea EngField = new JTextArea(40,40);
CardLayout c1 = new CardLayout ();
public InterFace()
{
FirstScreen.setLayout(c1);
SecondScreen.add(WordField);
SecondScreen.add(Translate);
ThirdScreen.add(Back);
ForthScreen.add(Back1);
ThirdScreen.add(Quit1);
ForthScreen.add(Quit2);
FirstScreen.add(SecondScreen,"1");
FirstScreen.add(ThirdScreen,"2");
FirstScreen.add(ForthScreen,"3");
JPanel controlButtons = new JPanel();
controlButtons.add(Help);
controlButtons.add(About);
controlButtons.add(Quit);
JPanel wordTranslate = new JPanel();
wordTranslate.add(WordField);
wordTranslate.add(Translate);
JPanel controlTextArea = new JPanel();
controlTextArea.add(EngField);
controlTextArea.add(ArbField);
c1.show(FirstScreen,"1");
About.addActionListener(this);
Back.addActionListener(this);
Help.addActionListener(this);
Back1.addActionListener(this);
Quit.addActionListener(this);
Quit1.addActionListener(this);
Quit2.addActionListener(this);
frame.add(FirstScreen);
Container pane = frame.getContentPane();
pane.add(wordTranslate, BorderLayout.NORTH);
pane.add(controlTextArea, BorderLayout.CENTER);
pane.add(controlButtons, BorderLayout.PAGE_END);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.pack();
frame.setVisible(true);
}
//EventHandler
public void actionPerformed(ActionEvent e)
{
if(e.getSource()==About)
c1.show(FirstScreen,"2");
if(e.getSource()==Help)
c1.show(FirstScreen,"3");
if(e.getSource()==Quit)
System.exit(0);
if(e.getSource()==Quit1)
System.exit(0);
if(e.getSource()==Quit2)
System.exit(0);
if(e.getSource()==Back)
c1.show(FirstScreen,"1");
if(e.getSource()==Back1)
c1.show(FirstScreen,"1");
}
public static void main (String args[])
{
InterFace d = new InterFace ();
}
}
pane.add(controlTextArea, BorderLayout.CENTER);
...
frame.add(FirstScreen);
First you add the text area panel to the content pane.
Then you add the "FirstScreen" to the frame.
The problem is that when you add the "FirstScreen" to the frame you are really adding it to the content pane of the frame. So basically you are replacing the text area panel with the first screen.
Also, follow Java naming conventions. Variable names should NOT start with an upper case character.
There is no errors but when I Run it the content that I added into the JPanel won't appear, only the one not inside the JPanel appear.
import javax.swing.*;
import java.awt.*;
public class SimpleGUI extends JFrame
{
public static void main(String arg[])
{
SimpleGUI f = new SimpleGUI("GUI components");
f.setSize(600,200);
f.setVisible(true);
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
SimpleGUI(String s)
{
setTitle(s);
setLayout(new GridLayout(3,2));
JLabel msg = new JLabel("FINAL EXAM IS JUST AROUND THE CORNER!");
JButton bt = new JButton("OK");
JLabel lb = new JLabel ("Enter your name:");
JTextField tf = new JTextField("<type name here>");
JLabel lb2 = new JLabel ("Enter age:");
JTextField tf2= new JTextField(10);
tf2.setHorizontalAlignment(JTextField.RIGHT);
JCheckBox cb = new JCheckBox("Bold",true);
JRadioButton rb1 = new JRadioButton("Red");
JTextArea ta = new JTextArea(5,20);
JList list = new JList(new Object[] {"Block A", "Block B"});
JComboBox jcb = new JComboBox(new Object[] {"Hello", "Bye"});
ImageIcon ic = new ImageIcon("music.gif");
JButton newbt = new JButton("Play",ic);
newbt.setVerticalTextPosition(JButton.TOP);
newbt.setHorizontalTextPosition(JButton.CENTER);
JPanel p1 = new JPanel();
p1.setLayout(new BorderLayout());
p1.add(lb, BorderLayout.WEST);
p1.add(tf, BorderLayout.CENTER);
p1.add(cb, BorderLayout.EAST);
JPanel p2 = new JPanel();
p2.setLayout(new BorderLayout());
p2.add(lb2, BorderLayout.WEST);
p2.add(tf2, BorderLayout.CENTER);
p2.add(rb1, BorderLayout.EAST);
JPanel p3 = new JPanel();
p3.setLayout(new BorderLayout());
p3.add(jcb);
add(ta);
add(list);
p3.add(newbt, BorderLayout.NORTH);
add(msg);
p3.add(bt, BorderLayout.SOUTH);
}
}
I've updated your code. Have a look at this version:
import javax.swing.*;
import java.awt.*;
public class SimpleGUI extends JFrame {
public static void main(String arg[]) {
SwingUtilities.invokeLater(new Runnable() {
#Override
public void run() {
SimpleGUI f = new SimpleGUI("GUI components");
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
});
}
public SimpleGUI(String s) {
setTitle(s);
setLayout(new GridLayout(3, 2));
JLabel msg = new JLabel("FINAL EXAM IS JUST AROUND THE CORNER!");
JButton bt = new JButton("OK");
JLabel lb = new JLabel("Enter your name:");
JTextField tf = new JTextField("<type name here>");
JLabel lb2 = new JLabel("Enter age:");
JTextField tf2 = new JTextField(10);
tf2.setHorizontalAlignment(JTextField.RIGHT);
JCheckBox cb = new JCheckBox("Bold", true);
JRadioButton rb1 = new JRadioButton("Red");
JTextArea ta = new JTextArea(5, 20);
JList list = new JList(new Object[]{"Block A", "Block B"});
JComboBox jcb = new JComboBox(new Object[]{"Hello", "Bye"});
ImageIcon ic = new ImageIcon("music.gif");
JButton newbt = new JButton("Play", ic);
newbt.setVerticalTextPosition(JButton.TOP);
newbt.setHorizontalTextPosition(JButton.CENTER);
JPanel p1 = new JPanel();
p1.setLayout(new BorderLayout());
p1.add(lb, BorderLayout.WEST);
p1.add(tf, BorderLayout.CENTER);
p1.add(cb, BorderLayout.EAST);
JPanel p2 = new JPanel();
p2.setLayout(new BorderLayout());
p2.add(lb2, BorderLayout.WEST);
p2.add(tf2, BorderLayout.CENTER);
p2.add(rb1, BorderLayout.EAST);
JPanel p3 = new JPanel();
p3.setLayout(new BorderLayout());
p3.add(jcb);
add(ta);
add(list);
p3.add(newbt, BorderLayout.NORTH);
add(msg);
p3.add(bt, BorderLayout.SOUTH);
/**
* Need to add the following lines
*/
this.add(p1);
this.add(p2);
this.add(p3);
this.pack();
this.setVisible(true);
}
}
A couple of pointers:
You need to add your components to your JFrame for them to actually show up.
Any updates to the user interface must happen on the event dispatch thread. Consequently you would notice that I've added a SwingUtilites.invokeLater() to the main. Have a look at this article to understand "Threading with Swing"
Where you you add your panels to the frame? Also, forgotten my java "rules and regulations": do you need to call "super()"?