Advertisement
rohitmehra

Untitled

Dec 17th, 2012
17
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.29 KB | None | 0 0
  1. // Demonstrate JTabbedPane.
  2. import javax.swing.*;
  3. /*
  4. <applet code="JTabbedPaneDemo" width=400 height=100>
  5. </applet>
  6. */
  7. public class JTabbedPaneDemo extends JApplet {
  8. public void init() {
  9. try {
  10. SwingUtilities.invokeAndWait(
  11. new Runnable() {
  12. public void run() {
  13. makeGUI();
  14. }
  15. }
  16. );
  17. } catch (Exception exc) {
  18. System.out.println("Can't create because of " + exc);
  19. }
  20. }
  21. private void makeGUI() {
  22. JTabbedPane jtp = new JTabbedPane();
  23. jtp.addTab("Cities", new CitiesPanel());
  24. jtp.addTab("Colors", new ColorsPanel());
  25. jtp.addTab("Flavors", new FlavorsPanel());
  26. add(jtp);
  27. }
  28. }
  29. // Make the panels that will be added to the tabbed pane.
  30. class CitiesPanel extends JPanel {
  31. public CitiesPanel() {
  32. JButton b1 = new JButton("New York");
  33. add(b1);
  34. JButton b2 = new JButton("London");
  35. add(b2);
  36. JButton b3 = new JButton("Hong Kong");
  37. add(b3);
  38. JButton b4 = new JButton("Tokyo");
  39. add(b4);
  40. }
  41. }
  42. class ColorsPanel extends JPanel {
  43. public ColorsPanel() {
  44. JCheckBox cb1 = new JCheckBox("Red");
  45. add(cb1);
  46. JCheckBox cb2 = new JCheckBox("Green");
  47. add(cb2);
  48. JCheckBox cb3 = new JCheckBox("Blue");
  49. add(cb3);
  50. }
  51. }
  52. class FlavorsPanel extends JPanel {
  53. public FlavorsPanel() {
  54. JComboBox jcb = new JComboBox();
  55. jcb.addItem("Vanilla");
  56. jcb.addItem("Chocolate");
  57. jcb.addItem("Strawberry");
  58. add(jcb);
  59. }
  60. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement