
Hi, Am new to java, and am trying to get a string from a JTextField so that I can compare it with another String using either compare or equals or compareTo methods of the String class. The problem is i have no clue how to get the very string i need because i think am getting a reference to that String instead of the variable. Please help

import javax.swing.*;
import java.awt.event.*;
class TextFieldExample
{
public static void main(String[] args)
{
JFrame f=new JFrame();
final JTextField text=new JTextField(20);
JButton b=new JButton("Get");
b.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e) {
String str=text.getText();
JOptionPane.showMessageDialog(null,"You have entered: "+str);
}
});
text.setBounds(10,10,150,20);
b.setBounds(10,30,100,20);
f.setLayout(null);
f.add(text);
f.add(b);
f.setVisible(true);
f.setSize(300,100);
}
}
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.