Advertisement
Guest User

Untitled

a guest
Jan 23rd, 2020
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.71 KB | None | 0 0
  1. import javax.swing.*;
  2. import java.awt.*;
  3. import java.awt.event.*;
  4.  
  5. public class SwingComponents extends JFrame implements ActionListener {
  6. FlowLayout fl = new FlowLayout();
  7. Font bFont = new Font("Arial", Font.BOLD, 16);
  8. JLabel lb1 = new JLabel("<html><font color='yellow'>STI PARKING SYSTEM</font></html>");
  9. JTextField tf = new JTextField(10);
  10. JButton bt = new JButton("PK 1");
  11. JButton bt1 = new JButton("PK 2");
  12. JButton bt2 = new JButton("PK 3");
  13. JButton bt3 = new JButton("PK 4");
  14. JButton bt4 = new JButton("PK 5");
  15. JButton bt5 = new JButton("PK 6");
  16. JButton bt6 = new JButton("PK 7");
  17. JButton bt7 = new JButton("PK 8");
  18. JButton bt8 = new JButton("PK 9");
  19. JLabel lb2 = new JLabel("");
  20.  
  21.  
  22.  
  23.  
  24.  
  25. public static void main(String[] args){
  26. SwingComponents fr = new SwingComponents();
  27. fr.setVisible(true);
  28. }
  29.  
  30. public SwingComponents(){
  31. super("Sample Event");
  32. getContentPane().setBackground( Color.RED );
  33. setSize(275,400);
  34. setLayout(fl);
  35. lb1.setFont(bFont);
  36. lb2.setFont(bFont);
  37. add(lb1);
  38. add(tf);
  39. add(bt);
  40. add(bt1);
  41. add(bt2);
  42. add(bt3);
  43. add(bt4);
  44. add(bt5);
  45. add(bt6);
  46. add(bt7);
  47. add(bt8);
  48. add(lb2);
  49. setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  50. bt.addActionListener(this);
  51. bt1.addActionListener(this);
  52. bt2.addActionListener(this);
  53. bt3.addActionListener(this);
  54. bt4.addActionListener(this);
  55. bt5.addActionListener(this);
  56. bt6.addActionListener(this);
  57. bt7.addActionListener(this);
  58. bt8.addActionListener(this);
  59. }
  60.  
  61. public void actionPerformed(ActionEvent e){
  62. if (e.getActionCommand().equals("PK 1")) {
  63. String name = tf.getText();
  64. String greet = "<html><b style='color: white'>Reserved</b> <i style='color: blue'>" + name + "</i>!</html>";
  65. lb2.setText(greet);
  66. }else if(e.getActionCommand().equals("PK 2")) {
  67.  
  68. String greet = "<html><i style='color: white'>Available1</b> <i style='color: blue'>" + "</i></html>";
  69. lb2.setText(greet);
  70. }else if(e.getActionCommand().equals("PK 3")) {
  71.  
  72. String greet = "<html><i style='color: white'>Available2</b> <i style='color: blue'>" + "</i></html>";
  73. lb2.setText(greet);
  74. }
  75. else if(e.getActionCommand().equals("PK 4")) {
  76.  
  77. String greet = "<html><i style='color: white'>Available3</b> <i style='color: blue'>" + "</i></html>";
  78. lb2.setText(greet);
  79. }
  80. else if(e.getActionCommand().equals("PK 5")) {
  81.  
  82. String greet = "<html><i style='color: white'>Available4</b> <i style='color: blue'>" + "</i></html>";
  83. lb2.setText(greet);
  84. }
  85. else if(e.getActionCommand().equals("PK 6")) {
  86.  
  87. String greet = "<html><i style='color: white'>Available5</b> <i style='color: blue'>" + "</i></html>";
  88. lb2.setText(greet);
  89. }
  90. else if(e.getActionCommand().equals("PK 7")) {
  91.  
  92. String greet = "<html><i style='color: white'>Available6</b> <i style='color: blue'>" + "</i></html>";
  93. lb2.setText(greet);
  94. }
  95. else if(e.getActionCommand().equals("PK 8")) {
  96.  
  97. String greet = "<html><i style='color: white'>Available7</b> <i style='color: blue'>" + "</i></html>";
  98. lb2.setText(greet);
  99. } else if(e.getActionCommand().equals("PK 9")) {
  100.  
  101. String greet = "<html><i style='color: white'>Available8</b> <i style='color: blue'>" + "</i></html>";
  102. lb2.setText(greet);
  103. }else if(e.getActionCommand().equals("PK 2")) {
  104.  
  105. String greet = "<html><i style='color: white'>Available9</b> <i style='color: blue'>" + "</i></html>";
  106. lb2.setText(greet);
  107. }
  108.  
  109. }
  110. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement