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 Samson_Swing extends JFrame implements ActionListener{
- private Container con = getContentPane();
- FlowLayout fl = new FlowLayout();
- Font bFont = new Font("Arial", Font.BOLD, 20);
- JLabel lb1 = new JLabel("Enter Your Fullname: ");
- JTextField tf1 = new JTextField(18);
- JLabel lb2 = new JLabel("Enter Your Age: ");
- JTextField tf2 = new JTextField(18);
- JLabel lb3 = new JLabel("Enter Your Address: ");
- JTextField tf3 = new JTextField(18);
- JButton bt = new JButton("Send");
- JLabel lb4 = new JLabel();
- JLabel lb5 = new JLabel();
- JLabel lb6 = new JLabel();
- JLabel lb7 = new JLabel();
- public Samson_Swing() {
- super("Message");
- setSize(600, 500);
- con.setLayout(fl);
- con.setBackground(Color.GRAY);
- lb1.setFont(bFont);
- lb2.setFont(bFont);
- lb3.setFont(bFont);
- lb4.setFont(bFont);
- lb5.setFont(bFont);
- lb6.setFont(bFont);
- lb7.setFont(bFont);
- add(lb1);
- add(tf1);
- add(lb2);
- add(tf2);
- add(lb3);
- add(tf3);
- add(bt);
- add(lb4);
- add(lb5);
- add(lb6);
- add(lb7);
- setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- lb1.setPreferredSize(new Dimension(250,50));
- tf1.setPreferredSize(new Dimension(325,30));
- lb2.setPreferredSize(new Dimension(250,50));
- tf2.setPreferredSize(new Dimension(325,30));
- lb3.setPreferredSize(new Dimension(250,50));
- tf3.setPreferredSize(new Dimension(325,30));
- bt.setPreferredSize(new Dimension(200, 40));
- bt.setHorizontalAlignment(JButton.CENTER);
- lb4.setPreferredSize(new Dimension(375,50));
- lb5.setPreferredSize(new Dimension(375,50));
- lb6.setPreferredSize(new Dimension(375,50));
- lb7.setPreferredSize(new Dimension(375,50));
- lb4.setHorizontalAlignment(JLabel.CENTER);
- lb5.setHorizontalAlignment(JLabel.CENTER);
- lb6.setHorizontalAlignment(JLabel.CENTER);
- lb7.setHorizontalAlignment(JLabel.CENTER);
- lb4.setForeground(Color.BLACK);
- lb5.setForeground(Color.BLACK);
- lb6.setForeground(Color.BLACK);
- lb7.setForeground(Color.BLACK);
- bt.setBackground(Color.BLACK);
- bt.setForeground(Color.YELLOW);
- bt.setToolTipText("Click to Submit");
- bt.addActionListener(this);
- }
- public void actionPerformed(ActionEvent e) {
- String name1 = tf1.getText();
- String age1 = tf2.getText();
- String add1 = tf3.getText();
- int age = Integer.parseInt(tf2.getText());
- String message = "Hi!, "+name1+".";
- String message2 = "Age: "+age1+".";
- String message3 = "Address: "+add1+".";
- String message4A = "You Can Vote.";
- String message4B = "You Can't Vote.";
- lb4.setText(message);
- lb5.setText(message2);
- lb6.setText(message3);
- if(age > 17){
- lb7.setText(message4A);
- }else{
- lb7.setText(message4B);
- }
- }
- public static void main(String []args){
- Samson_Swing fr = new Samson_Swing();
- fr.setVisible(true);
- }
- }
Add Comment
Please, Sign In to add comment