Dev-san

Untitled

Oct 20th, 2014
256
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 4.54 KB | None | 0 0
  1. /*
  2.  * To change this license header, choose License Headers in Project Properties.
  3.  * To change this template file, choose Tools | Templates
  4.  * and open the template in the editor.
  5.  */
  6. /**
  7.  *
  8.  * @author Ilija
  9.  */
  10. import javax.swing.*;
  11. import java.awt.*;
  12.  
  13. /**
  14.  *
  15.  * @author Ilija
  16.  */
  17. public class UIBilet extends JApplet{
  18.     public JPanel createFlightOptions()
  19.     {
  20.         JComboBox start = new JComboBox();
  21.         start.addItem("London");
  22.         start.addItem("Skopje");
  23.         start.addItem("Tokyo");
  24.         JComboBox end = new JComboBox();
  25.         end.addItem("Barcelona");
  26.         end.addItem("Madrid");
  27.         end.addItem("Paris");
  28.         JPanel flightPane = new JPanel(new GridBagLayout());
  29.         GridBagConstraints c = new GridBagConstraints();
  30.         c.fill = GridBagConstraints.HORIZONTAL;
  31.         c.weightx = 1.0;
  32.         flightPane.setBorder(BorderFactory.createTitledBorder("Flight options:"));
  33.         // DEST
  34.         JPanel destinationOpts = new JPanel(new GridBagLayout());
  35.         c.gridx = 0;
  36.         c.gridy = 0;
  37.         destinationOpts.add(new JLabel("From:", SwingConstants.RIGHT), c);
  38.         c.gridx = 1;
  39.         c.gridy = 0;
  40.         destinationOpts.add(new JLabel("To:", SwingConstants.RIGHT), c);
  41.         c.gridx = 0;
  42.         c.gridy = 1;
  43.         destinationOpts.add(start,c);
  44.         c.gridx = 1;
  45.         c.gridy = 1;
  46.  
  47.         destinationOpts.add(end,c);
  48.         c.gridx = 0;
  49.         c.gridy = 0;
  50.         c.ipady = 10;
  51.         flightPane.add(destinationOpts,c);
  52.         c.ipady = 0;
  53.         // /DEST
  54.        
  55.         JPanel otherOpts = new JPanel(new GridBagLayout());
  56.         c.gridx = 0;
  57.         c.gridy = 0;
  58.        
  59.         otherOpts.add(new JLabel("Number of seats:"), c);
  60.         c.gridx = 1;
  61.         c.gridy = 0;
  62.         otherOpts.add(new JTextPane(), c);
  63.         c.gridx = 0;
  64.         c.gridy = 1;
  65.         otherOpts.add(new JLabel("Type of luggage: "), c);
  66.         JPanel luggagePanel = new JPanel(new GridLayout(2, 1));
  67.         luggagePanel.add(new JCheckBox("Bag", true));
  68.         luggagePanel.add(new JCheckBox("Suitcase", false));
  69.         c.gridx = 1;
  70.         c.gridy = 1;
  71.         otherOpts.add(luggagePanel, c);
  72.         c.gridx = 0;
  73.         c.gridy = 1;
  74.         flightPane.add(otherOpts,c);
  75.         return flightPane;
  76.     }
  77.    
  78.     public JPanel createPersonalOptions()
  79.     {
  80.         GridLayout lay = new GridLayout(3, 2);
  81.         lay.setVgap(5);
  82.         JPanel opts = new JPanel(lay);
  83.         opts.setBorder(BorderFactory.createTitledBorder("Personal options:"));
  84.         opts.add(new JLabel("First name: "));
  85.         opts.add(new JTextPane());
  86.         opts.add(new JLabel("Last name: "));
  87.         opts.add(new JTextPane());
  88.         opts.add(new JLabel("Passport number: "));
  89.         opts.add(new JTextPane());
  90.         return opts;
  91.     }
  92.    
  93.    
  94.     public JPanel createPaymentInfo()
  95.     {
  96.         GridLayout lay = new GridLayout(1, 4);
  97.         lay.setVgap(5);
  98.         JPanel opts = new JPanel(lay);
  99.         opts.setBorder(BorderFactory.createTitledBorder("Payment:"));
  100.         opts.add(new JLabel("Card: "));
  101.         ButtonGroup gr = new ButtonGroup();
  102.         JRadioButton v = new JRadioButton("Visa", true)
  103.                 , m1 = new JRadioButton("Maestro", false)
  104.                 , m2 = new JRadioButton("Master", false);
  105.         gr.add(v);
  106.         gr.add(m1);
  107.         gr.add(m2);
  108.         opts.add(v);
  109.         opts.add(m1);
  110.         opts.add(m2);
  111.         return opts;
  112.     }
  113.    
  114.     @Override
  115.     public void init() {
  116.         JPanel pane = new JPanel(new GridBagLayout());
  117.         GridBagConstraints c = new GridBagConstraints();
  118.         c.fill = GridBagConstraints.HORIZONTAL;
  119.         c.weightx = 1.0;
  120.         c.gridx = 0;
  121.         Dimension d = new Dimension(500, 1024);
  122.         //this.getContentPane().setMaximumSize(d);
  123.         //this.getContentPane().setMinimumSize(d);
  124.         c.gridy++;
  125.         pane.add(createFlightOptions(), c);
  126.         c.gridy++;
  127.         pane.add(createPersonalOptions(), c);
  128.         c.gridy++;
  129.         pane.add(createPaymentInfo(), c);
  130.         c.gridy++;
  131.         JPanel btnPane = new JPanel(new GridLayout(1, 2));
  132.         JButton b1 = new JButton("Quit"), b2 = new JButton("Buy");
  133.         int y = c.gridy;
  134.         c.gridx = 0;
  135.         c.gridy = 0;
  136.         btnPane.add(b1, c);
  137.         btnPane.add(b2, c);
  138.         c.gridy = y;
  139.         c.fill = GridBagConstraints.NONE;
  140.         c.anchor = GridBagConstraints.EAST;
  141.         pane.add(btnPane,c);
  142.         this.getContentPane().add(pane);
  143.         this.setSize(300, 320);
  144.     }
  145. }
Advertisement
Add Comment
Please, Sign In to add comment