Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import javax.swing.*;
- import java.awt.*;
- import java.awt.event.*;
- public class SwingComponents extends JFrame implements ActionListener {
- FlowLayout fl = new FlowLayout();
- Font bFont = new Font("Arial", Font.BOLD, 16);
- JLabel lb1 = new JLabel("<html><font color='yellow'>STI PARKING SYSTEM</font></html>");
- JTextField tf = new JTextField(10);
- JButton bt = new JButton("PK 1");
- JButton bt1 = new JButton("PK 2");
- JButton bt2 = new JButton("PK 3");
- JButton bt3 = new JButton("PK 4");
- JButton bt4 = new JButton("PK 5");
- JButton bt5 = new JButton("PK 6");
- JButton bt6 = new JButton("PK 7");
- JButton bt7 = new JButton("PK 8");
- JButton bt8 = new JButton("PK 9");
- JLabel lb2 = new JLabel("");
- public static void main(String[] args){
- SwingComponents fr = new SwingComponents();
- fr.setVisible(true);
- }
- public SwingComponents(){
- super("Sample Event");
- getContentPane().setBackground( Color.RED );
- setSize(275,400);
- setLayout(fl);
- lb1.setFont(bFont);
- lb2.setFont(bFont);
- add(lb1);
- add(tf);
- add(bt);
- add(bt1);
- add(bt2);
- add(bt3);
- add(bt4);
- add(bt5);
- add(bt6);
- add(bt7);
- add(bt8);
- add(lb2);
- setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- bt.addActionListener(this);
- bt1.addActionListener(this);
- bt2.addActionListener(this);
- bt3.addActionListener(this);
- bt4.addActionListener(this);
- bt5.addActionListener(this);
- bt6.addActionListener(this);
- bt7.addActionListener(this);
- bt8.addActionListener(this);
- }
- public void actionPerformed(ActionEvent e){
- if (e.getActionCommand().equals("PK 1")) {
- String name = tf.getText();
- String greet = "<html><b style='color: white'>Reserved</b> <i style='color: blue'>" + name + "</i>!</html>";
- lb2.setText(greet);
- }else if(e.getActionCommand().equals("PK 2")) {
- String greet = "<html><i style='color: white'>Available1</b> <i style='color: blue'>" + "</i></html>";
- lb2.setText(greet);
- }else if(e.getActionCommand().equals("PK 3")) {
- String greet = "<html><i style='color: white'>Available2</b> <i style='color: blue'>" + "</i></html>";
- lb2.setText(greet);
- }
- else if(e.getActionCommand().equals("PK 4")) {
- String greet = "<html><i style='color: white'>Available3</b> <i style='color: blue'>" + "</i></html>";
- lb2.setText(greet);
- }
- else if(e.getActionCommand().equals("PK 5")) {
- String greet = "<html><i style='color: white'>Available4</b> <i style='color: blue'>" + "</i></html>";
- lb2.setText(greet);
- }
- else if(e.getActionCommand().equals("PK 6")) {
- String greet = "<html><i style='color: white'>Available5</b> <i style='color: blue'>" + "</i></html>";
- lb2.setText(greet);
- }
- else if(e.getActionCommand().equals("PK 7")) {
- String greet = "<html><i style='color: white'>Available6</b> <i style='color: blue'>" + "</i></html>";
- lb2.setText(greet);
- }
- else if(e.getActionCommand().equals("PK 8")) {
- String greet = "<html><i style='color: white'>Available7</b> <i style='color: blue'>" + "</i></html>";
- lb2.setText(greet);
- } else if(e.getActionCommand().equals("PK 9")) {
- String greet = "<html><i style='color: white'>Available8</b> <i style='color: blue'>" + "</i></html>";
- lb2.setText(greet);
- }else if(e.getActionCommand().equals("PK 2")) {
- String greet = "<html><i style='color: white'>Available9</b> <i style='color: blue'>" + "</i></html>";
- lb2.setText(greet);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement