Start New Discussion within our Software Development Community

consider a instance

jtextfield t=new jtextfield();
jtextfield t1=new jtextfield();
jtextfield t2=new jtextfield();
i want to get the values of textfield t and t1 and display in t2
like i want to add values of t and t1 and store in t2

Have a look at the getText() and setText(String text) methods that JTextField inherits from JTextComponent.
ps Watch out for your capitalisation - java is case-sensitive

import java.awt.*;

import javax.swing.*;

import java.awt.event.*;

class calc extends JFrame 
	JTextField t1=new JTextField();
	JTextField t2=new JTextField();
	JTextField t3=new JTextField();
JButton	b1=new JButton("+");
  JButton b2=new JButton("-");
  JButton b3=new JButton("*");
  JButton b4=new JButton("/");
  JPanel panel=new JPanel(new GridLayout(2,2));

		b1.addActionListener(new ActionListener(){
			public void actionperformed(ActionEvent e)
			b1.addActionListener(new ActionListener(){
				public void actionperformed(action event e)
	public static void main(string args[])
		calc frame=new calc();

this is my problem i want to do a simple calculator please solve me

Have another look at setText... your syntax is wrong in

We will help you with your problem, but it's your homework, we won't do it for you. You have made a start, so keep going! If you get stuck post your latest code and the details of why you're stuck, and someone will help.

sir i didnt tel you to solve my problem sir my doubt is in


i dont know what to do over there
if i do t1.gettext() how will it get value sir ????? i just need to get the value of two text fields and display in t3

t1.getText() will give you the current contents of the field as a String.
Next you have to convert that to a numeric value (eg int or float).
Then you can add/subtract etc the values
Then convert the result back to a String
Finally set the result field's text to that String.

To convert between Strings and numbers there are useful methods in the appropriate numeric classes, eg
Integer.parseInt(aString); // converts String to Integer
Integer.toString(anInt): // converts int to String
You should look these up yourself to learn about them properly.

so can i use integer.parse method will it convert string to integer??

This article has been dead for over six months. Start a new discussion instead.