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 is the code

import javax.swing.*;

import java.awt.event.*;

class Frame1 extends JFrame

{

private JButton btn1;

private JTextField tf1;
public Frame1()
{
    setLayout(null);
    setSize(500,500);
    tf1=new JTextField();
    tf1.setBounds(100,100,100,30);
    btn1=new JButton("click for second frame");
    btn1.setBounds(100,250,100,30);
    btn1.addActionListener(new ActionListener(){
        public void actionPerformed(ActionEvent e)
        {
            String text=tf1.getText();
            new Frame2(text);
        }
    });
add(tf1);
add(btn1);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setVisible(true);
}
public JTextField getTextField1()
{
    return tf1;
}

} class Frame2 extends JFrame { private JButton btn2; private JTextField tf2; private String secondtext; public Frame2() {

}
public Frame2(String firsttext)
{
    setLayout(null);
    setSize(500,500);
    tf2=new JTextField();
    tf2.setText(firsttext);
    secondtext=tf2.getText();
    tf2.setBounds(100,100,100,30);
    btn2=new JButton("click for first frame");
    btn2.setBounds(100,250,100,30);
    btn2.addActionListener(new MyActionListener());
    add(tf2);
    add(btn2);
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    setVisible(true);
}
public JTextField getTextField2()
{

    return tf2;
}
public String getText()
{

    return secondtext;

}

} class MyActionListener extends Frame1 implements ActionListener { private String text; private JTextField tf1; private JTextField tf2; private Frame2 frame2; public MyActionListener() {

    super();
    frame2=new Frame2();
    text=frame2.getText();
    modify();
}
public void actionPerformed(ActionEvent e)
{
    new MyActionListener();
}
public void modify()
{
    tf1=super.getTextField1();
    tf2=frame2.getTextField2();
    tf1.setText(text);
}

}

class MyFrame
{

public static void main(String args[])

{

new Frame1();

} }

View Answers









