Advertisement
Kulas_Code20

Enter complete name

Mar 6th, 2022
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.75 KB | None | 0 0
  1. package com.project;
  2.  
  3. import javax.swing.*;
  4. import javax.swing.border.*;
  5. import java.awt.*;
  6. import java.awt.event.*;
  7.  
  8. public class PE3Biala extends JFrame implements ActionListener{
  9.     private JTextField inputField;
  10.     private JPanel panel;
  11.     private JButton btnSubmit;
  12.     private JLabel lblTitle, lbl1, lblResult;
  13.  
  14.     public PE3Biala() {
  15.         setTitle("PE3 Biala");
  16.         setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  17.         setBounds(100, 100, 350, 200);
  18.         panel = new JPanel();
  19.         panel.setPreferredSize(new Dimension(350, 200));
  20.         panel.setBorder(new EmptyBorder(5, 5, 5, 5));
  21.         setContentPane(panel);
  22.         panel.setLayout(null);
  23.        
  24.         lblTitle = new JLabel("Welcome to GUI Components!");
  25.         lblTitle.setFont(new Font("Serif", Font.BOLD, 22));
  26.         lblTitle.setBounds(22, 22, 302, 24);
  27.         panel.add(lblTitle);
  28.        
  29.         lbl1 = new JLabel("Enter Your Complete Name");
  30.         lbl1.setFont(new Font("Tahoma", Font.PLAIN, 16));
  31.         lbl1.setBounds(65, 57, 203, 24);
  32.         panel.add(lbl1);
  33.        
  34.         inputField = new JTextField();
  35.         inputField.setBounds(34, 92, 195, 24);
  36.         panel.add(inputField);
  37.         inputField.setColumns(10);
  38.        
  39.         btnSubmit = new JButton("Submit");
  40.         btnSubmit.setFont(new Font("Tahoma", Font.PLAIN, 11));
  41.         btnSubmit.setBounds(240, 92, 67, 24);
  42.         btnSubmit.addActionListener(this);
  43.         panel.add(btnSubmit);
  44.        
  45.        
  46.         lblResult = new JLabel("");
  47.         lblResult.setFont(new Font("Tahoma", Font.PLAIN, 12));
  48.         lblResult.setHorizontalAlignment(SwingConstants.CENTER);
  49.         lblResult.setBounds(34, 127, 273, 23);
  50.         panel.add(lblResult);
  51.     }
  52.  
  53.     @Override
  54.     public void actionPerformed(ActionEvent e) {
  55.         if(e.getSource() == btnSubmit) {
  56.             lblResult.setText("Hello, "+inputField.getText());
  57.         }
  58.     }
  59.    
  60.     public static void main(String[] args) {
  61.         new PE3Biala().setVisible(true);
  62.     }
  63. }
  64.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement