Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Answers Viewqa Java-Beginners How to return a string from a JTextField
Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


Hilary Desi
How to return a string from a JTextField
1 Answer(s)      2 years and 6 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


Advertisement
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
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
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
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
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
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 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
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
java jtextfield
java jtextfield  how to validate jTextField which accept only number or alphabets from keyboard....plez do help me
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
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
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
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
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
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
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
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
Extarct string from PDF
Extarct string from PDF  how can i search a particular character from pdf? also extarct string from a pdf document
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
Get JTextField value from another class
Get JTextField value from another class       In this section, you will learn how to get the textfield value from other class. For this, we have created two classes ClassA.java
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
Advertisements
 

 

 

DMCA.com