summaryrefslogtreecommitdiff
path: root/examples/gnu
diff options
context:
space:
mode:
authorRoman Kennke <roman@kennke.org>2006-01-27 21:56:31 +0000
committerRoman Kennke <roman@kennke.org>2006-01-27 21:56:31 +0000
commit68fa3970401af1d2dcd57ffbab22a0890a7b6429 (patch)
tree87b0976f265e5a000c18be4258cb8e9b8627e957 /examples/gnu
parent0057a8f1d8e5d858e64433d6b12857db01d0abcd (diff)
downloadclasspath-68fa3970401af1d2dcd57ffbab22a0890a7b6429.tar.gz
2006-01-27 Roman Kennke <kennke@aicas.com>
* examples/gnu/classpath/examples/swing/ButtonDemo.java (createContent): Only create new content if we don't have one already. * examples/gnu/classpath/examples/swing/ComboBoxDemo.java (createContent): Only create new content if we don't have one already. * examples/gnu/classpath/examples/swing/FileChooserDemo.java (createContent): Only create new content if we don't have one already. * examples/gnu/classpath/examples/swing/ScrollBarDemo.java (createContent): Only create new content if we don't have one already. * examples/gnu/classpath/examples/swing/SliderDemo.java (createContent): Only create new content if we don't have one already. * examples/gnu/classpath/examples/swing/TableDemo.java (createContent): Only create new content if we don't have one already. * examples/gnu/classpath/examples/swing/TextFieldDemo.java (createContent): Only create new content if we don't have one already.
Diffstat (limited to 'examples/gnu')
-rw-r--r--examples/gnu/classpath/examples/swing/ButtonDemo.java19
-rw-r--r--examples/gnu/classpath/examples/swing/ComboBoxDemo.java22
-rw-r--r--examples/gnu/classpath/examples/swing/FileChooserDemo.java96
-rw-r--r--examples/gnu/classpath/examples/swing/ScrollBarDemo.java11
-rw-r--r--examples/gnu/classpath/examples/swing/SliderDemo.java39
-rw-r--r--examples/gnu/classpath/examples/swing/TableDemo.java46
-rw-r--r--examples/gnu/classpath/examples/swing/TextFieldDemo.java23
7 files changed, 146 insertions, 110 deletions
diff --git a/examples/gnu/classpath/examples/swing/ButtonDemo.java b/examples/gnu/classpath/examples/swing/ButtonDemo.java
index b53ba3b5c..ffe9fb236 100644
--- a/examples/gnu/classpath/examples/swing/ButtonDemo.java
+++ b/examples/gnu/classpath/examples/swing/ButtonDemo.java
@@ -46,6 +46,8 @@ public class ButtonDemo
implements ActionListener
{
+ private JPanel content;
+
private JCheckBox buttonState;
private JButton button1;
private JButton button2;
@@ -95,13 +97,16 @@ public class ButtonDemo
*/
JPanel createContent()
{
- JPanel content = new JPanel(new BorderLayout());
- JPanel panel = new JPanel(new GridLayout(4, 1));
- panel.add(createButtonPanel());
- panel.add(createTogglePanel());
- panel.add(createCheckBoxPanel());
- panel.add(createRadioPanel());
- content.add(panel);
+ if (content == null)
+ {
+ content = new JPanel(new BorderLayout());
+ JPanel panel = new JPanel(new GridLayout(4, 1));
+ panel.add(createButtonPanel());
+ panel.add(createTogglePanel());
+ panel.add(createCheckBoxPanel());
+ panel.add(createRadioPanel());
+ content.add(panel);
+ }
return content;
}
diff --git a/examples/gnu/classpath/examples/swing/ComboBoxDemo.java b/examples/gnu/classpath/examples/swing/ComboBoxDemo.java
index 52431cb5d..9c893c287 100644
--- a/examples/gnu/classpath/examples/swing/ComboBoxDemo.java
+++ b/examples/gnu/classpath/examples/swing/ComboBoxDemo.java
@@ -69,6 +69,7 @@ public class ComboBoxDemo
}
}
+ private JPanel content;
private JCheckBox comboState1;
private JComboBox combo1;
private JComboBox combo2;
@@ -120,15 +121,18 @@ public class ComboBoxDemo
*/
JPanel createContent()
{
- JPanel content = new JPanel(new BorderLayout());
- JPanel panel = new JPanel(new GridLayout(6, 1));
- panel.add(createPanel1());
- panel.add(createPanel2());
- panel.add(createPanel3());
- panel.add(createPanel4());
- panel.add(createPanel5());
- panel.add(createPanel6());
- content.add(panel);
+ if (content == null)
+ {
+ content = new JPanel(new BorderLayout());
+ JPanel panel = new JPanel(new GridLayout(6, 1));
+ panel.add(createPanel1());
+ panel.add(createPanel2());
+ panel.add(createPanel3());
+ panel.add(createPanel4());
+ panel.add(createPanel5());
+ panel.add(createPanel6());
+ content.add(panel);
+ }
return content;
}
diff --git a/examples/gnu/classpath/examples/swing/FileChooserDemo.java b/examples/gnu/classpath/examples/swing/FileChooserDemo.java
index 70bb56d66..9e880f5dc 100644
--- a/examples/gnu/classpath/examples/swing/FileChooserDemo.java
+++ b/examples/gnu/classpath/examples/swing/FileChooserDemo.java
@@ -63,7 +63,9 @@ public class FileChooserDemo extends JFrame implements ActionListener
return false;
}
}
-
+
+ private JPanel content;
+
/** A label to display the selected file. */
JLabel selectedFileLabel;
@@ -102,52 +104,56 @@ public class FileChooserDemo extends JFrame implements ActionListener
* added if this demo is being run as a standalone demo).
*/
JPanel createContent()
- {
- JPanel panel = new JPanel(new BorderLayout());
-
- // create a panel of buttons to select the different styles of file
- // chooser...
- JPanel buttonPanel = new JPanel(new GridLayout(5, 1));
- JButton openButton = new JButton("Open...");
- openButton.setActionCommand("OPEN");
- openButton.addActionListener(this);
- buttonPanel.add(openButton);
- JButton saveButton = new JButton("Save...");
- saveButton.setActionCommand("SAVE");
- saveButton.addActionListener(this);
- buttonPanel.add(saveButton);
- JButton queryButton = new JButton("Select Directory...");
- queryButton.setActionCommand("SELECT_DIRECTORY");
- queryButton.addActionListener(this);
- buttonPanel.add(queryButton);
- JButton openJavaButton = new JButton("Open Java file...");
- openJavaButton.setActionCommand("OPEN_JAVA");
- openJavaButton.addActionListener(this);
- buttonPanel.add(openJavaButton);
- JButton openMultiButton = new JButton("Open multiple files...");
- openMultiButton.setActionCommand("OPEN_MULTI");
- openMultiButton.addActionListener(this);
- buttonPanel.add(openMultiButton);
- panel.add(buttonPanel, BorderLayout.WEST);
-
- // create a panel to display the selected file(s) and the return code
- JPanel displayPanel = new JPanel(new BorderLayout());
-
- selectedFileLabel = new JLabel("-");
- selectedFileLabel.setBorder(BorderFactory.createTitledBorder("Selected File/Directory: "));
- displayPanel.add(selectedFileLabel, BorderLayout.NORTH);
+ {
+ if (content == null)
+ {
+ JPanel panel = new JPanel(new BorderLayout());
- selectedFilesList = new JList();
- JScrollPane sp = new JScrollPane(selectedFilesList);
- sp.setBorder(BorderFactory.createTitledBorder("Selected Files: "));
- displayPanel.add(sp);
-
- returnCodeLabel = new JLabel("0");
- returnCodeLabel.setBorder(BorderFactory.createTitledBorder("Return Code:"));
- displayPanel.add(returnCodeLabel, BorderLayout.SOUTH);
+ // create a panel of buttons to select the different styles of file
+ // chooser...
+ JPanel buttonPanel = new JPanel(new GridLayout(5, 1));
+ JButton openButton = new JButton("Open...");
+ openButton.setActionCommand("OPEN");
+ openButton.addActionListener(this);
+ buttonPanel.add(openButton);
+ JButton saveButton = new JButton("Save...");
+ saveButton.setActionCommand("SAVE");
+ saveButton.addActionListener(this);
+ buttonPanel.add(saveButton);
+ JButton queryButton = new JButton("Select Directory...");
+ queryButton.setActionCommand("SELECT_DIRECTORY");
+ queryButton.addActionListener(this);
+ buttonPanel.add(queryButton);
+ JButton openJavaButton = new JButton("Open Java file...");
+ openJavaButton.setActionCommand("OPEN_JAVA");
+ openJavaButton.addActionListener(this);
+ buttonPanel.add(openJavaButton);
+ JButton openMultiButton = new JButton("Open multiple files...");
+ openMultiButton.setActionCommand("OPEN_MULTI");
+ openMultiButton.addActionListener(this);
+ buttonPanel.add(openMultiButton);
+ panel.add(buttonPanel, BorderLayout.WEST);
+
+ // create a panel to display the selected file(s) and the return code
+ JPanel displayPanel = new JPanel(new BorderLayout());
+
+ selectedFileLabel = new JLabel("-");
+ selectedFileLabel.setBorder(BorderFactory.createTitledBorder("Selected File/Directory: "));
+ displayPanel.add(selectedFileLabel, BorderLayout.NORTH);
- panel.add(displayPanel);
- return panel;
+ selectedFilesList = new JList();
+ JScrollPane sp = new JScrollPane(selectedFilesList);
+ sp.setBorder(BorderFactory.createTitledBorder("Selected Files: "));
+ displayPanel.add(sp);
+
+ returnCodeLabel = new JLabel("0");
+ returnCodeLabel.setBorder(BorderFactory.createTitledBorder("Return Code:"));
+ displayPanel.add(returnCodeLabel, BorderLayout.SOUTH);
+
+ panel.add(displayPanel);
+ content = panel;
+ }
+ return content;
}
/**
diff --git a/examples/gnu/classpath/examples/swing/ScrollBarDemo.java b/examples/gnu/classpath/examples/swing/ScrollBarDemo.java
index fce137301..f02728cab 100644
--- a/examples/gnu/classpath/examples/swing/ScrollBarDemo.java
+++ b/examples/gnu/classpath/examples/swing/ScrollBarDemo.java
@@ -40,6 +40,8 @@ public class ScrollBarDemo
implements ActionListener
{
+ private JPanel content;
+
/**
* Creates a new demo instance.
*
@@ -67,9 +69,12 @@ public class ScrollBarDemo
*/
JPanel createContent()
{
- JPanel content = new JPanel(new BorderLayout());
- JPanel panel = createScrollBarPanel();
- content.add(panel);
+ if (content == null)
+ {
+ content = new JPanel(new BorderLayout());
+ JPanel panel = createScrollBarPanel();
+ content.add(panel);
+ }
return content;
}
diff --git a/examples/gnu/classpath/examples/swing/SliderDemo.java b/examples/gnu/classpath/examples/swing/SliderDemo.java
index 736024c48..86509827f 100644
--- a/examples/gnu/classpath/examples/swing/SliderDemo.java
+++ b/examples/gnu/classpath/examples/swing/SliderDemo.java
@@ -35,7 +35,9 @@ import javax.swing.JSlider;
public class SliderDemo extends JFrame implements ActionListener
{
-
+
+ private JPanel content;
+
JSlider hslider1;
JSlider hslider2;
JSlider hslider3;
@@ -59,13 +61,13 @@ public class SliderDemo extends JFrame implements ActionListener
public SliderDemo(String frameTitle)
{
super(frameTitle);
- JPanel content = createContent();
+ JPanel cont = createContent();
JPanel closePanel = new JPanel();
JButton closeButton = new JButton("Close");
closeButton.setActionCommand("CLOSE");
closeButton.addActionListener(this);
closePanel.add(closeButton);
- content.add(closePanel, BorderLayout.SOUTH);
+ cont.add(closePanel, BorderLayout.SOUTH);
getContentPane().add(content);
}
@@ -78,20 +80,23 @@ public class SliderDemo extends JFrame implements ActionListener
*/
JPanel createContent()
{
- JPanel content = new JPanel(new BorderLayout());
- JPanel panel = new JPanel(new GridLayout(1, 2));
- panel.add(createHorizontalPanel());
- panel.add(createVerticalPanel());
- enabledCheckBox = new JCheckBox("Enabled");
- enabledCheckBox.setSelected(true);
- enabledCheckBox.setActionCommand("TOGGLE_ENABLED");
- enabledCheckBox.addActionListener(this);
- JPanel checkBoxPanel = new JPanel();
- checkBoxPanel.add(enabledCheckBox);
- JPanel panel2 = new JPanel(new BorderLayout());
- panel2.add(panel);
- panel2.add(checkBoxPanel, BorderLayout.SOUTH);
- content.add(panel2);
+ if (content == null)
+ {
+ content = new JPanel(new BorderLayout());
+ JPanel panel = new JPanel(new GridLayout(1, 2));
+ panel.add(createHorizontalPanel());
+ panel.add(createVerticalPanel());
+ enabledCheckBox = new JCheckBox("Enabled");
+ enabledCheckBox.setSelected(true);
+ enabledCheckBox.setActionCommand("TOGGLE_ENABLED");
+ enabledCheckBox.addActionListener(this);
+ JPanel checkBoxPanel = new JPanel();
+ checkBoxPanel.add(enabledCheckBox);
+ JPanel panel2 = new JPanel(new BorderLayout());
+ panel2.add(panel);
+ panel2.add(checkBoxPanel, BorderLayout.SOUTH);
+ content.add(panel2);
+ }
return content;
}
diff --git a/examples/gnu/classpath/examples/swing/TableDemo.java b/examples/gnu/classpath/examples/swing/TableDemo.java
index 0442bcad3..92f4cc758 100644
--- a/examples/gnu/classpath/examples/swing/TableDemo.java
+++ b/examples/gnu/classpath/examples/swing/TableDemo.java
@@ -130,7 +130,9 @@ public class TableDemo extends JFrame
return super.getColumnClass(column);
}
}
-
+
+ private JPanel content;
+
/**
* The table being displayed.
*/
@@ -165,29 +167,33 @@ public class TableDemo extends JFrame
*/
JPanel createContent()
{
- JPanel p = new JPanel();
- p.setLayout(new BorderLayout());
- table.setModel(model);
- values = new Object[rows][];
- for (int i = 0; i < values.length; i++)
+ if (content == null)
{
- values[i] = new Object[cols];
- for (int j = 1; j < cols; j++)
+ JPanel p = new JPanel();
+ p.setLayout(new BorderLayout());
+ table.setModel(model);
+ values = new Object[rows][];
+ for (int i = 0; i < values.length; i++)
{
- values[i][j] = "" + ((char) ('a' + j)) + i;
+ values[i] = new Object[cols];
+ for (int j = 1; j < cols; j++)
+ {
+ values[i][j] = "" + ((char) ('a' + j)) + i;
+ }
+ values [i][0] = i % 2 == 0? Boolean.TRUE : Boolean.FALSE;
}
- values [i][0] = i % 2 == 0? Boolean.TRUE : Boolean.FALSE;
+
+ // Create the table, place it into scroll pane and place
+ // the pane into this frame.
+ JScrollPane scroll = new JScrollPane();
+
+ // The horizontal scroll bar is never needed.
+ scroll.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
+ scroll.getViewport().add(table);
+ p.add(scroll, BorderLayout.CENTER);
+ content = p;
}
-
- // Create the table, place it into scroll pane and place
- // the pane into this frame.
- JScrollPane scroll = new JScrollPane();
-
- // The horizontal scroll bar is never needed.
- scroll.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
- scroll.getViewport().add(table);
- p.add(scroll, BorderLayout.CENTER);
- return p;
+ return content;
}
/**
diff --git a/examples/gnu/classpath/examples/swing/TextFieldDemo.java b/examples/gnu/classpath/examples/swing/TextFieldDemo.java
index 5ddf11680..11850d07d 100644
--- a/examples/gnu/classpath/examples/swing/TextFieldDemo.java
+++ b/examples/gnu/classpath/examples/swing/TextFieldDemo.java
@@ -107,6 +107,8 @@ public class TextFieldDemo
}
}
+ private JPanel content;
+
/**
* The left aligned textfields and state buttons.
*/
@@ -180,15 +182,18 @@ JPanel textFieldPanel1;
*/
JPanel createContent()
{
- JPanel content = new JPanel(new BorderLayout());
- JPanel panel = new JPanel(new GridLayout(5, 1));
- panel.add(createLeftAlignedPanel());
- panel.add(createRightAlignedPanel());
- panel.add(createCenteredPanel());
- panel.add(createCustomColoredPanel());
- panel.add(createMiscPanel());
- content.add(panel);
- //content.setPreferredSize(new Dimension(400, 300));
+ if (content == null)
+ {
+ content = new JPanel(new BorderLayout());
+ JPanel panel = new JPanel(new GridLayout(5, 1));
+ panel.add(createLeftAlignedPanel());
+ panel.add(createRightAlignedPanel());
+ panel.add(createCenteredPanel());
+ panel.add(createCustomColoredPanel());
+ panel.add(createMiscPanel());
+ content.add(panel);
+ //content.setPreferredSize(new Dimension(400, 300));
+ }
return content;
}