votako

bibike

Jul 4th, 2013
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.89 KB | None | 0 0
  1. package test;
  2.  
  3. import java.awt.*;
  4. import java.awt.event.ActionEvent;
  5. import java.awt.event.ActionListener;
  6.  
  7.  
  8.  
  9.  
  10. import javax.swing.*;
  11.  
  12. public class Test implements ActionListener {
  13.         String[] bikeName = new String[]{      
  14.                 "B.O.N.E", "Colony", "DK", "Fit", "Ghost"       };
  15.        
  16.        
  17.         JComboBox comboxName = new JComboBox(bikeName);
  18.         JTextArea quanityBikes = new JTextArea();
  19.        
  20.         JLabel welcome = new JLabel("welcome to my bike magazine");
  21.        
  22.         JButton ok = new JButton("ok");
  23.        
  24.         JPanel panel = new JPanel();
  25.        
  26.         public void init(){
  27.                 GridLayout bl = new GridLayout(4,1);
  28.                 panel.setLayout(bl);
  29.                 panel.add(welcome);
  30.                 panel.add(comboxName);
  31.                 panel.add(quanityBikes);
  32.                 panel.add(ok);
  33.                
  34.                 JFrame frame = new JFrame("Bike shop");
  35.         frame.setContentPane(panel);
  36.  
  37.         frame.pack();
  38.  
  39.         frame.setVisible(true);
  40.        
  41.         ok.addActionListener(this);
  42.         }
  43.        
  44.         public void actionPerformed(ActionEvent e) {
  45.                 String BN = (String) comboxName.getSelectedItem();
  46.                 try {
  47.                     Integer NB = Integer.parseInt(quanityBikes.getText());
  48.                     if(NB>7){
  49.                         JOptionPane.showConfirmDialog(null,"too many bike.",
  50.                                 null, JOptionPane.PLAIN_MESSAGE);
  51.                     }else{
  52.                         JOptionPane.showConfirmDialog(null,BN+" "+NB,
  53.                                 null, JOptionPane.PLAIN_MESSAGE);
  54.                     }
  55.                 } catch (NumberFormatException e1) {
  56.                     // TODO Auto-generated catch block
  57.                     JOptionPane.showConfirmDialog(null,"enter the number",null,
  58.                             JOptionPane.PLAIN_MESSAGE);
  59.                 }
  60.         }
  61.        
  62.        
  63.        
  64.         public static void main(String[] args) {
  65.                 Test b = new Test();
  66.                 b.init();
  67.  
  68.         }
  69.  
  70. }
Advertisement
Add Comment
Please, Sign In to add comment