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



Home Answers Viewqa Java-Beginners swing text field problem
Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


om
swing text field problem
3 Answer(s)      a year and 6 months ago
Posted in : Java Beginners


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

} }


Advertisement
View Answers

June 10, 2013 at 5:13 PM


try to do like the following :

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,200,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 Frame1(String text1)
    {
        setLayout(null);
        setSize(500,500);
        tf1=new JTextField();
        tf1.setText(text1);
        tf1.setBounds(100,100,100,30);
        btn1=new JButton("click for second frame");
        btn1.setBounds(100,250,200,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;
    }   
}

Continue...



June 10, 2013 at 5:14 PM


import javax.swing.*; import java.awt.*; import java.awt.event.*; class Frame2 extends JFrame { private JButton btn2; private JTextField tf2; private String secondtext;

    private Frame1 frame1;

    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,200,30);
        //btn2.addActionListener(new MyActionListener());
        btn2.addActionListener(new ActionListener()
        {
          public void actionPerformed(ActionEvent ae)
          {
              secondtext=tf2.getText();           
              frame1 = new Frame1(secondtext);
          }
        });
        add(tf2);
        add(btn2);
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        setVisible(true);
    }
    public JTextField getTextField2()
    {
        return tf2;
    }
    public String getSecondText()
    {
        return secondtext;
    }
}

Continue...



June 10, 2013 at 5:15 PM


class MyFrame { public static void main(String args[]) { new Frame1(); } }

Thanks.



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: import java.awt.*; import javax.swing.*; import java.awt.event.*; class RetrieveDataFromTextFields{ public static void main
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
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
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
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
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
Digit Only text field
Digit Only text field  How should we accept digits only in a textbox? (using JSTL only, without Javascript
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
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
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
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
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
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
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
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
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 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..  
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
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
Advertisements
 

 

 

DMCA.com