need some java help badly

badatjava

Junior Member
Apr 17, 2002
1
0
0
i need to write a program that uses tabbedpane and each tab displays a flag
i have this much and have no clue where to go from here or if im heading in the right direction

import javax.swing.JTabbedPane;
import javax.swing.ImageIcon;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JFrame;

import java.awt.*;
import java.awt.event.*;

public class TabbedPaneDemo extends JPanel {
public TabbedPaneDemo() {

JTabbedPane tabbedPane = new JTabbedPane();

ImageIcon icon1 = new ImageIcon("images/us.gif");

tabbedPane.addTab("USA", icon1);
tabbedPane.setSelectedIndex(0);

ImageIcon icon2 = new ImageIcon("images/uk.gif");
tabbedPane.addTab("UK", icon2);

ImageIcon icon3 = new ImageIcon("images/germany.gif");
tabbedPane.addTab("Germany", icon3);

ImageIcon icon4 = new ImageIcon("images/ca.gif");
tabbedPane.addTab("Canada", icon4);

ImageIcon icon5 = new ImageIcon("images/china.gif");
tabbedPane.addTab("China", icon5);

ImageIcon icon6 = new ImageIcon("images/india.gif");
tabbedPane.addTab("India", icon6);

//Add the tabbed pane to this panel.
setLayout(new GridLayout(1, 1));
add(tabbedPane);
}

public static void main(String[] args) {
JFrame frame = new JFrame("TabbedPaneDemo");
frame.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {System.exit(0);}
});

frame.getContentPane().add(new TabbedPaneDemo(),
BorderLayout.CENTER);
frame.setSize(400, 125);
frame.setVisible(true);
}
}


~Marsha
 

manly

Lifer
Jan 25, 2000
13,086
3,850
136
You're on the right track, but I don't think that code compiles.

Consult the Java Platform API JavaDocs to see the usage of the addTab method. Specifically, each tab you create must reference a visual Component.

There's also a JTabbedPane section in The Java Tutorial.

I haven't done Swing programming in a while, but it's quite a nice API to program in. Let me know if you need more pointers.