
I create 2 text field f1,f2 and 2 button b1,b2.If i enter some text in the text field and click the button b1 the text field f1 text will be shown in the Message dialog box and if i click the button b2 the text field f2 text will be shown in another one Messagedialog box.I Need the code of this program...

import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
class SwingProgram
{
SwingProgram(){
final JTextField f1=new JTextField(20);
final JTextField f2=new JTextField(20);
JButton b1=new JButton("Button1");
JButton b2=new JButton("Button2");
b1.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
String st=f1.getText();
JOptionPane.showMessageDialog(null,"TextField value is: "+st);
}
});
b2.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
String st=f2.getText();
JOptionPane.showMessageDialog(null,"TextField value is: "+st);
}
});
JPanel p=new JPanel(new GridLayout(2,2));
p.add(f1);
p.add(f2);
p.add(b1);
p.add(b2);
JFrame f=new JFrame();
f.add(p);
f.setVisible(true);
f.pack();
}
public static void main(String[]args){
new SwingProgram();
}
}
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.