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




Have Programming Question? Ask it here!
 
 
 


Abhishek Das
text field
5 Answer(s)      3 years and 8 months ago
Posted in : Java Beginners


How to retrieve data from text field


Advertisement
View Answers

November 30, 2010 at 10:30 AM


Hi Friend,

Try the following code:

import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
class  RetrieveDataFromTextFields{

    public static void main(String[] args){
    JFrame f=new JFrame();
    JLabel label1=new JLabel("Name: ");
    JLabel label2=new JLabel("Address: ");
    final JTextField text1=new JTextField(20);
    final JTextField text2=new JTextField(20);
    JButton b=new JButton("Submit");
    b.addActionListener(new ActionListener(){
        public void actionPerformed(ActionEvent e){
        String value1=text1.getText();
        String value2=text2.getText();
        JOptionPane.showMessageDialog(null,"Name is: "+value1+"\nAddress is: "+value2);
        }
    });
        JPanel p=new JPanel(new GridLayout(3,2));
        p.add(label1);
        p.add(text1);
        p.add(label2);
        p.add(text2);
        p.add(b);
        f.add(p);
        f.setVisible(true);
        f.pack();
    }
}

Thanks



November 30, 2010 at 2:48 PM


Hi Friend...

Your code is perfect & working but now if in that textfield i supplied integer numbers and want to perform any arithmatic operation on them & retrieve the result, how do i do it?

String value1=text1.getText();

Is there any way to convert value1 to integer?? Like using Convert to.int or something??



March 28, 2011 at 4:31 PM


String s=t1.getText(); int a= Integer.parseInt(s);

so converted value will be in a as integer...



March 28, 2011 at 9:51 PM


Thank you.... :)



March 17, 2013 at 2:32 PM


i want to take out the print of the textfield output when it is dispyd in message box..in ur above program,,,,ca u help me,,??with it



Related Tutorials/Questions & Answers:
text field
text field  How to retrieve data from text field   Hi Friend, Try the following code: import java.awt.*; import javax.swing.*; import java.awt.event.*; class RetrieveDataFromTextFields{ public static void main
converting field to text sql
converting field to text sql  I wanted to convert the field to TEXT in SQL.. is it possible?   SQL - Converting the field to TEXT works... the field to TEXT works SELECT CONVERT(TEXT,fld_name) FROM TABLE_NAME
Advertisements
jsf text field not blank
jsf text field not blank  text field not clear in jsf onclick of reset button in my application initial value not deleted   Hello Friend, Post your code. Thanks
validate text field iPhone
validate text field iPhone  i got two different UITextfield in my iPhone application for user login. Just wondering how to validate
CALULATION IN TEXT FIELD
CALULATION IN TEXT FIELD  Suppose 3 text Field first amount ,second amount and third sum of these amount,this amount will appear when tab in next filed(i don't want use any type button) in java swing HOW? PLEASE HELP
swing text field problem
swing text field problem  I want to navigate the content of text field from one class to another and viceversa through button but when I am getting the text from first class I am getting null value.please help me..here
swing text field problem
swing text field problem  I want to navigate the content of text field from one class to another and viceversa through button but when I am getting the text from first class I am getting null value.please help me..here
Digit Only text field
Digit Only text field  How should we accept digits only in a textbox? (using JSTL only, without Javascript
Text field save as word file
Text field save as word file  Dear experts At run how to save set of text field contains text into single Word file. To save in our desktop computer. Solve my problem
clearing text field in spring form
clearing text field in spring form  hi, I have spring form in that i have security question dropdown field and security answer text field ,when i submitted form with errors the answers text field value should be clear, for this i
rich text field - JSP-Servlet
rich text field  Hi, this is jawahar. my question i need rich text field in my program . plz send me the code
iPhone Text Field Border 
Text Field Boarder  In this tutorial will learn about the text field Boarder, we can set the boarder of text field by selecting the text field... for the text field. This project is View Based Application and here will take four text
text field validation - Java Beginners
text field validation  hi How to validate allow only decimal number in text box in jsp?  Hi Friend, Try the following code: function isDecimal(str){ if(isNaN(str) || str.indexOf(".")<0){ alert
Text Field in HTML
Text Field in HTML       The Text Field in HTML are one line areas, which enable the user... Text Field in HTML.In this Tutorial, the code create a text field in HTML page
focus text field - Swing AWT
focus text field  i want to move cursor to next text field by pressing enter.i have created the following coding. but it does nt working.pls help me.thanks in adv. package labwork; import java.awt.KeyboardFocusManager
focus text field - Swing AWT
focus text field  i want to move cursor to next text field by pressing enter.i have created the following coding. but it does nt working.pls help me.thanks in adv. package labwork; import java.awt.KeyboardFocusManager
regarding out put display in html text field
regarding out put display in html text field  how to dispaly the output coming from servlet in a particular text field of html
Can i insert image into struts text field
Can i insert image into struts text field  please tell me can i insert image into text field
JSP combo and text field related questio
JSP combo and text field related questio  in JSP,i had stored data from database in a textboxes usin combo..now i want to use these values of text... and name given to that text field..but its showing somethimng null pointer exception
How to Define Text Field Validation iPhone
How to Define Text Field Validation iPhone  Hi, Can anybody explain me how to define textfield validation iPhone program. please phone online help reference or example. Thanks
iPhone Text Field Validation
iPhone Text Field Validation In any user based application "... data from user. In this tutorial we are going to limiting the text field input...;. We have also take a Text field on the view to take the input from user
fetch values from database into text field
fetch values from database into text field  please provide the example for fetching values from database into text field of table wth edit...;/td>"); the i am getting "rs.getString" in the text field also..  
fetch values from database into text field
fetch values from database into text field  please provide the example for fetching values from database into text field of table as if i am... "rs.getString" in the text field also..   import java.awt.*; import
set text field appearance to default - Java Beginners
set text field appearance to default  hi, i am doing a program, in which i have a form for the user to input some data. i wanted to change the border color of a text box if the input was incorrect, but when i fail to set
retrive record from the text field and insert into to database
retrive record from the text field and insert into to database  the following code is inserting values in the my sql database but i want to insert... ServletException,IOException{ response.setContentType("text/html
Use of Text Field
Use of Text Field, Text box, Text Area, Checkbox,Dropdownlist and Radio... types of information. A form contains form elements checkbox, text field, radio...;/form> Text Fields: Text fields are used to allow
Text Field Midlet Example
Text Field MIDlet Example       This example illustrates how to insert text field in your form... the form with name and company field. The TextField
Write an applet program to transfer the content of the text field into the component on clicking a button
Write an applet program to transfer the content of the text field into the component on clicking a button  Write an applet program to transfer the content of the text field into the component on clicking a button
Retrive data from databse to a text field - Java Server Faces Questions
Retrive data from databse to a text field  Hi, Can you give me a source code to rertrve data from Mysql databse to a text field using JSF.....by selecting option from a dropdown option
Fetched Record from database show into text field of html page
Fetched Record from database show into text field of html page  hi, i have a database with field merchant_code, merchant_name, city, region... in the text field of merchant name then suggest all merchant name in the form
Show text field & check input using jQuery
Show text field & check input using jQuery In this tutorial, we will discuss about how to display 'text field' by a button click & check... how to display 'text field' by a button click & check input using
javascript cal code for selecting date in text field - JSP-Servlet
javascript cal code for selecting date in text field  HI I want javascript calendar code to select date in text field in jsp.pls send me?  Hi Friend, Please visit the following links: http://www.roseindia.net
File format validation and text field validation in java swings
File format validation and text field validation in java swings   i am reading a jpg image file throuh jfilechooser in java swings,when we press browse button for selecting file it will display filechooser in this process when
Can not input value into text field which use sx:datetimepicker
Can not input value into text field which use sx:datetimepicker  I am using lib: struts2-dojo-plugin-2.2.3.1.jar. My source is below: I input value from calendar, it runs normal. But i input value from keyboard by hands
Can not input value into text field which use sx:datetimepicker
Can not input value into text field which use sx:datetimepicker  I am using lib: struts2-dojo-plugin-2.2.3.1.jar. My source is below: print("<sx:datetimepicker name="info.date1" id="date1" displayFormat="yyyyMMdd HHmmss
i want validation for one text field and text area,email,combobox, in that email will validte by useing regular expressions?
i want validation for one text field and text area,email,combobox... for one text field and text area,email,combobox, in that email will validte by useing...; Enter Name: <input type="text" name="name" size="30
how to move curosr from one text field to another automatically when the first textfield reaches its maximum length
how to move curosr from one text field to another automatically when the first textfield reaches its maximum length  how to move curosr from one text field to another automatically when the first textfield reaches its maximum
Password Field in HTML
displays asterisks or bullets instead of the characters. Password text field is same as text field. The only difference between them is that when a user entered... illustrates a username and password text field. <form action> :The page
automatically move next page when data fetched from database is stored in text field
automatically move next page when data fetched from database is stored in text field  hi I have php page where i have two text fields . The data are stored in database wherein when the in the first text field the data is already
how can retrieve more than one values in text field using ajax?
how can retrieve more than one values in text field using ajax?  im... first then in mysql db retrieve seat numbers 1,2,3,4 in text boxes problem...($result)) { echo "<input name='seat' type='text' value=".$row['Seat_Number
iPhone Input Field, iPhone Input Field Tutorial
the users.  In iPhone application we can use Text Field to take the input.  Text field displays editable text and once you taps it'll display a keyboard.... And now place labels and Text Field according to your requirement. I have taken
spring form field clearence
giving wrong format validation occurs but the field remains in that text field, I want clear the text field after validation occurs...spring form field clearence  hi, I have spring form application
Unique field
Unique field  I have created a form where I have a textbox and a button. When I write something in the textbox and click on submit,it should go to database but at the same time, it should give an alert if the text entered
iphone text field example
in this application, First 2 takes the input from the user and the last text field prints the added values of above text fields into it on button click(Submit button... readable. Now go to Tools->Inspector->Text Field Attributes-> Interaction
File Upload in struts2 - Invalid field value for field
File Upload in struts2 - Invalid field value for field   Hi I am... : Invalid field value for field "upload". My webContents->Web-Inf->lib...="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1
form field issue
form field issue  how to set the values in form field and form field drop down (doc 2007) using Apache poi
how to get the anchor field in hidden field tag
how to get the anchor field in hidden field tag  I have a following code I need to have the value of property "emp" in a hidden field also. when i try to put the following code, I cant get the hidden tag when i see the source
JSTL: Form Action Text Field
JSTL: Form Action Text Field          In this example we are going...; <input type="text" name="name"/> </td> </tr>
php array sort by field
php array sort by field  Array sort by field in PHP
the focus to the first form field
the focus to the first form field   How do I set the focus to the first form field
 

 

 

DMCA.com