Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.awt.BorderLayout;
- import java.awt.GridLayout;
- import java.awt.event.ActionEvent;
- import java.awt.event.ActionListener;
- import javax.swing.JButton;
- import javax.swing.JComboBox;
- import javax.swing.JFrame;
- import javax.swing.JLabel;
- import javax.swing.JOptionPane;
- import javax.swing.JPanel;
- import javax.swing.JTextField;
- public class ComboBoxAndArray extends JFrame{
- /// INIT OBJECTS ////////////////////////////////////////////////////////////////////////
- private String months[] = {"January", "February", "March", "April", "May", "June", "July",
- "August", "September", "October", "November", "December"};
- private JComboBox comoboBox;
- private JTextField tName;
- private JTextField tDay;
- private JTextField tYear;
- private JLabel lName;
- private JLabel lDay;
- private JLabel lYear;
- private JLabel label;
- private JPanel panel;
- private JLabel header;
- private JButton enter;
- private JPanel input;
- ///// DONE INIT OBJECTS ///////////////////////////////////////////////////////////////////
- public ComboBoxAndArray()
- {
- //set frame properties
- setTitle("ComboBox and Array");
- setSize(300,300);
- setDefaultCloseOperation(EXIT_ON_CLOSE);
- // create objects
- enter = new JButton("Enter");
- enter.addActionListener(new ButtonListener());
- header = new JLabel("Please enter your birth date and press the enter button.");
- tName = new JTextField(9);
- tDay = new JTextField(2);
- tYear = new JTextField(4);
- lName = new JLabel("Name:");
- lDay = new JLabel("Day:");
- lYear = new JLabel("Year:");
- label = new JLabel("Select Month : ");
- comoboBox = new JComboBox(months);
- input = new JPanel(new GridLayout(4,2));
- panel = new JPanel(new BorderLayout());
- input.add(lName);
- input.add(tName);
- input.add(label);
- input.add(comoboBox);
- input.add(lDay);
- input.add(tDay);
- input.add(lYear);
- input.add(tYear);
- panel.add(header, BorderLayout.NORTH);
- panel.add(input, BorderLayout.CENTER);
- panel.add(enter, BorderLayout.SOUTH);
- setSize(350,175);
- setLayout(new BorderLayout());
- add(panel,BorderLayout.CENTER);
- }
- public static void main(String[] args) {
- ComboBoxAndArray comoboBoxAndArray = new ComboBoxAndArray();
- comoboBoxAndArray.setVisible(true);
- }
- private class ButtonListener implements ActionListener{
- @Override
- public void actionPerformed(ActionEvent ae) {
- JOptionPane.showMessageDialog(null, "Hello "+ tName.getText() + ", you were born on the " + tDay.getText() + " day of " +
- comoboBox.getSelectedItem() + " in the year " + tYear.getText());
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement