/**
* @author Igor Kholodov, Bristol Community College
*
* <code>application</code> package is a namespace for the classes
* of the application.
*/
package application;
import javax.swing.JOptionPane;
import javax.swing.JDialog;
import javax.swing.JButton;
import javax.swing.JRadioButton;
import javax.swing.ButtonGroup;
import javax.swing.JLabel;
import javax.swing.ImageIcon;
import javax.swing.BoxLayout;
import javax.swing.Box;
import javax.swing.BorderFactory;
import javax.swing.border.Border;
import javax.swing.JTabbedPane;
import javax.swing.JPanel;
import javax.swing.JFrame;
import javax.swing.JTextField;
import java.beans.*; //Property change stuff
import java.awt.*;
import java.awt.event.*;
/*
* PanelWithTabs.java requires these files:
* DialogViewOptions.java
* images/middle.gif
*/
public class PanelWithTabs
extends JPanel
{
JLabel mLabel;
JButton mButOK; // OK button
JButton mButCancel; // Cancel button
private JTextField textField;
JFrame mFrame;
String strTabOneTitle = "Tab One Title";
String strTabTwoTitle = "Tab Two Title";
String strTabThreeTitle = "Tab Three Title";
DialogViewOptions mDialogViewOptions;
/** Creates the GUI shown inside the mFrame's content pane. */
public PanelWithTabs(JFrame aFrame, DialogViewOptions aDialogViewOptions)
{
super(new BorderLayout());
mFrame = aFrame;
mDialogViewOptions = aDialogViewOptions;
//Create the components.
JPanel tabOnePanel = new JPanel();
JPanel tabTwoPanel = new JPanel();
JPanel tabThreePanel = new JPanel();
//Lay them out.
Border padding = BorderFactory.createEmptyBorder(20, 20, 5, 20);
tabOnePanel.setBorder(padding);
tabTwoPanel.setBorder(padding);
tabThreePanel.setBorder(padding);
//Polpulate tabs
textField = new JTextField(30);
tabOnePanel.add(textField);
//Ensure the text field always gets the first focus.
addComponentListener(new ComponentAdapter()
{
public void componentShown(ComponentEvent ce)
{
textField.requestFocusInWindow();
}
});
//Register an event handler for the text field
textField.addActionListener(aDialogViewOptions);
JTabbedPane tabbedPane = new JTabbedPane();
tabbedPane.addTab(strTabOneTitle, null,
tabOnePanel,
strTabOneTitle); //tooltip text
tabbedPane.addTab(strTabTwoTitle, null,
tabTwoPanel,
strTabTwoTitle); //tooltip text
tabbedPane.addTab(strTabThreeTitle, null,
tabThreePanel,
strTabThreeTitle); //tooltip text
add(tabbedPane, BorderLayout.CENTER);
mLabel = new JLabel("A label", JLabel.CENTER);
mLabel.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
// push buttons
mButOK = new JButton("OK");
mButCancel = new JButton("Cancel");
mButOK.addActionListener(aDialogViewOptions);
mButCancel.addActionListener(aDialogViewOptions);
//add(mLabel, BorderLayout.PAGE_END);
JPanel bottomPanel = new JPanel();
bottomPanel.add(mLabel);
bottomPanel.add(mButOK);
bottomPanel.add(mButCancel);
add(bottomPanel, BorderLayout.PAGE_END);
}//constructor PanelWithTabs
/** Gets the text displayed by the text field. */
public String getText()
{
return textField.getText();
}
/** Sets the text of the text field. */
public void setText(String aText)
{
textField.setText(aText);
}
}//class PanelWithTabs