Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 8 of 8

Thread: Calculator Using AWT

  1. #1
    Junior Member
    Join Date
    Mar 2011
    Posts
    14
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Calculator Using AWT

    My code is not working for some reason, help? When I try to compile, it says that there are 34 errors, many stating "illegal start of expression" and "';' expected"


    import java.io.*;
    import java.lang.Math.*;
    import java.awt.*;
    import java.awt.event.*;
    import java.awt.Component.*;

    public class Calculator extends Frame implements ActionListener, WindowListener

    /* EQUAL
    * POINT
    * DECIMAL
    * C
    * MATH */

    {

    //1 Window
    TextField Txwindow;

    //29 Buttons
    Button b1,b2,b3,b4,b5,b6,b7,b8,b9,b0; //10 Buttons on this Line
    Button b10algo,blog,bealgo,bln; //4 Buttons on this Line
    Button bpi,broot,bpower,be; //4 Buttons on this Line
    Button bsin, bcos, btan, btrig; //4 Buttons on this Line
    Button bclear,bpoint,bequal; //3 Buttons on this Line
    Button badd,bsub,bmulti,bdivi; //4 Buttons on this Line

    //5 Panels
    Panel panelNorth,panelSouth,panelEast,panelWest,panelCen ter;

    int x;

    String aux1;
    String aux2, lastCommand;
    String value, calcDisplay;
    int op, counter=0;

    boolean point=false;

    double n1,n2,n3,n4,preAns,secVal;
    double answer=0,ans;

    public static void main(String[] args) throws IOException
    {
    Calculator form=new Calculator(); //Creates a specified class
    form.setSize(400,600); //Establishes Size of Window
    form.setTitle ("CASIO FX-Superb007"); //This is the Title
    form.setVisible(true); //The Window will Become Visible

    }

    public Calculator() throws IOException {

    //Layout Head
    setLayout(new BorderLayout(1,1));//Head, Beginning

    //Panel
    panelNorth= new Panel(new FlowLayout());
    panelSouth= new Panel(new GridLayout(1,1));

    panelEast= new Panel(new GridLayout(4,1));
    panelWest= new Panel(new GridLayout(5,1));
    panelCenter= new Panel(new GridLayout(6,3));

    //North Finished
    Txwindow= new TextField(50);
    Txwindow.setEditable(false);
    panelNorth.add(Txwindow);

    //South Finished

    bequal= new Button("="); //Equal Button
    panelSouth.add(bequal);
    //listener
    bequal.addActionListener(this);

    //West Finished

    b10algo= new Button("10^x"); //10^algo
    blog= new Button("+/-"); //Log
    bealgo= new Button("e^x"); //E^algo
    bln= new Button("Ln"); //Ln
    be= new Button("e"); //e

    panelWest.add(b10algo);
    panelWest.add(blog);
    panelWest.add(bealgo);
    panelWest.add(bln);
    panelWest.add(be);

    //listener
    b10algo.addActionListener(this);
    blog.addActionListener(this);
    bealgo.addActionListener(this);
    bln.addActionListener(this);
    be.addActionListener(this);

    //East Finished

    badd= new Button ("+"); //Addition
    bsub= new Button("-"); //Subtraction
    bmulti= new Button("*"); //Multiplication
    bdivi= new Button("/"); //Division

    panelEast.add(badd);
    panelEast.add(bsub);
    panelEast.add(bmulti);
    panelEast.add(bdivi);

    //listener
    badd.addActionListener(this);
    bsub.addActionListener(this);
    bmulti.addActionListener(this);
    bdivi.addActionListener(this);

    //Center Finished

    b1= new Button("1"); //Number 1
    b2= new Button("2"); //Number 2
    b3= new Button("3"); //Number 3
    b4= new Button("4"); //Number 4
    b5= new Button("5"); //Number 5
    b6= new Button("6"); //Number 6
    b7= new Button("7"); //Number 7
    b8= new Button("8"); //Number 8
    b9= new Button("9"); //Number 9
    b0= new Button("0"); //Number 0



    bpi= new Button("Pi");//pi
    bpower= new Button("Power"); //Power
    broot= new Button("Root"); //Root


    bsin= new Button("Sin"); //sin
    bcos= new Button("Cos"); //cos
    btan= new Button("Tan"); //tan


    bPoint= new Button("."); //Point
    bclear= new Button("C"); //clear

    panelCenter.add(bpi);
    panelCenter.add(bpower);
    panelCenter.add(broot);
    panelCenter.add(bsin);
    panelCenter.add(bcos);
    panelCenter.add(btan);
    panelCenter.add(b1);
    panelCenter.add(b2);
    panelCenter.add(b3);
    panelCenter.add(b4);
    panelCenter.add(b5);
    panelCenter.add(b6);
    panelCenter.add(b7);
    panelCenter.add(b8);
    panelCenter.add(b9);
    panelCenter.add(bpoint);
    panelCenter.add(b0);
    panelCenter.add(bclear);

    //listener
    bpi.addActionListener(this);
    bpower.addActionListener(this);
    broot.addActionListener(this);
    bsin.addActionListener(this);
    bcos.addActionListener(this);
    btan.addActionListener(this);
    b1.addActionListener(this);
    b2.addActionListener(this);
    b3.addActionListener(this);
    b4.addActionListener(this);
    b5.addActionListener(this);
    b6.addActionListener(this);
    b7.addActionListener(this);
    b8.addActionListener(this);
    b9.addActionListener(this);
    bpoint.addActionListener(this);
    b0.addActionListener(this);
    bclear.addActionListener(this);

    panelCenter.repaint();


    //Add to Panels, Border Layout

    add(panelNorth, BorderLayout.NORTH);
    add(panelSouth, BorderLayout.SOUTH);
    add(panelEast, BorderLayout.EAST);
    add(panelWest, BorderLayout.WEST);
    add(panelCenter, BorderLayout.CENTER);


    //This Adds a Listener to the Window
    addWindowListener(this); }


    public void repaint(Graphics g){

    //The Color of this
    g.setColor(Color.blue);
    }

    public void actionPerformed(ActionEvent e){

    //input numbers

    if(e.getSource() == b1){ aux1="1"; window=Txwindow.getText()+aux1; Txwindow.setText(value); }
    if(e.getSource() == b2){ aux1="2"; window=Txwindow.getText()+aux1; Txwindow.setText(value); }
    if(e.getSource() == b3){ aux1="3"; window=Txwindow.getText()+aux1; Txwindow.setText(value); }
    if(e.getSource() == b4){ aux1="4"; window=Txwindow.getText()+aux1; Txwindow.setText(value); }
    if(e.getSource() == b5){ aux1="5"; window=Txwindow.getText()+aux1; Txwindow.setText(value); }
    if(e.getSource() == b6){ aux1="6"; window=Txwindow.getText()+aux1; Txwindow.setText(value); }
    if(e.getSource() == b7){ aux1="7"; window=Txwindow.getText()+aux1; Txwindow.setText(value); }
    if(e.getSource() == b8){ aux1="8"; window=Txwindow.getText()+aux1; Txwindow.setText(value); }
    if(e.getSource() == b9){ aux1="9"; window=Txwindow.getText()+aux1; Txwindow.setText(value); }
    if(e.getSource() == b0){ aux1="0"; window=Txwindow.getText()+aux1; Txwindow.setText(value); }
    if(e.getSource() == bpoint&& point==false){ aux1="."; value=Txwindow.getText()+aux1; Txwindow.setText(value); point=true; }

    //The Functions
    if(e.getSource() == bpi){ Txwindow.setText(""+Math.PI); value=""; }
    if(e.getSource() == be){ Txwindow.setText(""+Math.E); value=""; }

    if(e.getSource() == bpower){
    aux2=Txwindow.getText();
    if(!aux2.equals("")){
    preAns=Double.parseDouble(Txwindow.getText());
    lastCommand="power";
    Txwindow.setText("");}}

    if(e.getSource() == broot){

    aux2=Txwindow.getText();
    if(!aux2.equals(""))
    {n1=Double.parseDouble(Txwindow.getText());
    Txwindow.setText(""+Math.sqrt(n1));
    } }

    if(e.getSource() == bsin){

    aux2=Txwindow.getText();
    if(!aux2.equals(""))
    {n1=Double.parseDouble(Txwindow.getText());
    Txwindow.setText(""+Math.sin(Math.toRadians(n1)));
    }}

    if(e.getSource() == bcos){

    aux2=Txwindow.getText();
    if(!aux2.equals(""))
    {n1=Double.parseDouble(Txwindow.getText());
    Txwindow.setText(""+Math.cos(Math.toRadians(n1)));
    } }

    if(e.getSource() == btan){

    aux2=Txwindow.getText();
    if(!aux2.equals(""))
    {n1=Double.parseDouble(Txwindow.getText());
    Txwindow.setText(""+Math.tan(Math.toRadians(n1)));
    } }

    if(e.getSource() == b10algo){

    aux2=Txwindow.getText();
    if(!aux2.equals(""))
    {n1=Double.parseDouble(Txwindow.getText());
    Txwindow.setText(""+Math.pow(10.0,n1));
    } }

    if(e.getSource() == blog){

    aux2=Txwindow.getText();
    if(!aux2.equals(""))
    {n1=Double.parseDouble(Txwindow.getText());
    n1=n1*(-1);
    Txwindow.setText(""+n1);
    } }

    if(e.getSource() == bealgo){

    aux2=Txwindow.getText();
    if(!aux2.equals(""))
    {n1=Double.parseDouble(Txwindow.getText());
    Txwindow.setText(""+Math.pow(Math.E,n1));
    } }

    if(e.getSource() == bln){

    aux2=Txwindow.getText();
    if(!aux2.equals(""))
    {n1=Double.parseDouble(Txwindow.getText());
    Txwindow.setText(""+Math.log(n1));
    } }

    if(e.getSource() == badd){
    aux2=Txwindow.getText();
    if(!aux2.equals("")){
    preRes=Double.parseDouble(Txwindow.getText());
    lastCommand="+";
    Txwindow.setText("");}

    if(e.getSource() == broot){
    aux2=Txwindow.getText();
    if(!aux2.equals("")){
    preRes=Double.parseDouble(Txwindow.getText());
    lastCommand="-";
    Txwindow.setText("");}
    }

    if(e.getSource() == bmulti){
    aux2=Txwindow.getText();
    if(!aux2.equals("")){
    preRes=Double.parseDouble(Txwindow.getText());
    lastCommand="*";
    Txwindow.setText("");}}

    if(e.getSource() == bdivi){
    aux2=Txwindow.getText();
    if(!aux2.equals("")){
    preRes=Double.parseDouble(Txwindow.getText());
    lastCommand="/";
    Txwindow.setText("");}}

    if(e.getSource() == bclear){ Txwindow.setText(""); }

    if(e.getSource() == bequal){
    Double secVal=Double.parseDouble(Txwindow.getText());

    if(lastCommand.equals("+"))
    ans=preAns+secVal;
    else if(lastCommand.equals("-"))
    ans=preAns-secVal;
    else if(lastCommand.equals("*"))
    ans=preAns*secVal;
    else if (lastCommand.equals("/"))
    ans=preAns/secVal;
    else if (lastCommand.equals("power"));
    ans=Math.pow(preAns,secVal);

    Txwindow.setText(" "+ans);
    lastCommand="=";

    }}
    public double calcoperations(int op, double aux2){
    if(op==1)
    {}
    if(op==2)
    {}
    if(op==3)
    {}
    if(op==4)
    {}
    if(op==5)
    {}
    return ans; }

    public void windowClosing(WindowEvent e){

    System.exit(0);
    }
    public void windowActivated(WindowEvent e){
    }
    public void windowClosed(WindowEvent e){
    }
    public void windowDeactivated(WindowEvent e){
    }
    public void windowDeiconified(WindowEvent e){
    }
    public void windowIconified(WindowEvent e){
    }
    public void windowOpened(WindowEvent e){
    }
    }
    Last edited by Allicat; May 15th, 2011 at 08:36 PM.


  2. #2
    Junior Member
    Join Date
    Apr 2011
    Location
    Pune, India
    Posts
    11
    My Mood
    Cool
    Thanks
    0
    Thanked 2 Times in 2 Posts

    Default Re: Calculator Using AWT

    Hi Sorry to tell you, but first start with basics of the java.
    There are lot basic things missed in you code.
    Hardik Jadhav

  3. #3
    Member vanDarg's Avatar
    Join Date
    Jan 2011
    Location
    Chicago
    Posts
    65
    My Mood
    Mellow
    Thanks
    1
    Thanked 7 Times in 7 Posts

    Default Re: Calculator Using AWT

    An "illegal start of expression" error is usually caused by either forgetting a closing bracket '}' or by forgetting to use a delimiter ';'

    It can also be caused by nesting a method within another method
    Last edited by vanDarg; May 16th, 2011 at 05:01 AM.
    "Everything should be made as simple as possible, but not simpler."
    Asking Questions for Dummies | The Java Tutorials | Java Coding Styling Guide

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Calculator Using AWT

    You forgot to post the full text of the error messages. We need them to be able to help you correct your code.
    Last edited by Norm; May 16th, 2011 at 07:22 AM.

  5. #5
    Forum old-timer
    Join Date
    Nov 2008
    Location
    Faversham, Kent, UK
    Posts
    472
    My Mood
    Mellow
    Thanks
    4
    Thanked 58 Times in 54 Posts

    Default Re: Calculator Using AWT

    Also, when posting code, use the [code] tags to keep the formatting, otherwise it's just unreadable.

  6. #6
    Junior Member
    Join Date
    Mar 2011
    Posts
    14
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Calculator Using AWT

    import java.io.*;
    import java.lang.Math.*;
    import java.awt.*;
    import java.awt.event.*;
    import java.awt.Component.*;
     
    public class Calculator extends Frame implements ActionListener, WindowListener
     
    /* EQUAL
     * POINT 
     * DECIMAL 
     * C 
     * MATH */
     
    {
     
    	//1 Window
    	TextField  Txwindow;
     
    	//29 Buttons 
    	Button b1,b2,b3,b4,b5,b6,b7,b8,b9,b0; //10 Buttons on this Line
    	Button b10algo,blog,bealgo,bln; //4 Buttons on this Line
    	Button bpi,broot,bpower,be; //4 Buttons on this Line
    	Button bsin, bcos, btan, btrig; //4 Buttons on this Line
    	Button bclear,bpoint,bequal; //3 Buttons on this Line
    	Button badd,bsub,bmulti,bdivi; //4 Buttons on this Line
     
    	//5 Panels
    	Panel panelNorth,panelSouth,panelEast,panelWest,panelCenter;
     
    	int x;
     
    	String aux1;
    	String aux2, lastCommand;
    	String value, calcDisplay;
    	int op, counter=0;
     
    	boolean point=false;
     
    	double n1,n2,n3,n4,preAns,secVal;
    	double answer=0,ans;
     
    	public static void main(String[] args) throws IOException
    	{
    		Calculator form=new Calculator(); //Creates a specified class
    		form.setSize(400,600); //Establishes Size of Window
    		form.setTitle ("CASIO FX-Superb007"); //This is the Title
    		form.setVisible(true); //The Window will Become Visible
     
    	}
     
    	public Calculator() throws IOException {
     
    		//Layout Head
    		setLayout(new BorderLayout(1,1));//Head, Beginning
     
    		//Panel
    		panelNorth= new Panel(new FlowLayout());
    		panelSouth= new Panel(new GridLayout(1,1));
     
    		panelEast= new Panel(new GridLayout(4,1));
    		panelWest= new Panel(new GridLayout(5,1));
    		panelCenter= new Panel(new GridLayout(6,3));
     
    		//North Finished
    		Txwindow= new TextField(50);
    		Txwindow.setEditable(false);
    		panelNorth.add(Txwindow);
     
    		//South Finished
     
    		bequal= new Button("="); //Equal Button
    		panelSouth.add(bequal);	 
    				//listener
    		bequal.addActionListener(this);
     
    		//West Finished
     
    		b10algo= new Button("10^x"); //10^algo
    		blog= new Button("+/-"); //Log
    		bealgo= new Button("e^x"); //E^algo
    		bln= new Button("Ln"); //Ln
    		be= new Button("e"); //e	
     
    		panelWest.add(b10algo);
    		panelWest.add(blog);
    		panelWest.add(bealgo);
    		panelWest.add(bln);
    		panelWest.add(be);
     
    				//listener	
    		b10algo.addActionListener(this);
    		blog.addActionListener(this);
    		bealgo.addActionListener(this);
    		bln.addActionListener(this);
    		be.addActionListener(this);
     
    		//East Finished
     
    		badd= new Button ("+"); //Addition
    		bsub= new Button("-"); //Subtraction
    		bmulti= new Button("*"); //Multiplication
    		bdivi= new Button("/"); //Division	
     
    		panelEast.add(badd);
    		panelEast.add(bsub);
    		panelEast.add(bmulti);
    		panelEast.add(bdivi);
     
    				//listener
    		badd.addActionListener(this);
    		bsub.addActionListener(this);
    		bmulti.addActionListener(this);
    		bdivi.addActionListener(this);
     
    		//Center Finished
     
    		b1= new Button("1"); //Number 1
    		b2= new Button("2"); //Number 2
    		b3= new Button("3"); //Number 3
    		b4= new Button("4"); //Number 4
    		b5= new Button("5"); //Number 5
    		b6= new Button("6"); //Number 6	
    		b7= new Button("7"); //Number 7
    		b8= new Button("8"); //Number 8
    		b9= new Button("9"); //Number 9
    		b0= new Button("0"); //Number 0
     
     
     
    		bpi= new Button("Pi");//pi
    		bpower= new Button("Power"); //Power
    		broot= new Button("Root"); //Root
     
     
    		bsin= new Button("Sin"); //sin
    		bcos= new Button("Cos"); //cos
    		btan= new Button("Tan"); //tan
     
     
    		bPoint= new Button("."); //Point
    		bclear= new Button("C"); //clear	
     
    		panelCenter.add(bpi);
    		panelCenter.add(bpower);
    		panelCenter.add(broot);
    		panelCenter.add(bsin);
    		panelCenter.add(bcos);
    		panelCenter.add(btan);
    		panelCenter.add(b1);
    		panelCenter.add(b2);
    		panelCenter.add(b3);
    		panelCenter.add(b4);
    		panelCenter.add(b5);
    		panelCenter.add(b6);
    		panelCenter.add(b7);
    		panelCenter.add(b8);
    		panelCenter.add(b9);
    		panelCenter.add(bpoint);				
    		panelCenter.add(b0);
    		panelCenter.add(bclear);
     
    				//listener
    		bpi.addActionListener(this);
    		bpower.addActionListener(this);
    		broot.addActionListener(this);
    		bsin.addActionListener(this);
    		bcos.addActionListener(this);
    		btan.addActionListener(this);
    		b1.addActionListener(this);
    		b2.addActionListener(this);
    		b3.addActionListener(this);
    		b4.addActionListener(this);
    		b5.addActionListener(this);
    		b6.addActionListener(this);
    		b7.addActionListener(this);
    		b8.addActionListener(this);
    		b9.addActionListener(this);
    		bpoint.addActionListener(this);
    		b0.addActionListener(this);
    		bclear.addActionListener(this);
     
    		panelCenter.repaint();
     
     
    		//Add to Panels, Border Layout
     
    		add(panelNorth, BorderLayout.NORTH);
    		add(panelSouth, BorderLayout.SOUTH);
    		add(panelEast, BorderLayout.EAST);
    		add(panelWest, BorderLayout.WEST);
    		add(panelCenter, BorderLayout.CENTER);
     
     
    		//This Adds a Listener to the Window
    		addWindowListener(this);	}
     
     
    		public void repaint(Graphics g){
     
    			//The Color of this
    			g.setColor(Color.blue);
    		}
     
    		public void actionPerformed(ActionEvent e){
     
    			//input numbers
     
    			if(e.getSource() == b1){ aux1="1"; window=Txwindow.getText()+aux1; Txwindow.setText(value);		}
    			if(e.getSource() == b2){ aux1="2"; window=Txwindow.getText()+aux1; Txwindow.setText(value);		}
    			if(e.getSource() == b3){ aux1="3"; window=Txwindow.getText()+aux1; Txwindow.setText(value);		}
    			if(e.getSource() == b4){ aux1="4"; window=Txwindow.getText()+aux1; Txwindow.setText(value);		}
    			if(e.getSource() == b5){ aux1="5"; window=Txwindow.getText()+aux1; Txwindow.setText(value);		}
    			if(e.getSource() == b6){ aux1="6"; window=Txwindow.getText()+aux1; Txwindow.setText(value);		}
    			if(e.getSource() == b7){ aux1="7"; window=Txwindow.getText()+aux1; Txwindow.setText(value);		}
    			if(e.getSource() == b8){ aux1="8"; window=Txwindow.getText()+aux1; Txwindow.setText(value);		}
    			if(e.getSource() == b9){ aux1="9"; window=Txwindow.getText()+aux1; Txwindow.setText(value);		}
    			if(e.getSource() == b0){ aux1="0"; window=Txwindow.getText()+aux1; Txwindow.setText(value);		}
    			if(e.getSource() == bpoint&& point==false){ aux1="."; value=Txwindow.getText()+aux1; Txwindow.setText(value); point=true;	}
     
    			//The Functions
    			if(e.getSource() == bpi){		Txwindow.setText(""+Math.PI); value="";	}
    			if(e.getSource() == be){		Txwindow.setText(""+Math.E);  value="";	}
     
    			if(e.getSource() == bpower){	
    					aux2=Txwindow.getText();
    				if(!aux2.equals("")){
    					preAns=Double.parseDouble(Txwindow.getText());
    		            lastCommand="power";
    		            Txwindow.setText("");}}
     
    			if(e.getSource() == broot){
     
    				aux2=Txwindow.getText();
    					if(!aux2.equals(""))
    						{n1=Double.parseDouble(Txwindow.getText());
    						Txwindow.setText(""+Math.sqrt(n1));
    						}	}
     
    			if(e.getSource() == bsin){	
     
    				aux2=Txwindow.getText();
    					if(!aux2.equals(""))
    					{n1=Double.parseDouble(Txwindow.getText());
    					Txwindow.setText(""+Math.sin(Math.toRadians(n1)));
    					}}
     
    			if(e.getSource() == bcos){
     
    				aux2=Txwindow.getText();
    					if(!aux2.equals(""))
    					{n1=Double.parseDouble(Txwindow.getText());
    					Txwindow.setText(""+Math.cos(Math.toRadians(n1)));
    					}	}
     
    			if(e.getSource() == btan){
     
    				aux2=Txwindow.getText();
    					if(!aux2.equals(""))
    						{n1=Double.parseDouble(Txwindow.getText());
    						Txwindow.setText(""+Math.tan(Math.toRadians(n1)));
    						}	}
     
    			if(e.getSource() == b10algo){
     
    				aux2=Txwindow.getText();
    					if(!aux2.equals(""))
    						{n1=Double.parseDouble(Txwindow.getText());
    						Txwindow.setText(""+Math.pow(10.0,n1));
    						}	}
     
    			if(e.getSource() == blog){ 				
     
    				aux2=Txwindow.getText();
    					if(!aux2.equals(""))
    						{n1=Double.parseDouble(Txwindow.getText());
    						n1=n1*(-1);
    						Txwindow.setText(""+n1);
    						}	}
     
    			if(e.getSource() == bealgo){
     
    					aux2=Txwindow.getText();
    					if(!aux2.equals(""))
    						{n1=Double.parseDouble(Txwindow.getText());
    						Txwindow.setText(""+Math.pow(Math.E,n1));
    						}	}
     
    			if(e.getSource() == bln){
     
    				aux2=Txwindow.getText();
    					if(!aux2.equals(""))
    						{n1=Double.parseDouble(Txwindow.getText());
    						Txwindow.setText(""+Math.log(n1));
    						}	}
     
    			if(e.getSource() == badd){	
    					aux2=Txwindow.getText();
    				if(!aux2.equals("")){
    					preRes=Double.parseDouble(Txwindow.getText());
    		            lastCommand="+";
    		            Txwindow.setText("");}	
     
    			if(e.getSource() == broot){ 
    					aux2=Txwindow.getText();
    				if(!aux2.equals("")){
    					preRes=Double.parseDouble(Txwindow.getText());
    		            lastCommand="-";
    		            Txwindow.setText("");}
    				}
     
    			if(e.getSource() == bmulti){ 
    					aux2=Txwindow.getText();
    				if(!aux2.equals("")){
    					preRes=Double.parseDouble(Txwindow.getText());
    		            lastCommand="*";
    		            Txwindow.setText("");}}
     
    			if(e.getSource() == bdivi){	
    					aux2=Txwindow.getText();
    				if(!aux2.equals("")){
    					preRes=Double.parseDouble(Txwindow.getText());
    		            lastCommand="/";
    		            Txwindow.setText("");}}
     
    			if(e.getSource() == bclear){ Txwindow.setText("");	}
     
    			if(e.getSource() == bequal){
              Double secVal=Double.parseDouble(Txwindow.getText());
     
               if(lastCommand.equals("+"))
            	   ans=preAns+secVal;
               else if(lastCommand.equals("-"))
                    ans=preAns-secVal;
               else if(lastCommand.equals("*"))
                    ans=preAns*secVal;   
               else if (lastCommand.equals("/"))
       				ans=preAns/secVal; 
       			else if (lastCommand.equals("power"));
       				ans=Math.pow(preAns,secVal);
     
               	   Txwindow.setText(" "+ans);
            	   lastCommand="=";
     
    					}}
    		public double calcoperations(int op, double aux2){
    			if(op==1)
    			{}
    			if(op==2)
    			{}
    			if(op==3)
    			{}
    			if(op==4)
    			{}
    			if(op==5)
    			{}
    			return ans;	}				
     
    		public void windowClosing(WindowEvent e){
     
    			System.exit(0);
    		}
    		public void windowActivated(WindowEvent e){
    		}
    		public void windowClosed(WindowEvent e){
    		}
    		public void windowDeactivated(WindowEvent e){
    		}
    		public void windowDeiconified(WindowEvent e){
    		}
    		public void windowIconified(WindowEvent e){
    		}				
    		public void windowOpened(WindowEvent e){
    		}		
    }

    Like this? I looked it over, I cannot figure out where I left a bracket out.

  7. #7
    Member vanDarg's Avatar
    Join Date
    Jan 2011
    Location
    Chicago
    Posts
    65
    My Mood
    Mellow
    Thanks
    1
    Thanked 7 Times in 7 Posts

    Default Re: Calculator Using AWT

    Quote Originally Posted by hardikjadhav View Post
    Hi Sorry to tell you, but first start with basics of the java.
    There are lot basic things missed in you code.
    Ditto. If you can't figure out where to place brackets. Cut back to the basics.
    "Everything should be made as simple as possible, but not simpler."
    Asking Questions for Dummies | The Java Tutorials | Java Coding Styling Guide

  8. #8
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Calculator Using AWT

    I cannot figure out where I left a bracket out
    Does your IDE editor have a matching {} finder? Put the cursor on a { or } and have the editor find the matching } or {.

    One problem I see is that a lot of } follow statements.
    Its best if they are on a line of their own and that they line up vertically with the code with the open {.
    Also it helps if you put labels on them describing what block they are closing. For example:
    class AClass {
    ...
    } // end AClass <<<<<<<<<<<<<< NOTE
    Last edited by Norm; May 17th, 2011 at 06:53 AM.

Similar Threads

  1. Calculator
    By Andrew Wilson in forum What's Wrong With My Code?
    Replies: 1
    Last Post: March 2nd, 2011, 08:08 AM
  2. Calculator
    By javapenguin in forum What's Wrong With My Code?
    Replies: 5
    Last Post: December 22nd, 2010, 09:00 AM
  3. [SOLVED] Calculator help
    By Bradshjo in forum What's Wrong With My Code?
    Replies: 2
    Last Post: November 1st, 2010, 04:27 PM
  4. Calculator help.
    By Skinnyskinny in forum Java Theory & Questions
    Replies: 6
    Last Post: August 1st, 2009, 12:34 PM
  5. Problem of implementing mathematic logic in Java applet
    By AnithaBabu1 in forum Java Applets
    Replies: 0
    Last Post: August 15th, 2008, 11:42 PM