• Post Reply Bookmark Topic Watch Topic
  • New Topic

Problem in Java Swing Program

 
Randika Isuru
Ranch Hand
Posts: 38
Java Linux Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,

please see the below code and give me way to correct my problem,, if you any another suggestion to do this program any other way i like to know that this is my code..



problem is come out inside a actionperformed (). what i need, just add a two numbers and put into a JTextfield. can any one help me to solve this problem.


E:\OCJP Practicals\Sample Example for Test\Add_2_Num>javac Add2Num.java
Add2Num.java:60: error: local variable jtnum1 is accessed from within inner class; needs to be decla
red final
no1 = Integer.parseInt(jtnum1.getText());
^
Add2Num.java:61: error: local variable jtnum2 is accessed from within inner class; needs to be decla
red final
no2 = Integer.parseInt(jtnum2.getText());
^
Add2Num.java:65: error: local variable jtsum is accessed from within inner class; needs to be declar
ed final
jtsum.setText(tot);
^
Add2Num.java:65: error: method setText in class JTextComponent cannot be applied to given types;
jtsum.setText(tot);
^
required: String
found: int
reason: actual argument int cannot be converted to String by method invocation conversion
4 errors



This compile error commad line gives me when i run this program..

 
Randika Isuru
Ranch Hand
Posts: 38
Java Linux Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi all,

hey i solve this problem myself sorry for bothering your all.

Thank you..
 
Tony Docherty
Saloon Keeper
Posts: 3138
72
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well done and thanks for updating the thread.
 
Campbell Ritchie
Marshal
Posts: 52516
119
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I presume you did that by declaring the local variables final. You will find an explanation of that here, or here.
If the variable were not final, there would be a risk that the inner class copy and the original would have different values.

I shall move this discussion to our Swing forum
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!