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



Home Answers Viewqa Swing-AWT java textfield problem
Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


om
java textfield problem
0 Answer(s)      a year and 3 months ago
Posted in : Swing AWT


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

Related Tutorials/Questions & Answers:
java textfield problem
java textfield 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
Java textfield validaton
Java textfield validaton  Sir... i'm new to java. In java JTextfield when we entered a negative value after pressing one button it have to display an error message dialog of textfield and also the textfield should accept
Advertisements
Java textfield validaton
Java textfield validaton  Sir... i'm new to java. In java JTextfield when we entered a negative value after pressing one button it have to display an error message dialog of textfield and also the textfield should accept
How to Type in japanese in java Textfield?
How to Type in japanese in java Textfield?  Hello Sir/madam; Am creating an application in java in which i want to get a japanese String input from... in textfield ..Please help me and tell me how to write in japanese
Simple Java applet that need usernam, password and textfield.
Simple Java applet that need usernam, password and textfield.  Hi. Anyone can help me on this matter: I need to create a small application... a textfield box. Anything that been input to that textbox will be transfer to DB2
data to the textfield by means of an actionListener - Java Beginners
data to the textfield by means of an actionListener  how can i put the data of the database 1 at a time to the textfields by means of an actionlisteners and can be view by next or previous
Validate textfield in Java Swing
Validate Jtextfield in Java Swing In this section,you will learn how to validate the textfield by allowing only numbers to enter. For this purpose, we have used the keyEvent class.Using the method getKeyChar() of keyEvent class, we have
TextField on the Image
TextField on the Image  how we set label or textfield etc. on the Image
java run time textfield and use with map - Java Beginners
java run time textfield and use with map  i want to program which read data from file and store in map and display in different textfields which are generated at run time like a text file store information class a1
TextField
TextField      ... as the TextField. In the example given below, shown a textfield in the applet by creating its...;TextField("Type in the box");    add(tf); 
TextField validations
TextField validations  I want to know How to check first letter capital or not in a text field and also check all are characters or not in same textfield? and also want to know how to check all digits or not in a textfield? ex
TextField validations
TextField validations  I want to know How to check first letter capital or not in a text field and also check all are characters or not in same textfield? and also want to know how to check all digits or not in a textfield? ex
java Problem
java Problem  I want to create a binary tree for displaying members in Downline. i am creating a site for MLM(Multi-Level MArketing). tree must be dynamically populated from database. is there any help for me. Thanks in advance
JAVA Problem
JAVA Problem  Write a program that takes two parameters 1. a word 2. an array of words It should then remove all instances of the word in the array. For Example: INPUT word="ravi" word_array = ["Chethan Bhagat
textfield selected text
textfield selected text  How to select text in text field
how to set size of button,textfield.
how to set size of button,textfield.  how we set size of button textfield etc and reduce problem when click maximize button the text or textfield get large how to set as a preferd size in the panel or frame .when we click
s:textfield - Struts
s:textfield  I am using the s:textfield tag in an appication and need... this?  Hi friend, Textfield Tag Example Textfield Tag Example
resolution problem in java
resolution problem in java  I designed project in java in my PC when run the same project in some other PC i can't fully view my java forms.Some said that it is resolution problem
java input problem - Java Beginners
java input problem  I am facing a Java input problem
java applet problem - Applet
java applet problem  i was doing a program using java applet. I want... ActionListener{ TextField text1,text2,text3,text4; Label l1,l2,l3,l4; Label... void init(){ text1 = new TextField(12); text2= new TextField(12
java programming problem - JDBC
java programming problem  Hi, Request you to provide the source code in Java for the following programming problem : upload .csv file data into oracle database. please send the solution to raichallp@yahoo.in
Java Problem - Java Beginners
Java Problem  Write a program 2 input a positive integer n and check wheter n is prime or not and also know the position of that number in the prime..., Code to solve the problem : import java.io.*; public class PrimeNumber
IPhone-UIPicker Data to TextField
IPhone-UIPicker Data to TextField  When I select the textfield, a picker view must come in form of action sheet and the data selected from that picker view must be populated in the text field. can anyone help me on this please
Problem in uploading java application
Problem in uploading java application  I have uploaded my java application (folder created under webapps) using Filezilla FtpClient.Application... this problem
Java problem - Java Beginners
Java problem  what are threads in java. what are there usage. a simple thread program in java  Hi Friend, Please visit the following link: http://www.roseindia.net/java/thread/index.shtml Thanks
for a problem in coading - Java Beginners
for a problem in coading  what is the problm in following coading...(String[] args) { mywindow (); } }   Hi Friend, There is no problem... mywindows.java Run : java mywindows Thanks RoseIndia Team
Multiplication problem - Java Beginners
Multiplication problem  I am facing a peculiar problem in java regarding a multiplication. Please see below: 19300 * 0.001 = 19.3 19400 * 0.001 = 19.400000000000002 (why is this ??) 19500 * 0.001 = 19.5 Can anybody help
get textfield value in javascript
get textfield value in javascript  How to get and the set value of text field in JavaScript?   Get the text field value in JavaScript <html> <head> <script type="text/javascript"> <
how to set the value of textfield constant
how to set the value of textfield constant  how to set the value of textfield constant
Java problem - Java Beginners
Java problem  I have an image in my application and I need to restrict the image path view on the browser. Noone should be able to right click and see the image path. Please help
 

 

 

DMCA.com