Advertisement
Guest User

Untitled

a guest
Jan 27th, 2016
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.75 KB | None | 0 0
  1. import javax.swing.*;
  2. import javax.swing.border.*;
  3.  
  4. import java.awt.*;
  5. import java.awt.event.ActionEvent;
  6. import java.awt.event.ActionListener;
  7. import java.util.*;
  8.  
  9. public class Apleti extends JApplet{
  10.  
  11. JTextField text_name, text_lastname,text_passport;
  12. JTextField text_seats;
  13.  
  14. public void init(){
  15. JFrame frame = new JFrame("Lab2");
  16. JPanel flight = new JPanel();
  17. JLabel destination1 = new JLabel("Destination(from):");
  18. JLabel destination2 = new JLabel("Destination(to):");
  19. JLabel seats = new JLabel("Number of seats:");
  20. JLabel luggage = new JLabel("Type of luggage:");
  21. JComboBox comboBox1 = new JComboBox();
  22. JComboBox comboBox2 = new JComboBox();
  23. text_seats = new JTextField(10);
  24. JCheckBox checkBox = new JCheckBox("Bag");
  25. checkBox.setSelected(true);
  26. JCheckBox checkBox1 = new JCheckBox("Suitcase");
  27.  
  28. JPanel info = new JPanel();
  29. JLabel name = new JLabel("First name:");
  30. JLabel lastname = new JLabel("Last name:");
  31. JLabel passport = new JLabel("Passport number:");
  32. text_name = new JTextField(10);
  33. text_lastname = new JTextField(20);
  34. text_passport = new JTextField(10);
  35.  
  36. JPanel payment = new JPanel();
  37. JLabel card = new JLabel("Card:");
  38. JRadioButton b1 = new JRadioButton("Visa");
  39. JRadioButton b2 = new JRadioButton("Maestro");
  40. JRadioButton b3 = new JRadioButton("Master");
  41. ButtonGroup bg = new ButtonGroup();
  42. JPanel kopcinja = new JPanel();
  43. JButton quit = new JButton("Quit");
  44. JButton buy = new JButton("Buy");
  45. buy.addActionListener(new ActionListener() {
  46.  
  47. @Override
  48. public void actionPerformed(ActionEvent e) {
  49. JOptionPane.showMessageDialog(null, text_name.getText() +
  50. " "+text_lastname.getText()+ " vashiot bilet e potvrden!");
  51. }
  52. });
  53. quit.addActionListener(new ActionListener() {
  54.  
  55. @Override
  56. public void actionPerformed(ActionEvent e) {
  57. text_name.setText("");
  58. text_lastname.setText("");
  59. text_passport.setText("");
  60. text_seats.setText("");
  61. }
  62. });
  63.  
  64. TitledBorder title1 = BorderFactory.createTitledBorder("Flight options:");
  65. flight.setBorder(title1);
  66. TitledBorder title2 = BorderFactory.createTitledBorder("Personal info:");
  67. info.setBorder(title2);
  68. TitledBorder title3 = BorderFactory.createTitledBorder("Payment:");
  69. payment.setBorder(title3);
  70.  
  71. comboBox1.addItem("Pariz");
  72. comboBox1.addItem("Berlin");
  73. comboBox1.addItem("London");
  74. comboBox2.addItem("Barcelona");
  75. comboBox2.addItem("NewYork");
  76. comboBox2.addItem("Skopje");
  77.  
  78. frame.setLayout(new GridLayout(4, 1));
  79. flight.setLayout(new GridLayout(4, 2,20,20));
  80. info.setLayout(new GridLayout(3, 2,20,20));
  81. payment.setLayout(new GridLayout(1, 4));
  82.  
  83. JPanel tmp = new JPanel();
  84. //flight panel
  85. flight.add(destination1);
  86. flight.add(destination2);
  87. flight.add(comboBox1);
  88. flight.add(comboBox2);
  89. flight.add(seats);
  90. flight.add(text_seats);
  91. flight.add(luggage);
  92. tmp.add(checkBox);
  93. tmp.add(checkBox1);
  94. flight.add(tmp);
  95. //flight.add(checkBox1);
  96.  
  97. //info panel
  98. text_name.setText("FName");
  99. text_lastname.setText("LName");
  100. text_passport.setText("A123N09");
  101. info.add(name);
  102. info.add(text_name);
  103. info.add(lastname);
  104. info.add(text_lastname);
  105. info.add(passport);
  106. info.add(text_passport);
  107.  
  108. //payment panel
  109. bg.add(b1);
  110. bg.add(b2);
  111. bg.add(b3);
  112. b1.setSelected(true);
  113. payment.add(card);
  114. payment.add(b1);
  115. payment.add(b2);
  116. payment.add(b3);
  117.  
  118. //kopcinja panel
  119. kopcinja.add(quit);
  120. kopcinja.add(buy);
  121.  
  122. frame.getContentPane().add(flight);
  123. frame.getContentPane().add(info);
  124. frame.getContentPane().add(payment);
  125. frame.getContentPane().add(kopcinja);
  126. frame.setVisible(true);
  127. frame.setSize(600,800);
  128.  
  129. }
  130. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement