Click to See Complete Forum and Search --> : can sum1 make this calculator work. i really need help...


bien09cruz
10-07-2008, 12:14 PM
this is just an interface of the calculator, im using jcreator.


import java.awt.*;
import java.awt.event.*;
public class calculator extends Frame
{
TextField txtOut;
Panel pnlNorth, pnlEast, pnlCenter;
Button btnAdd, btnMinus, btnDivide, btnMulti, btnEqual, btnBack, btnClear;

public calculator ()
{
super ("MY CALCULATOR");
txtOut = new TextField(10);
pnlNorth = new Panel();
pnlEast = new Panel();
pnlCenter = new Panel();
btnAdd = new Button("+");
btnMinus = new Button("-");
btnDivide = new Button("/");
btnMulti = new Button("*");
btnEqual = new Button("=");
btnBack = new Button("Backspace");
btnClear = new Button("Clear");


pnlNorth = new Panel(new FlowLayout(FlowLayout.LEFT));
pnlNorth.add(txtOut);
pnlNorth.add(btnClear);
pnlNorth.add(btnBack);

pnlCenter = new Panel(new GridLayout(4,3));
for (int i=0; i <10; i++)
{
Button btnNum = new Button(""+i);
pnlCenter.add(btnNum);
}


pnlEast = new Panel(new GridLayout(5,1,0,5));
pnlEast.add(btnAdd);
pnlEast.add(btnMinus);
pnlEast.add(btnDivide);
pnlEast.add(btnMulti);
pnlEast.add(btnEqual);

setSize(400,300);
add(pnlNorth, BorderLayout.NORTH);
add(pnlCenter, BorderLayout.CENTER);
add(pnlEast, BorderLayout.EAST);
pack();
show();





}
public static void main (String[]args)
{
new calculator ();
}

FourCourtJester
10-07-2008, 12:20 PM
This looks like java, not javascript ?

bien09cruz
10-07-2008, 12:29 PM
sowe, im just a freshman. how can i move this thread?

bien09cruz
10-07-2008, 12:31 PM
this is just an interface of the calculator, im using jcreator.


import java.awt.*;
import java.awt.event.*;
public class calculator extends Frame
{
TextField txtOut;
Panel pnlNorth, pnlEast, pnlCenter;
Button btnAdd, btnMinus, btnDivide, btnMulti, btnEqual, btnBack, btnClear;

public calculator ()
{
super ("MY CALCULATOR");
txtOut = new TextField(10);
pnlNorth = new Panel();
pnlEast = new Panel();
pnlCenter = new Panel();
btnAdd = new Button("+");
btnMinus = new Button("-");
btnDivide = new Button("/");
btnMulti = new Button("*");
btnEqual = new Button("=");
btnBack = new Button("Backspace");
btnClear = new Button("Clear");


pnlNorth = new Panel(new FlowLayout(FlowLayout.LEFT));
pnlNorth.add(txtOut);
pnlNorth.add(btnClear);
pnlNorth.add(btnBack);

pnlCenter = new Panel(new GridLayout(4,3));
for (int i=0; i <10; i++)
{
Button btnNum = new Button(""+i);
pnlCenter.add(btnNum);
}


pnlEast = new Panel(new GridLayout(5,1,0,5));
pnlEast.add(btnAdd);
pnlEast.add(btnMinus);
pnlEast.add(btnDivide);
pnlEast.add(btnMulti);
pnlEast.add(btnEqual);

setSize(400,300);
add(pnlNorth, BorderLayout.NORTH);
add(pnlCenter, BorderLayout.CENTER);
add(pnlEast, BorderLayout.EAST);
pack();
show();





}
public static void main (String[]args)
{
new calculator ();
}

FourCourtJester
10-07-2008, 01:06 PM
Alrite, basic Java 101 for class files:

You have posted a class file for a calculator. It instantiates its super class in the constructor, and then creates a bunch of panels. After that, it goes through a loop that creates your numbers and puts them in a nice grid.

For some reason, you end the constructor there (the } after pnlCenter.add(btnNum)) . You may wish to encapsulate those into it.

Now, what is it you're asking? How to edit this file? Or how to make functions work?

To edit this file, treat it as you would a normal java file. It is no different than any other java file. The fact that you have a public main method there means we're using an in-house class, which is fine since you're a beginniner.

To edit your custom calculator class, just make sure any methods you create fall within the encapsulating {} brackets (ie - but it before the } above public static void main (String[]args)) . These methods can they do stuff with your calculator.

To play with your calculator, you may wish to assign the 'new calculator()' statement into a variable, and then you can invoke methods assigned to that variable. Things like add, subtract, etc, will be very good to have in your calculator class.

To read up on the basics of java, I HIGHLY RECOMMEND http://www.javabeginner.com/

starheartbeam
10-07-2008, 01:11 PM
For cal help you might want to look at this:

http://www.christiankiefer.de/labs/Labreport_Scribbler_Christian_Kiefer_s0508749.doc

bien09cruz
10-16-2008, 01:40 AM
For cal help you might want to look at this:

http://www.christiankiefer.de/labs/Labreport_Scribbler_Christian_Kiefer_s0508749.doc

ty sir!

starheartbeam
10-16-2008, 08:26 AM
ty sir!


No prob. hope it was of some use!