Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.project;
- import javax.swing.*;
- import javax.swing.border.*;
- import java.awt.*;
- import java.awt.event.*;
- public class PE3Biala extends JFrame implements ActionListener{
- private JTextField inputField;
- private JPanel panel;
- private JButton btnSubmit;
- private JLabel lblTitle, lbl1, lblResult;
- public PE3Biala() {
- setTitle("PE3 Biala");
- setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- setBounds(100, 100, 350, 200);
- panel = new JPanel();
- panel.setPreferredSize(new Dimension(350, 200));
- panel.setBorder(new EmptyBorder(5, 5, 5, 5));
- setContentPane(panel);
- panel.setLayout(null);
- lblTitle = new JLabel("Welcome to GUI Components!");
- lblTitle.setFont(new Font("Serif", Font.BOLD, 22));
- lblTitle.setBounds(22, 22, 302, 24);
- panel.add(lblTitle);
- lbl1 = new JLabel("Enter Your Complete Name");
- lbl1.setFont(new Font("Tahoma", Font.PLAIN, 16));
- lbl1.setBounds(65, 57, 203, 24);
- panel.add(lbl1);
- inputField = new JTextField();
- inputField.setBounds(34, 92, 195, 24);
- panel.add(inputField);
- inputField.setColumns(10);
- btnSubmit = new JButton("Submit");
- btnSubmit.setFont(new Font("Tahoma", Font.PLAIN, 11));
- btnSubmit.setBounds(240, 92, 67, 24);
- btnSubmit.addActionListener(this);
- panel.add(btnSubmit);
- lblResult = new JLabel("");
- lblResult.setFont(new Font("Tahoma", Font.PLAIN, 12));
- lblResult.setHorizontalAlignment(SwingConstants.CENTER);
- lblResult.setBounds(34, 127, 273, 23);
- panel.add(lblResult);
- }
- @Override
- public void actionPerformed(ActionEvent e) {
- if(e.getSource() == btnSubmit) {
- lblResult.setText("Hello, "+inputField.getText());
- }
- }
- public static void main(String[] args) {
- new PE3Biala().setVisible(true);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement