How to return a string from a JTextField

How to return a string from a JTextField

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

View Answers

March 14, 2012 at 11:18 AM

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);
  }
}









Related Tutorials/Questions & Answers:
How to return a string from a JTextField
How to return a string from a JTextField  Hi, Am new to java, and am trying to get a string from a JTextField so that I can compare it with another.... The problem is i have no clue how to get the very string i need because i think
in string how will write the return statement..........?
in string how will write the return statement..........?  import...; public static void main(String args[]){ int i=Integer.parseInt(args[0... 256"); } else{ binary(i); } } public static String binary(int i
Advertisements
Copy data from one JTextField to another JTextField
, you will learn how to copy the data from one JTextField into another JTextField. When you run this program it starts with two JTextField. Enter some... Copy data from one JTextField to another JTextField
How to return multiple values from a method - Java Beginners
How to return multiple values from a method  I came the following method "How do I return multiple values from a method?" posted elsewhere...() { return ivFirstName; } public String getLastName() { return
How to return multiple values from a method - Java Beginners
How to return multiple values from a method  I came the following method "How do I return multiple values from a method?" posted elsewhere...() { return ivFirstName; } public String getLastName() { return
how to pass a string from one class to another
how to pass a string from one class to another  hi all, Good morning. I am trying to develop a coding pass a string from one class and declare in other class. the string which i need to pass is the data from an file and i want
How to evaluate the mathematical expression from the string in J2ME.
How to evaluate the mathematical expression from the string in J2ME.  How to evaluate the mathematical expression from the string in J2ME. For example a string containing "24".From the string i want evaluate the mathematical
How to evaluate the mathematical expression from the string in J2ME.
How to evaluate the mathematical expression from the string in J2ME.  How to evaluate the mathematical expression from the string in J2ME. For example a string containing "24".From the string i want evaluate the mathematical
how to write to file from string in Java
how to write to file from string in Java  Hi, Please any one help me for how to write to file from string in Java. I am beginner in Java programming. Thanks,   Hi, Are you eager to learn how to write to file from
How to Remove Repeated Characters from the String?
How to Remove Repeated Characters from the String?  Hi, I trying to develop an application which will remove the repeated characters from... the example of how to remove repeated characters from the string. Please visit
jtextfield
jtextfield  hii..is it possible to make a jtextfield in login page in such a way that some text should already be inserted like username and it should be displayed light in color and when a user enters some text then it should
navigating the value of JTextField from one JFrame to another - Swing AWT
navigating the value of JTextField from one JFrame to another  hello I m doing one project where I m retriving the data from databse in JTextField...=conn.createStatement(); ResultSet rs=st.executeQuery("Select * from data"); String
navigating the value of JTextField from one JFrame to another - Swing AWT
navigating the value of JTextField from one JFrame to another  Hello... is working also.. but only first record is comming... how can I fetch all the records from database using up and down keys of keyboard? And also I wanted
Return Value from One Form
Return Value from One Form  I have two buttons in main form client and bank.when i click client button new form will open, in this dedupe button... value of dedupe form and use in bank form..how to do
How to pass Array of string from action class to jsp page
How to pass Array of string from action class to jsp page  this is my... final String SUCCESS = "success"; @Override public ActionForward execute...(true); DiagservicesForm lf=(DiagservicesForm) form; String pname
How can we extract string 'roseindia.net ' from a string http://deepak@roseindia. net using regular expression of php?
How can we extract string 'roseindia.net ' from a string http://deepak@roseindia. net using regular expression of php?   How can we extract string 'roseindia.net ' from a string http://deepak@roseindia. net using regular
Remove duplicate characters from the string
Remove duplicate characters from the string In this tutorial, you will learn how to remove duplicate characters from the string. Java has provide several.... Here we are going to remove duplicate characters from the string
Java Remove a character from string
Java Remove a character from string In this tutorial, you will learn how to remove a character from the string. There are several methods for examining... to remove a particular character from the string. In the given example, we have
Extarct string from PDF
Extarct string from PDF  how can i search a particular character from pdf? also extarct string from a pdf document
Stripping of unwanted characters from string
Stripping of unwanted characters from string  how to strip off unwanted characters from a string   Hi Friend, Try this: public class StripCharacters { public String strip(String s) { String st
Removing characters from a string
Removing characters from a string  Removing characters from a string...(String []args){ String str="Hello 123.you are At 3456"; String...() method removes all blank spaces in the string
jsonelement from string
jsonelement from string  Hi, I have to create jsonelement from string in Java. How to do this? Thanks   Hi, You can use following code: Gson gson = new Gson(); String data ="Hello"; JsonElement ele
calling servlet from JS and return response from servlet to JS
calling servlet from JS and return response from servlet to JS  hello... task.now i want this servlet(myServlet) to return a url(eg. pages/file.jsp... Ajax. i tried following: in servlet:: String url = "loadData.jsp
Java dom from string
Java dom from string  Hi, How to create dom tree from string data? I am trying to search the example for java dom from string. Thanks... static void main(String[] args) { String url="http://www.roseindia.net
String Start with Example
String Start with Example       In this section, you will learn how to check the given string...() function it will return 'true' and display a message "The given string is start
PHP get character from String
PHP Get Character From String To get sub string from a String we can use substr() method. Structure of this method is :ADS_TO_REPLACE_1 string substr (string $var, int $initial [, int $len]  ) In the above example we want
Return Value From Event - Java Beginners
Return Value From Event  I would like to call a method that returns... } return value } My problem... for the listener and then return the value as modified. Thanks
remove comma from string php
remove comma from string php  How to remove the last comma from the string in PHP
Removing character from a string in sql.
Removing character from a string in sql.  How to remove or replace character from a string
Java get Int from String
Java get Int from String       In this section, you will study how to obtain the integer value from String. For this, we have defined a string. The method  Integer.parseInt
remove a substring from a string
remove a substring from a string  Please I jave an arraylist composed...] w2.w4 is a subset of w2.w3.w4 ?how I recognize it also ADS_TO_REPLACE_1 w1.w3 is a subset of w1.w2.w3 ?how I recognize it same for w1.w2 in w1.w2.w3. I nedd
Jlist and JTextfield
Jlist and JTextfield  How can we filter values from jlist by adding only a single letter in jtextfield such that when letter S is pressed in jtextfield then jlist should diplay all the values starting from letter S.I am using
java jtextfield
java jtextfield  how to validate jTextField which accept only number or alphabets from keyboard....plez do help me
remove comma from string php
remove comma from string php  How to remove the last comma from the string in PHP?   remove last comma from string names = names.replaceAll(",$", ""); //Or a simple substring: if (names.endsWith(",")) { names
remove punctuation from string in java
remove punctuation from string in java  Hi, I want to remove punctuation in text from Java program. How to remove punctuation from string in java... RemovePunctExample { public static void main(String[] args) { //Construct String
jTextField in swing
jTextField in swing  I am new to java and i am making a registration form.i just want to know if there is any code in which a string cannot be inserted in a jtextfield where a phone number has to be inserted.the jtextfield should
Removing character from a string in sql.
Removing character from a string in sql.  Removing special characters from a string in sql
Get Character from String
Get Character from String       In this example we will see that how to convert string to array... toCharArray() to convert string to character array. 3. Retrieve character from
Removing HTML from a Java String
Removing HTML from a Java String  Removing HTML from a Java String
How to read and retrieve jtable row values into jtextfield on clicking at particular row ...
How to read and retrieve jtable row values into jtextfield on clicking at particular row ...  Hello Sir, I am developing a desktop application in which i have to display database records in jtable .now I want
how to pass string array from action class to jsp page? pls reply me.
how to pass string array from action class to jsp page? pls reply me.  how to pass string array from action class to jsp page? pls reply me.  .... In your action class, String[] arr = {"A","B","C","D"}; for (int x = 0; x < arr
Passing java variables from JSP to Servlet - return null values
Passing java variables from JSP to Servlet - return null values  I want to pass some variables from a JSP page to a servlet. These variables are from the java code of my JSP. In JSP page I did, String msg="hello
how to get date format in string from date object containing real date in java
how to get date format in string from date object containing real date in java  i want to get data string format from date object where date object containing real date. date frequently vary in from of only month & year
how to get date format in string from date object containing real date in java
how to get date format in string from date object containing real date in java  i want to get data string format from date object where date object containing real date. date frequently vary in from of only month & year
Count Palindromes from the string
Count Palindromes from the string In this section, we are going to find out the number of palindromes from the string. For this, we have allowed the user to input a sentence or string. This string is then break down into tokens using
JTextField Validation in java swing
JTextField Validation in java swing In this tutorial, you will learn how to validate jtextfield in java swing. Here we have created a textfield on frame... extends JFrame{ JTextField text; JLabel label; JPanel p; TextValidation(){ text
Reading string from file timed
Reading string from file timed  So I want to make a file reader/ buffered reader that reads a new line of the textfile, lets say every 30 second. Like it reads the first line, waiting 30 seconds, read the next line and so one
UITableView dataSource must return a cell from tableView:cellForRowAtIndexPath
UITableView dataSource must return a cell from tableView:cellForRowAtIndexPath  HI, What is the solution of UITableView dataSource must return a cell from tableView:cellForRowAtIndexPath error? Thanks
create a string from an array using JavaScript
create a string from an array using JavaScript  How to use "join()" to create a string from an array using JavaScript
JtextField - Java Beginners
JtextField  Hi, How can I populate a jtextfield of another Jframe using the information inputted from another Jframe  Hi Friend, Use...; JLabel label1,label2; JTextField text1,text2; Form() { label1

Ads