Win a copy of Escape Velocity: Better Metrics for Agile Teams this week in the Agile and Other Processes forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Liutauras Vilda
  • Tim Cooke
  • Paul Clapham
  • Jeanne Boyarsky
  • Ron McLeod
  • Frank Carver
  • Junilu Lacar
Saloon Keepers:
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
  • Piet Souris
  • Frits Walraven
  • fred rosenberger

how to solve the error?

Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello All

How to solve the error in this program...
Iam getting an error in d=md.Operations();

Iam just trying to get two numbers from The applet and performing Add/Sub/Mul/Div according the button pressed.

I have to write 4 actions in a single i hav used if stmt with get().

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.util;
import java.util.*;

public class FinalThreadDemo extends JFrame implements ActionListener

JFrame frm;
JPanel panel;
JLabel label1;
JLabel label2
JTextField tf1;
JTextField tf2;
JButton button1;
JButton button2;
JButton button3;
JButton button4;
GridLayout gl;

public FinalThreadDemo( )
super("FinalThread Demo");

JFrame frm=new JFrame("Arithmetic Operations");
JPanel panel=new JPanel( );
GridLayout gl=new GridLayout(4,4);
JLabel label1=new JLabel("FirstNumber");
JLabel label2=new JLabel("Second Number");
JTextField tf1=new JTextField(10);
JTextField tf2=new JTextField(10);
JButton button1=new JButton( );
JButton button2=new JButton( );
JButton button3=new JButton( );
JButton button4=new JButton( );





public void ActionListener(actionPerformed ae)

public void Operations(int a,int b)

if(ae.getText( )==Add)
return c;

return c;

if(ae.getText( )==Mul)
return c;

if(ae.getText( )==Div)
return c;


public static void main(String args[])

BufferedReader keyboardInput1 = new BufferedReader(new InputStreamReader(;
BufferedReader keyboardInput2 = new BufferedReader(new InputStreamReader(;

int a= Integer.parseInt(keyboardInput1.readLine());
int b=Integer.parseInt(keyboardInput2readLine());

javax.swing.SwingUtilities.invokeLater(new Runnable()
public void run()
int d;
FinalThreadDemo md=new FinalThreadDemo();



Ranch Hand
Posts: 1228
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It would be nice if you post the error you got.
Posts: 17347
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Also, we have a "CODE" tag, that can be created by clicking the CODE button,
which is located under the "Add Reply" button, along with URL, BOLD, etc. buttons

This tag will enable you to keep your formatting for your code, like indentation, and makes your code readable.
The way your code is posted makes it difficult to read, and therefore, more difficult for us to help you.


author and iconoclast
Posts: 24204
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The call to md.Operations() is in an anonymous Runnable class. The parameters you're passing are local variables in the surrounding methods. Under these circumstances, Java requires that such variables be "final", so making "a" and "b" final will fix that compile error.

Now, there are several other major things I want to tell you about. First of all, Integer.parseInt() will report failure by throwing a NumberFormatException; you really need to catch those instead of simply trusting that the input parameters are OK.

The second one is that Java has a firmly entrenched, but simple, set of naming conventions. Don't capitalize method names like "Operations" -- method namesand variable names should always start with a lower-case letter, while class names should always start with an upper-case letter.

Thirdly, don't ever, ever, compare Strings using the "==" operator; even if it seems to work, relatively minor changes to a program can make it stop working. Instead, use the equals() method to do the comparison --

if (s1.equals(s2)) ...
Hold that thought. Tiny ad:
the value of filler advertising in 2021
    Bookmark Topic Watch Topic
  • New Topic