Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package test;
- import java.awt.*;
- import java.awt.event.ActionEvent;
- import java.awt.event.ActionListener;
- import javax.swing.*;
- public class Test implements ActionListener {
- String[] bikeName = new String[]{
- "B.O.N.E", "Colony", "DK", "Fit", "Ghost" };
- JComboBox comboxName = new JComboBox(bikeName);
- JTextArea quanityBikes = new JTextArea();
- JLabel welcome = new JLabel("welcome to my bike magazine");
- JButton ok = new JButton("ok");
- JPanel panel = new JPanel();
- public void init(){
- GridLayout bl = new GridLayout(4,1);
- panel.setLayout(bl);
- panel.add(welcome);
- panel.add(comboxName);
- panel.add(quanityBikes);
- panel.add(ok);
- JFrame frame = new JFrame("Bike shop");
- frame.setContentPane(panel);
- frame.pack();
- frame.setVisible(true);
- ok.addActionListener(this);
- }
- public void actionPerformed(ActionEvent e) {
- String BN = (String) comboxName.getSelectedItem();
- try {
- Integer NB = Integer.parseInt(quanityBikes.getText());
- if(NB>7){
- JOptionPane.showConfirmDialog(null,"too many bike.",
- null, JOptionPane.PLAIN_MESSAGE);
- }else{
- JOptionPane.showConfirmDialog(null,BN+" "+NB,
- null, JOptionPane.PLAIN_MESSAGE);
- }
- } catch (NumberFormatException e1) {
- // TODO Auto-generated catch block
- JOptionPane.showConfirmDialog(null,"enter the number",null,
- JOptionPane.PLAIN_MESSAGE);
- }
- }
- public static void main(String[] args) {
- Test b = new Test();
- b.init();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment