Results 1 to 11 of 11
Thread: calculator
- 04-24-2011, 07:51 PM #1
Member
- Join Date
- Apr 2011
- Posts
- 32
- Rep Power
- 0
calculator
Java Code:import javax.swing.*; import java.awt.*; import java.awt.event.*; class calculator extends JFrame { JPanel p1=new JPanel(); JTextField t1=new JTextField(); JTextField t2=new JTextField(); JTextField t3=new JTextField(); JButton b1=new JButton("+"); public calculator() { p1.add(t1); p1.add(t2); p1.add(t3); p1.add(b1); b1.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { String value=t1.getText(); String value1=t2.getText(); t3.setText()=value+value1; } }); } public static void main(String args[]) { calculator frame=new calculator(); } }
hello actually i use three textboxes third textbox i want to display the output
one and two textbox will get and display in output.but i have done only for additon beacuse its gettting error i dont know what to do ?????please help me sir
- 04-24-2011, 07:57 PM #2
Member
- Join Date
- Apr 2011
- Posts
- 32
- Rep Power
- 0
i dont know how to get values from text1 and text2
- 04-24-2011, 08:41 PM #3
Member
- Join Date
- Apr 2011
- Posts
- 32
- Rep Power
- 0
hello please help
-
You're already getting values from the two JTextFields. What you're not doing is parsing them -- check out either Double.parseDouble(...) or Integer.parseInt(...) depending on what is being entered, or setting the text in the third properly -- you must pass a String into the setText(...) method, or it seems adding your JPanel p1 to the JFrame. Lot's of errors there. Have you gone through the tutorials? Also if you have errors in your code, please post the error messages themselves and indicate which line causes them.
- 04-24-2011, 09:00 PM #5
Member
- Join Date
- Apr 2011
- Posts
- 32
- Rep Power
- 0
this is the error message
Exception in thread "main" java.lang.Error: Unresolved compilation problem:
The left-hand side of an assignment must be a variable
at calculator.<init>(calculator.java:31)
at calculator.main(calculator.java:45)
-
Good, but which line? Probably this one:
You've got a method on the left and an equation on the right -- makes no sense.Java Code:t3.setText()=value+value1;
You must do the addition and put it into a variable, then change that into a String -- String.valueOf(myNumberVariable) will work for this, and then call setText passing this String into the method. Again, please read the tutorials for more on this.
- 04-24-2011, 09:10 PM #7
Member
- Join Date
- Apr 2011
- Posts
- 32
- Rep Power
- 0
tutorails mean??? where is it?? iam reading from ebooks sir
- 04-24-2011, 09:12 PM #8
Member
- Join Date
- Apr 2011
- Posts
- 32
- Rep Power
- 0
i want link tutorials from this one
- 04-24-2011, 11:10 PM #9
Trail: Graphical User Interfaces (The Java™ Tutorials)
EDIT: Actually, you don't seem to know how to use methods so I suggest reading this instead.
- 04-25-2011, 07:21 PM #10
Member
- Join Date
- Apr 2011
- Posts
- 32
- Rep Power
- 0
sir i know to parse but how can i do it please show me some examples like this similiar to this
- 04-25-2011, 11:24 PM #11
That is not valid Java syntax.Java Code:t3.setText()=value+value1;
What you need is to do Double.parseDouble(value) and value1 and add the returned values together to set it in "t3".
Similar Threads
-
Help with AWT CALCULATOR
By Megan Dosnueve in forum AWT / SwingReplies: 2Last Post: 04-04-2011, 05:49 PM -
Calculator
By Moshe22 in forum New To JavaReplies: 8Last Post: 01-17-2011, 05:29 AM -
Help in a calculator
By Ayannie in forum New To JavaReplies: 6Last Post: 01-04-2011, 08:21 PM -
help with calculator
By kalibballer in forum New To JavaReplies: 8Last Post: 04-01-2009, 12:57 PM -
Calculator help.
By madkidd02 in forum New To JavaReplies: 2Last Post: 10-25-2008, 07:42 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks