Advertisement
Guest User

Untitled

a guest
Jun 17th, 2014
283
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.79 KB | None | 0 0
  1. import java.awt.BorderLayout;
  2. import java.awt.GridLayout;
  3. import java.awt.event.ActionEvent;
  4. import java.awt.event.ActionListener;
  5. import javax.swing.JButton;
  6. import javax.swing.JComboBox;
  7. import javax.swing.JFrame;
  8. import javax.swing.JLabel;
  9. import javax.swing.JOptionPane;
  10. import javax.swing.JPanel;
  11. import javax.swing.JTextField;
  12.  
  13.  
  14. public class ComboBoxAndArray extends JFrame{
  15.             /// INIT OBJECTS ////////////////////////////////////////////////////////////////////////
  16.             private String months[] = {"January", "February",  "March",   "April",    "May", "June", "July",
  17.                                         "August", "September", "October", "November", "December"};
  18.  
  19.             private JComboBox comoboBox;
  20.             private JTextField tName;
  21.             private JTextField tDay;
  22.             private JTextField tYear;
  23.             private JLabel lName;
  24.             private JLabel lDay;
  25.             private JLabel lYear;
  26.             private JLabel label;
  27.             private JPanel panel;
  28.             private JLabel header;
  29.             private JButton enter;
  30.             private JPanel input;
  31.             ///// DONE INIT OBJECTS ///////////////////////////////////////////////////////////////////
  32.            
  33.             public ComboBoxAndArray()
  34.             {
  35.                         //set frame properties
  36.                         setTitle("ComboBox and Array");
  37.                         setSize(300,300);
  38.                         setDefaultCloseOperation(EXIT_ON_CLOSE);
  39.                        
  40.                         // create objects
  41.                         enter = new JButton("Enter");
  42.                         enter.addActionListener(new ButtonListener());
  43.                         header = new JLabel("Please enter your birth date and press the enter button.");
  44.                         tName = new JTextField(9);
  45.                         tDay = new JTextField(2);
  46.                         tYear = new JTextField(4);
  47.                         lName = new JLabel("Name:");
  48.                         lDay = new JLabel("Day:");
  49.                         lYear = new JLabel("Year:");
  50.                         label = new JLabel("Select Month : ");
  51.                         comoboBox = new JComboBox(months);
  52.                         input = new JPanel(new GridLayout(4,2));
  53.                         panel = new JPanel(new BorderLayout());
  54.                        
  55.                        
  56.                         input.add(lName);
  57.                         input.add(tName);
  58.                         input.add(label);
  59.                         input.add(comoboBox);
  60.                         input.add(lDay);
  61.                         input.add(tDay);
  62.                         input.add(lYear);
  63.                         input.add(tYear);
  64.                         panel.add(header, BorderLayout.NORTH);
  65.                         panel.add(input, BorderLayout.CENTER);
  66.                         panel.add(enter, BorderLayout.SOUTH);
  67.                         setSize(350,175);
  68.                         setLayout(new BorderLayout());
  69.                         add(panel,BorderLayout.CENTER);
  70.             }
  71.  
  72.             public static void main(String[] args) {
  73.                         ComboBoxAndArray comoboBoxAndArray = new ComboBoxAndArray();
  74.                         comoboBoxAndArray.setVisible(true);
  75.             }
  76.            
  77.             private class ButtonListener implements ActionListener{
  78.  
  79.                 @Override
  80.                 public void actionPerformed(ActionEvent ae) {
  81.                     JOptionPane.showMessageDialog(null, "Hello "+ tName.getText() + ", you were born on the " + tDay.getText() + " day of " +
  82.                                                    comoboBox.getSelectedItem() + " in the year " + tYear.getText());
  83.                 }
  84.                
  85.             }
  86. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement