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
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 problemswing 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 problemswing 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 AWTfocus
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 AWTfocus
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 fieldtext 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 FIELDCALULATION 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 buttonSwing 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 fileText 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-awtproblem 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 netbeansjdbc 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 netbeansjdbc 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 sqlconverting
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 AWTSwing 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 blankjsf
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 problemswing 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 AWTtooltip 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 iPhonevalidate
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 AWTJava
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 AWTproblem 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 fieldDigit Only
text field How should we accept digits only in a textbox?
(using JSTL only, without Javascript
two text box problemtwo
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
clearing text field in spring formclearing
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 AWTMultiple 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 Beginnerstext 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 Beginnersjava
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 AWTJfree 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 AWTJava 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
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 validating text fields - Swing AWTvalidating
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 questioJSP 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 iPhoneHow 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 fieldfetch 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 fieldfetch 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 AWTNew
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 AWTProblem 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 Beginnersset
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
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