According to my information you just try this code may this will help you out.
Code:
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
class Abc extends JFrame implements ActionListener
{
JButton btn1;
JTextField txt1,txt2;
Abc()
{
setSize(500,500);
setDefaultCloseOperation(3);
setVisible(true);
setTitle(“Text Field Demo”);
btn1= new JButton(“Submit”);
txt1=new JTextField(10);
txt2= new JTextField(10);
//Assigning values to both the TextField
txt1.setText(“Enter the Name Here”);
txt2.setText(“Enter your Age here”);
setLayout(new FlowLayout());
//Adding component to the main Frame
add(txt1);
add(txt2);
btn1.addActionListener(this);
add(btn1);
}
public void actionPerformed(ActionEvent ae)
{
String s1, s2;
//Retrieving textField Values
s1= txt1.getText();
s2=txt2.getText();
//Displaying values in Message box
JOptionPane.showMessageDialog(null,”Your name is ”+ s1+ “/n and your Age is”+s2);
}
public static void main(String str[])
{
Abc a= new Abc();
}
}
Bookmarks