How to return a string from a JTextField

Ads

 
 

Share on Google+Share on Google+

Hilary Desi
How to return a string from a JTextField
1 Answer(s)      5 years and 7 months ago
Posted in : Java Beginners

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

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

Ads









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
How can we extract string 'roseindia.net ' from a string http://[email protected] net using regular expression of php?
How can we extract string 'roseindia.net ' from a string http://[email protected] net using regular expression of php?   How can we extract string 'roseindia.net ' from a string http://[email protected] net using regular
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
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
java jtextfield
java jtextfield  how to validate jTextField which accept only number or alphabets from keyboard....plez do help me
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
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
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
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
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
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
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 : string substr (string $var... string of variable $var, the initial index position is denoted by $initial
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 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 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   ... UpdateData { public static void main(String[] args) { String url="http

Ads

 
Advertisement null

Ads