Related Tutorials/Questions & Answers:
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
Advertisements
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...://www.roseindia.net/java/example/java/swing/ Thanks. Amardeep
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
text field
text field  How to retrieve data from text field   Hi Friend, Try the following code:ADS_TO_REPLACE_1 import java.awt.*; import javax.swing.*; import java.awt.event.*; class RetrieveDataFromTextFields{ public
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 Problem on submission of button
Swing Problem on submission of button  How to close current frame (Frame1) and open a new frame (Frame2) already created and pass the data to frame2 from frame1 on the clicking of button in swing
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
problem in swing-awt
problem in swing-awt  I am doing project in core java and i am facing one problem. I have to add command prompt(terminal) to the fream at bottom but not getting the solution. So please help me. thanks and regards, Aakash
jdbc and swing problem in netbeans
jdbc and swing problem in netbeans  i reteived the table from database in a jdbc program. next i want to do is place the table as it is in a jpanel.. i am using netbeans IDE can u tel me how to do that one?? urgent
jdbc and swing problem in netbeans
jdbc and swing problem in netbeans  i reteived the table from database in a jdbc program. next i want to do is place the table as it is in a jpanel.. i am using netbeans IDE can u tel me how to do that one?? urgent
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 (adsbygoogle = window.adsbygoogle || []).push
Swing and AWT Problem - Swing AWT
Swing and AWT Problem  hi sir i have a problem i know from one Jframe we can send values to another Jframe. so in my project i have one fame containing three textfields CODE: String a=TNa.getText().toString(); String b
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. (adsbygoogle = window.adsbygoogle || []).push
swing frame problem
swing frame problem  Hi All, I m creating a swing/awt based window application which will take some data from user and according to that data... a frame which have few buttons and Text Box to get some data from user at this time
tooltip problem - Swing AWT
tooltip problem  Hi All, I am using SWT_AWT bridge in my code to embed swing components into SWT Composite. I am using a Swing JButton in SWT Composite. My problem is that I am unable to see the tooltip for this button even
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
iPhone Text Field Border 
into the text field without any problem. After doing this will open Interface...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
Java Problem Steps - Swing AWT
Java Problem Steps  How to create a Jar File From the Dos prompt of a Swing program having two classes in the program with one is public class one of them
problem with JTable - Swing AWT
problem with JTable  hi guys, i was a student and i am very new to swings.i was having an assignment like i need to create a JTable with checkboxes inside it.i do have another checkbox outside the Table.i need to write
Digit Only text field
Digit Only text field  How should we accept digits only in a textbox? (using JSTL only, without Javascript
two text box problem
two text box problem  i have two text box in two different pages and same variable use in two text box when enter value in first text box it's reflection show in second text box , how i reduce it in jsf ?   Hi Friend
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
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
Multiple session problem - Swing AWT
Multiple session problem  I am working in a Linux based java swing application. Problem: I have optimized JDialog and JPanel for my use.... This problem is quite critical as UI looks quite unpredictable due
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
java swing problem - Java Beginners
java swing problem  i doesn't know about the panel in swings here i had created one frame then created a panel and i added that to my frame but which is not adding any item and it not showing that item on the panel tell me how
Jfree chart problem - Swing AWT
Jfree chart problem  hello i have a problem related to jfree chart i have some data and i want to display data in two different chart stacked area chart and line chart both in a single frame. That is hybrid combination
Java Swings problem - Swing AWT
Java Swings problem  Sir, I am facing a problem in JSplitPane. I want the divider in the splitpane to be customized. I have a splitpane with Horizontal orientation and here, there lies the divider between left component and right
Frame refresh problem - Swing AWT
to correct this problem....its urgent!! thnks in adv..  Hi Friend
Text Field in HTML
Text Field in HTML       The Text Field in HTML are one line areas, which enable the user... an example from Text Field in HTML.In this Tutorial, the code create a text
ModuleNotFoundError: No module named 'django-storage-text-field'
ModuleNotFoundError: No module named 'django-storage-text-field'  Hi...: No module named 'django-storage-text-field' How to remove the ModuleNotFoundError: No module named 'django-storage-text-field' error? Thanks  
ModuleNotFoundError: No module named 'django-short-text-field'
ModuleNotFoundError: No module named 'django-short-text-field'  Hi...: No module named 'django-short-text-field' How to remove the ModuleNotFoundError: No module named 'django-short-text-field' error? Thanks   
ModuleNotFoundError: No module named 'django-storage-text-field'
ModuleNotFoundError: No module named 'django-storage-text-field'  Hi...: No module named 'django-storage-text-field' How to remove the ModuleNotFoundError: No module named 'django-storage-text-field' error? Thanks  
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
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
validating text fields - Swing AWT
validating text fields  hi i am using NETBEANS IDE so when i want to validate TEXTFEILDS if one textfield is blank then it should focus on that particular textfield so help me with this plz..... /* * To change this template
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
SWT_AWT bridge ,jtextfield edit problem - Swing AWT
bridge in my code to embed swing components in to SWT Composite. I am using SWT_AWT bridge frame and adding JTextfield to it, My problem is that the JTextfield...); Thanks in advance.  Hi friend, Code to solve the problem
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
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..  
New Problem in Form Resizing - Swing AWT
New Problem in Form Resizing  Hi, I am using a MDI application...)); The problem is arising when the user resizes the form. The EditorPane(old... HeadPane.setBounds(0, 0, this.getWidth(), 100); But it creates another problem. it overwrites
Problem when resizing the form - Swing AWT
Problem when resizing the form  Hi, I am facing a problem when resizing the form. I have a JTextPane on the JInternalFrame which occupy all... The EditorPane(Old) overlaps the HeadPane(new). I think this problem is occuring whenever
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
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
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
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...;input> </form> Text Fields: Text fields
problem in swing program for opening two windows with same login credentials
problem in swing program for opening two windows with same login credentials  I Face two problems while writing the code in swing program 1.i... representation problem is when i delete a node the tree is not automatically

Ads