Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to solve the Error

 
Viji be
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • 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 function...so 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( );
button1.setText("Add");
JButton button2=new JButton( );
button2.setText("Sub");
JButton button3=new JButton( );
button3.setText("Mul");
JButton button4=new JButton( );
button4.setText("Div");

panel.add(l1);
panel.add(l2);
panel.add(tf1);
panel.add(tf2);
panel.add(button1);
panel.add(button2);
panel.add(button3);
panel.add(button4);

panel.setLayout(gl);

frm.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frm.setVisible(true);
frm.setSize(400,400);

this.getContentPane.add(panel);

public void ActionListener(actionPerformed ae)
{

public void Operations(int a,int b)
{

if(ae.getText( )==Add)
{
c=a+b;
return c;
}

if(ae.getText()==Sub)
{
c=a-b;
return c;
}

if(ae.getText( )==Mul)
{
c=a*b;
return c;
}

if(ae.getText( )==Div)
{
c=a/b;
return c;
}

}

public static void main(String args[])
{

BufferedReader keyboardInput1 = new BufferedReader(new InputStreamReader(System.in));
BufferedReader keyboardInput2 = new BufferedReader(new InputStreamReader(System.in));

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();
d=md.Operations(a,b);
}

});

}

}
 
Arto Pastinen
Ranch Hand
Posts: 79
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi!

Could you post stack trace (that error)

- Artsi
 
Srinivasa Raghavan
Ranch Hand
Posts: 1228
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi dude No Cross Post in ranch.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic