import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class OneOption implements ActionListener {
JTextField entryField;
JLabel label;
public void actionPerformed(ActionEvent e) {
String text = entryField.getText();
label.setText(text);
}
private JPanel getContent() {
JPanel panel = new JPanel(new BorderLayout());
panel.add(getLabel(), "North");
panel.add(getEntry());
panel.add(getButton(), "South");
return panel;
}
private JLabel getLabel() {
label = new JLabel();
label.setPreferredSize(new Dimension(100,30));
label.setHorizontalAlignment(JLabel.CENTER);
return label;
}
private JPanel getEntry() {
entryField = new JTextField(12);
entryField.addActionListener(this);
JPanel panel = new JPanel(new GridBagLayout());
panel.add(entryField, new GridBagConstraints());
return panel;
}
private JPanel getButton() {
JButton button = new JButton("make it happen");
button.addActionListener(this);
JPanel panel = new JPanel();
panel.add(button);
return panel;
}
public static void main(String[] args) {
JFrame f = new JFrame();
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.add(new OneOption().getContent());
f.setSize(400,200);
f.setLocationRelativeTo(null);
f.setVisible(true);
}
}