Jump to content

There are sum errors in my prgm......plz help me to compile it...thnxx?

- - - - -

  • Please log in to reply
1 reply to this topic

#1
shakky

shakky

    Newbie

  • Members
  • Pip
  • 1 posts
import javax.swing.*;

import java.awt.*;

import java.awt.event.*;

import java.text.*;

public class calc extends JFrame implements ActionListener

{

JLabel lab1,lab2,lab3;

JTextField tf1,tf2,tf3;

Jbutton but[];

Container C;

public static void main(String args[])

{

calc win=new calc();

win.setSize(400,400);

win.setVisible(true);

win.setDefaultCloseOperation(WindowCon…

public calc()

{

C=getContentpane();

C.setLayout(new FlowLayout());

lab1=new JLabel("1st no");

lab2=new Jlabel("2nd no");

lab3=new JLabel("result");

tf1=new JTextField(10);

tf2=new JTextField(10);

tf3=new JTextField(10);

C.add(lab1);

C.add(tf1);

C.add(lab2);

C.add(tf2);

C.add(lab3);

C.add(tf3);

String s[]={"+","-","*","/","SQRT","POW","MAX",…

but=new Jbutton[8];

for(int i=0;i<=7;i++)

{

but[i]=new JButton(s[i]);

C.add(but[i]);

but[i].addActionListener(this);

}

tf3.setEditable(false);

}

public void actionPerformed(ActionEvent e)

{

DecimalFormat df=new DecimalFormat("0.00");

int x=Integer.parseInt(tf1.getText());

int y=Integer.parseInt(tf2.getText());

if(e.getSource()==but[0])

tf3.setText((x+y)+" ");

else

if(e.getSource()==but[1])

tf3.setText((x-y)+" ");

else

if(e.getSource()==but[2])

tf3.setText((x*y)+" ");

else

if(e.getSource()==but[3])

tf3.setText(df.format((double)x/y)+" ");

else

if(e.getSource==but[4])

tf3.setText(df.format(Math.sqrt(x)));

else

if(e.getSource==but[5])

tf3.setText(df.format(Math.pow(x,y)));

else

if(e.getSource==but[5])

tf3.setText(df.format(Math.max(x,y)));

else

system.exit(0);

}

}

}


ERRORS:

calc.java:17: illegal start of expression
public calc()
^
calc.java:17: ';' expected
public calc()
^
calc.java:43: illegal start of expression
public void actionPerformed(ActionEvent e)
^
calc.java:43: illegal start of expression
public void actionPerformed(ActionEvent e)
^
calc.java:43: ';' expected
public void actionPerformed(ActionEvent e)
^
calc.java:43: ';' expected
public void actionPerformed(ActionEvent e)
^
6 errors

Edited by ZekeDragon, 25 April 2011 - 03:34 AM.
Please use [CODE] tags (the # button) when posting code.


#2
wim DC

wim DC

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 2,084 posts
  • Programming Language:Java, JavaScript, PL/SQL
  • Learning:Java
You're declaring methods in methods. You can never do that. They shouldn't be nested but just be listed under eachother.
It should look like this:

import javax.swing.*;

import java.awt.*;

import java.awt.event.*;

import java.text.*;

public class calc extends JFrame implements ActionListener

{

	JLabel lab1,lab2,lab3;

	JTextField tf1,tf2,tf3;

	Jbutton but[];

	Container C;

	

	public calc()

	{

		C=getContentpane();

		C.setLayout(new FlowLayout());

		lab1=new JLabel("1st no");

		lab2=new Jlabel("2nd no");

		lab3=new JLabel("result");

		tf1=new JTextField(10);

		tf2=new JTextField(10);

		tf3=new JTextField(10);

		C.add(lab1);

		C.add(tf1);

		C.add(lab2);

		C.add(tf2);

		C.add(lab3);

		C.add(tf3);

		String s[]={"+","-","*","/","SQRT","POW","MAX",…

		but=new Jbutton[8];

		for(int i=0;i<=7;i++)

		{

		but[i]=new JButton(s[i]);

		C.add(but[i]);

		but[i].addActionListener(this);

		}

		tf3.setEditable(false);

		}

	}

	

	public void actionPerformed(ActionEvent e)

	{

		DecimalFormat df=new DecimalFormat("0.00");

		int x=Integer.parseInt(tf1.getText());

		int y=Integer.parseInt(tf2.getText());

		if(e.getSource()==but[0])

		tf3.setText((x+y)+" ");

		else

		if(e.getSource()==but[1])

		tf3.setText((x-y)+" ");

		else

		if(e.getSource()==but[2])

		tf3.setText((x*y)+" ");

		else

		if(e.getSource()==but[3])

		tf3.setText(df.format((double)x/y)+" ");

		else

		if(e.getSource==but[4])

		tf3.setText(df.format(Math.sqrt(x)));

		else

		if(e.getSource==but[5])

		tf3.setText(df.format(Math.pow(x,y)));

		else

		if(e.getSource==but[5])

		tf3.setText(df.format(Math.max(x,y)));

		else

		system.exit(0);

	}

		

	public static void main(String args[])

	{

		calc win=new calc();

		win.setSize(400,400);

		win.setVisible(true);

		win.setDefaultCloseOperation(WindowCon…		

	}

}






1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users