~ubuntu-branches/ubuntu/precise/classpath/precise

« back to all changes in this revision

Viewing changes to examples/gnu/classpath/examples/swing/TabbedPaneDemo.java

  • Committer: Bazaar Package Importer
  • Author(s): Michael Koch
  • Date: 2006-05-27 16:11:15 UTC
  • mfrom: (1.1.3 upstream)
  • Revision ID: james.westby@ubuntu.com-20060527161115-h6e39eposdt5snb6
Tags: 2:0.91-3
* Install header files to /usr/include/classpath.
* debian/control: classpath: Conflict with jamvm < 1.4.3 and
  cacao < 0.96 (Closes: #368172).

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* TabbedPaneDemo.java -- Demonstrates JTabbedPane
 
2
   Copyright (C) 2006 Free Software Foundation, Inc.
 
3
 
 
4
This file is part of GNU Classpath.
 
5
 
 
6
GNU Classpath is free software; you can redistribute it and/or modify
 
7
it under the terms of the GNU General Public License as published by
 
8
the Free Software Foundation; either version 2, or (at your option)
 
9
any later version.
 
10
 
 
11
GNU Classpath is distributed in the hope that it will be useful, but
 
12
WITHOUT ANY WARRANTY; without even the implied warranty of
 
13
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
14
General Public License for more details.
 
15
 
 
16
You should have received a copy of the GNU General Public License
 
17
along with GNU Classpath; see the file COPYING.  If not, write to the
 
18
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
 
19
02110-1301 USA.
 
20
 
 
21
Linking this library statically or dynamically with other modules is
 
22
making a combined work based on this library.  Thus, the terms and
 
23
conditions of the GNU General Public License cover the whole
 
24
combination.
 
25
 
 
26
As a special exception, the copyright holders of this library give you
 
27
permission to link this library with independent modules to produce an
 
28
executable, regardless of the license terms of these independent
 
29
modules, and to copy and distribute the resulting executable under
 
30
terms of your choice, provided that you also meet, for each linked
 
31
independent module, the terms and conditions of the license of that
 
32
module.  An independent module is a module which is not derived from
 
33
or based on this library.  If you modify this library, you may extend
 
34
this exception to your version of the library, but you are not
 
35
obligated to do so.  If you do not wish to do so, delete this
 
36
exception statement from your version. */
 
37
 
 
38
 
 
39
package gnu.classpath.examples.swing;
 
40
 
 
41
import java.awt.BorderLayout;
 
42
import java.awt.GridLayout;
 
43
import java.awt.event.ActionEvent;
 
44
import java.awt.event.ActionListener;
 
45
 
 
46
import javax.swing.JButton;
 
47
import javax.swing.JComponent;
 
48
import javax.swing.JFrame;
 
49
import javax.swing.JPanel;
 
50
import javax.swing.JTabbedPane;
 
51
import javax.swing.SwingConstants;
 
52
import javax.swing.SwingUtilities;
 
53
 
 
54
public class TabbedPaneDemo
 
55
  extends JPanel
 
56
  implements ActionListener
 
57
{
 
58
  TabbedPaneDemo()
 
59
  {
 
60
    super();
 
61
    createContent();
 
62
  }
 
63
 
 
64
  private void createContent()
 
65
  {
 
66
    JPanel p = new JPanel();
 
67
    p.setLayout(new GridLayout(2, 2));
 
68
    JTabbedPane tabs1 = new JTabbedPane(SwingConstants.TOP);
 
69
    tabs1.add("Top Item 1", new JButton("Button"));
 
70
    tabs1.add("Top Item 2", new JButton("Button"));
 
71
    JTabbedPane tabs2 = new JTabbedPane(SwingConstants.LEFT);
 
72
    tabs2.add("Left Item 1", new JButton("Button"));
 
73
    tabs2.add("Left Item 2", new JButton("Button"));
 
74
    JTabbedPane tabs3 = new JTabbedPane(SwingConstants.BOTTOM);
 
75
    tabs3.add("Bottom Item 1", new JButton("Button"));
 
76
    tabs3.add("Bottom Item 2", new JButton("Button"));
 
77
    JTabbedPane tabs4 = new JTabbedPane(SwingConstants.RIGHT);
 
78
    tabs4.add("Right Item 1", new JButton("Button"));
 
79
    tabs4.add("Right Item 2", new JButton("Button"));
 
80
    p.add(tabs1);
 
81
    p.add(tabs2);
 
82
    p.add(tabs3);
 
83
    p.add(tabs4);
 
84
    setLayout(new BorderLayout());
 
85
    add(p, BorderLayout.CENTER);
 
86
  }
 
87
 
 
88
  public void actionPerformed(ActionEvent e) 
 
89
  {
 
90
    if (e.getActionCommand().equals("CLOSE"))
 
91
    {
 
92
      System.exit(0);
 
93
    }
 
94
  }
 
95
 
 
96
  /**
 
97
   * When the demo is run independently, the frame is displayed, so we should
 
98
   * initialise the content panel (including the demo content and a close 
 
99
   * button).  But when the demo is run as part of the Swing activity board,
 
100
   * only the demo content panel is used, the frame itself is never displayed,
 
101
   * so we can avoid this step.
 
102
   */
 
103
  void initFrameContent()
 
104
  {
 
105
    JPanel closePanel = new JPanel();
 
106
    JButton closeButton = new JButton("Close");
 
107
    closeButton.setActionCommand("CLOSE");
 
108
    closeButton.addActionListener(this);
 
109
    closePanel.add(closeButton);
 
110
    add(closePanel, BorderLayout.SOUTH);
 
111
  }
 
112
 
 
113
  public static void main(String[] args)
 
114
  {
 
115
    SwingUtilities.invokeLater
 
116
    (new Runnable()
 
117
     {
 
118
       public void run()
 
119
       {
 
120
         TabbedPaneDemo app = new TabbedPaneDemo();
 
121
         app.initFrameContent();
 
122
         JFrame frame = new JFrame("TabbedPane Demo");
 
123
         frame.getContentPane().add(app);
 
124
         frame.pack();
 
125
         frame.setVisible(true);
 
126
       }
 
127
     });
 
128
  }
 
129
 
 
130
  /**
 
131
   * Returns a DemoFactory that creates a TabbedPaneDemo.
 
132
   *
 
133
   * @return a DemoFactory that creates a TabbedPaneDemo
 
134
   */
 
135
  public static DemoFactory createDemoFactory()
 
136
  {
 
137
    return new DemoFactory()
 
138
    {
 
139
      public JComponent createDemo()
 
140
      {
 
141
        return new TabbedPaneDemo();
 
142
      }
 
143
    };
 
144
  }
 
145
}