Untitled

mail@pastecode.io avatar
unknown
plain_text
7 months ago
1.3 kB
6
Indexable
Never
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class Demo extends JFrame implements ActionListener {
   JPanel panel;
   JLabel name_label, age_label, message;
   JTextField name_text,age_text;
   JButton submit;
   Demo() {
      
      name_label = new JLabel();
      name_label.setText("Your Name :");
      name_text = new JTextField();
    
      age_label = new JLabel();
      age_label.setText("Your Age :");
      age_text = new JTextField();
     
      submit = new JButton("SEND");
      
      panel = new JPanel(new GridLayout(3, 2));
      panel.add(name_label);
      panel.add(name_text);
      panel.add(age_label);
      panel.add(age_text);
      message = new JLabel();
      panel.add(message);
      panel.add(submit);
      
      setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
      submit.addActionListener(this);
      
      add(panel, BorderLayout.CENTER);
      setTitle("Your Info");
      setSize(400,150);
      setVisible(true);
   }
   public static void main(String[] args) {
      new Demo();
   }
   @Override
   public void actionPerformed(ActionEvent e) {
      String name = name_text.getText();
      String age = age_text.getText(); 
      message.setText("Your Name is "+name+" & "+"age is "+age); 
   }
}   
Leave a Comment