create your own

Calculator Java Program

67
rate or flag this page

By bangawking000


hi i am Dexter,   i made this program for a case study in my school NEUST, our teacher back then was maam Arvee an she didn't seem to appreciate it because it is just too far from what she wants us to do in programming 2. we did not really learned anything from that school. we are in second year college for Pete's sake but most of the students there still do not have any idea on how programming really works. This program is made only using very basic things you will find in java programming. i hope this could help other newbies on java. 



-------------program starts here---------------

import java.awt.*;

import java.awt.event.*;

import javax.swing.*;

import javax.swing.border.*;


public class Group8and12 extends JFrame {


int X,A,S = 0;

double B,C,D = 0;

String history = " ";

String output  = " ";

String save = " ";

String save1= " ";

String save2 = " ";

String save3 = " ";

String save4 = " ";



//-----------------------------------------------------FONT------------------------------------------------------------


Font font1 = new Font("SansSerif", Font.BOLD, 25);

Font font2 = new Font("SansSerif", Font.BOLD, 16);

Font font3 = new Font("SansSerif", Font.BOLD, 30);



//-----------------------------------------------------BUTTONS & LABEL-----------------------------------------------------


private JButton jbtOpen = new JButton("Click To Open");

private JTextField notes = new JTextField("Write notes here");

private JLabel   jlLabel = new JLabel ("0.00");

private JButton jbtZero = new JButton("0");

private JButton jbtEquals = new JButton("=");

private JButton jbtHistory = new JButton("H");

private JButton jbtOne = new JButton("1");

private JButton jbtTwo = new JButton("2");

private JButton jbtThree = new JButton("3");

private JButton jbtFour = new JButton("4");

private JButton jbtFive = new JButton("5");

private JButton jbtSix = new JButton("6");

private JButton jbtSeven = new JButton("7");

private JButton jbtEight = new JButton("8");

private JButton jbtNine = new JButton("9");

private JButton jbtPlus = new JButton("+");

private JButton jbtMinus = new JButton("-");

private JButton jbtDivide = new JButton("/");

private JButton jbtMulti = new JButton("*");



public Group8and12() {


//-----------------------------------------------------MENU BAR-----------------------------------------------------


JMenuBar jmbMenuBar= new JMenuBar();

JMenu jmFile = new JMenu ("File");

jmFile.setMnemonic ('F');

JMenuItem jmiOpen = new JMenuItem ("Open Saved");

JMenuItem jmiSave = new JMenuItem ("Save");

JMenuItem jmiExit = new JMenuItem ("Exit");

jmiOpen.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_O, ActionEvent.CTRL_MASK));

jmiOpen.getAccessibleContext().setAccessibleDescription("Open a saved History");

jmiSave.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S, ActionEvent.CTRL_MASK));

jmiSave.getAccessibleContext().setAccessibleDescription("Sace current history");

jmiExit.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_X, ActionEvent.CTRL_MASK));

jmiExit.getAccessibleContext().setAccessibleDescription("Sace current history");

jmFile.add(jmiOpen);

jmFile.addSeparator();

jmFile.add(jmiSave);

jmFile.addSeparator();

jmFile.add(jmiExit);

jmbMenuBar.add(jmFile);

JMenu jmTools = new JMenu ("Tools");

jmTools.setMnemonic ('T');

JMenuItem jmiDelete = new JMenuItem ("Delete saved");

JMenuItem jmiMulti = new JMenuItem ("Multiplication Table");

JMenuItem jmiNotes = new JMenuItem ("Write Note");

jmiDelete.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_D, ActionEvent.CTRL_MASK));

jmiDelete.getAccessibleContext().setAccessibleDescription("Delete Saved History");

jmiMulti.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_M, ActionEvent.CTRL_MASK));

jmiMulti.getAccessibleContext().setAccessibleDescription("");

jmiNotes.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_N, ActionEvent.CTRL_MASK));

jmiNotes.getAccessibleContext().setAccessibleDescription("");

jmTools.add(jmiDelete);

jmTools.addSeparator();

jmTools.add(jmiMulti);

jmTools.addSeparator();

jmTools.add(jmiNotes);

jmbMenuBar.add(jmTools);

JMenu jmHelp = new JMenu ("Other");

jmHelp.setMnemonic ('O');

JMenuItem jmiHelp = new JMenuItem ("Help");

JMenuItem jmiAbout = new JMenuItem ("About");

JMenuItem jmiUser = new JMenuItem ("User Info");

jmiHelp.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_H, ActionEvent.CTRL_MASK));

jmiHelp.getAccessibleContext().setAccessibleDescription("");

jmiUser.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_U, ActionEvent.CTRL_MASK));

jmiUser.getAccessibleContext().setAccessibleDescription("");

jmiAbout.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_A, ActionEvent.CTRL_MASK));

jmiAbout.getAccessibleContext().setAccessibleDescription("");

jmHelp.add(jmiHelp);

jmHelp.addSeparator();

jmHelp.add(jmiUser);

jmHelp.addSeparator();

jmHelp.add(jmiAbout);

jmbMenuBar.add(jmHelp);

setJMenuBar (jmbMenuBar);

//-----------------------------------------------------PANEL & BUTTONS-----------------------------------------------------

JPanel p1 = new JPanel();

p1.setLayout(new GridLayout(4, 4,3,3)); 

p1.add(jbtOne);

p1.add(jbtTwo);

p1.add(jbtThree);

p1.add(jbtDivide);

p1.add(jbtFour);

p1.add(jbtFive);

p1.add(jbtSix);

p1.add(jbtMulti);

p1.add(jbtSeven);

p1.add(jbtEight);

p1.add(jbtNine);

p1.add(jbtMinus);

p1.add(jbtZero);

p1.add(jbtHistory);

p1.add(jbtEquals);

p1.add(jbtPlus);

JPanel p2 = new JPanel(new BorderLayout());

p2.add (jlLabel,BorderLayout.NORTH);

p2.add (p1, BorderLayout.CENTER);   

add(p2, BorderLayout.CENTER);


//-----------------------------------------------------BUTTON FUNCTIONS-----------------------------------------------------


jbtOne.addActionListener(new ActionListener() {

public void actionPerformed(ActionEvent e) {

C = C * 10 + 1;

jlLabel.setText(String.valueOf(C));

}

});

jbtTwo.addActionListener(new ActionListener() {

public void actionPerformed(ActionEvent e) { 

C = C * 10 + 2;

jlLabel.setText(String.valueOf(C));

}

});


jbtThree.addActionListener(new ActionListener() {

public void actionPerformed(ActionEvent e) { 

C = C * 10 + 3;

jlLabel.setText(String.valueOf(C));

}

});



jbtFour.addActionListener(new ActionListener() {

public void actionPerformed(ActionEvent e) { 

C = C * 10 + 4;

jlLabel.setText(String.valueOf(C));

}

});


jbtFive.addActionListener(new ActionListener() {

public void actionPerformed(ActionEvent e) { 

C = C * 10 + 5;

jlLabel.setText(String.valueOf(C));

}

});



jbtSix.addActionListener(new ActionListener() {

public void actionPerformed(ActionEvent e) { 

C = C * 10 + 6;

jlLabel.setText(String.valueOf(C));

}

});


jbtSeven.addActionListener(new ActionListener() {

public void actionPerformed(ActionEvent e) { 

C = C * 10 + 7;

jlLabel.setText(String.valueOf(C));

}

});



jbtEight.addActionListener(new ActionListener() {

public void actionPerformed(ActionEvent e) { 

C = C * 10 + 8;

jlLabel.setText(String.valueOf(C));

}

});


jbtNine.addActionListener(new ActionListener() {

public void actionPerformed(ActionEvent e) { 

C = C * 10 + 9;

jlLabel.setText(String.valueOf(C));

}

});


jbtZero.addActionListener(new ActionListener() {

public void actionPerformed(ActionEvent e) { 

C = C * 10;

jlLabel.setText(String.valueOf(C));

}

});

//--------------------------------OPERATIONS-------------------------


jbtPlus.addActionListener(new ActionListener() {

public void actionPerformed(ActionEvent e) {

B = C;

C = 0;

X = 1;

}

});


jbtMinus.addActionListener(new ActionListener() {

public void actionPerformed(ActionEvent e) {

B = C;

C = 0;

X = 2;

}

});

jbtDivide.addActionListener(new ActionListener() {

public void actionPerformed(ActionEvent e) {

B = C;

C = 0;

X = 3;

}

});

jbtMulti.addActionListener(new ActionListener() {

public void actionPerformed(ActionEvent e) {

B = C;

C = 0;

X = 4;

}

});


jbtEquals.addActionListener(new ActionListener() {

public void actionPerformed(ActionEvent e) {


if (A < 10) {

switch (X){


case 1 :  D =  B + C ; break;

case 2 :  D =  B - C ; break;

case 3 :  D =  B / C ; break;

case 4 :  D =  B * C ; break;

default: D =  D + C; 

}

//JOptionPane.showMessageDialog(null, ""  + D   ,"result",     JOptionPane.INFORMATION_MESSAGE);

jlLabel.setText(String.valueOf(D));

history += D + "\n";

C = 0;

D = 0;

B = 0;

A = A + 1;

}

else {

JOptionPane.showMessageDialog(null, "Max history capacity reached, Save History first","Max Reached",JOptionPane.INFORMATION_MESSAGE);

A = 0; 

JOptionPane.showMessageDialog(null, "The current History Will Save" ,"Save?",     JOptionPane.INFORMATION_MESSAGE);

save = save + "\n" + new java.util.Date(e.getWhen())+ "\n" +history;

save4= "" + save3;

save3= "" + save2;

save2= "" + save1;

save1= "" + save;

save  = "" ;

history = " ";

S = S + 1;

}

}

});




jbtHistory.addActionListener(new ActionListener() {

public void actionPerformed(ActionEvent e) { 

JOptionPane.showMessageDialog(null, "History \n" + history  ,"History",JOptionPane.INFORMATION_MESSAGE);

}

});


//-----------------------------------------------------MENU FUNCTIONS-----------------------------------------------------


jmiSave.addActionListener(new ActionListener() {

public void actionPerformed(ActionEvent e) { 


JOptionPane.showMessageDialog(null, "The current History Will Save" ,"Save?",     JOptionPane.INFORMATION_MESSAGE);

save = save + "\n" + new java.util.Date(e.getWhen())+ "\n" +history;

save4= "" + save3;

save3= "" + save2;

save2= "" + save1;

save1= "" + save;

save  = "" ;

history = " ";

S = S + 1;


}

});

jmiOpen.addActionListener(new ActionListener() {

public void actionPerformed(ActionEvent e) { 


JLabel jlOpen = new JLabel("Select Saved Data");

JButton jbtOpen1 = new JButton("Saved 1");

JButton jbtOpen2 = new JButton("Saved 2");

JButton jbtOpen3 = new JButton("Saved 3");

JButton jbtOpen4 = new JButton("Saved 4");


JPanel p1 = new JPanel ();

p1.setLayout(new GridLayout(4, 1)); 

p1.add(jbtOpen1);

p1.add(jbtOpen2);

p1.add(jbtOpen3);

p1.add(jbtOpen4);


JFrame frame = new JFrame("Open");

frame.add(p1,BorderLayout.CENTER);

frame.add(jlOpen,BorderLayout.WEST);

frame.setSize(200,100); 

frame.setLocationRelativeTo(null);

frame.setVisible(true);

jbtOpen1.addActionListener(new ActionListener() {

public void actionPerformed(ActionEvent e) { 


if (S <= 0) {

JOptionPane.showMessageDialog(null, "Saved Data 1 \n" + "all data empty", "Open", JOptionPane.INFORMATION_MESSAGE);

}


else {

JOptionPane.showMessageDialog(null, "Saved Data 1 " + save1, "Open", JOptionPane.INFORMATION_MESSAGE);

}

}

});


jbtOpen2.addActionListener(new ActionListener() {

public void actionPerformed(ActionEvent e) { 


if (S <= 0) {

JOptionPane.showMessageDialog(null, "Saved Data 2 \n" + "all data empty", "Open", JOptionPane.INFORMATION_MESSAGE);

}


else {

JOptionPane.showMessageDialog(null, "Saved Data 2" + save2, "Open", JOptionPane.INFORMATION_MESSAGE);

}

}

});

jbtOpen3.addActionListener(new ActionListener() {

public void actionPerformed(ActionEvent e) { 


if (S <= 0) {

JOptionPane.showMessageDialog(null, "Saved Data 3  \n" + "all data empty", "Open", JOptionPane.INFORMATION_MESSAGE);

}


else {

JOptionPane.showMessageDialog(null, "Saved Data 3" + save3, "Open", JOptionPane.INFORMATION_MESSAGE);

}

}

});

jbtOpen4.addActionListener(new ActionListener() {

public void actionPerformed(ActionEvent e) { 


if (S <= 0) {

JOptionPane.showMessageDialog(null, "Saved Data4 \n" + "all data empty", "Open", JOptionPane.INFORMATION_MESSAGE);

}


else {

JOptionPane.showMessageDialog(null, "Saved Data 4" + save4, "Open", JOptionPane.INFORMATION_MESSAGE);

}

}

});

}

});


jmiHelp.addActionListener(new ActionListener() {

public void actionPerformed(ActionEvent e) { 

JOptionPane.showMessageDialog(null, "To view result history click the H button \n" + "Use Save in File menu to save history \n" + "Use Delete Saved to delete saved data" , "Help", JOptionPane.INFORMATION_MESSAGE);

}

});


jmiMulti.addActionListener(new ActionListener() {

public void actionPerformed(ActionEvent e) { 



String output = "                Multiplication Table\n";

output += "------------------------------------------------\n";

output += "   |  ";

for (int j = 1; j <= 9; j++)

output += " " + j + "  ";

output += "\n";

for (int i = 1; i <= 9; i++) {

output += i + " | ";

for (int j = 1; j <= 9; j++) {

if (i * j < 10)

output += "  " + i * j + " ";

else

output += " " + i * j;

}

output += "\n";

}

JOptionPane.showMessageDialog(null, " " + output , "Multiplication Table", JOptionPane.INFORMATION_MESSAGE);

}

});


jmiAbout.addActionListener(new ActionListener() {

public void actionPerformed(ActionEvent e) { 


JPanel p1 = new JPanel();

p1.setLayout(new GridLayout(3, 1)); 

p1.add(new JLabel ("Simple Calculator By O - 45"));

p1.add(new JLabel ("Group 12"));

p1.add(new JLabel ("BSIT II - 0"));


JFrame frame = new JFrame("About"); 

frame.add(p1,BorderLayout.CENTER);

frame.setSize(200,100); 

frame.setLocationRelativeTo(null);

frame.setVisible(true);

}

});

jmiDelete.addActionListener(new ActionListener() {

public void actionPerformed(ActionEvent e) { 

JOptionPane.showMessageDialog(null, "Saved Data Deleted", "Delete", JOptionPane.INFORMATION_MESSAGE);

save = " ";

save1 = " ";

save2 = " ";

save3 = " ";

save4 = " ";

S = 0;

}

});


jmiNotes.addActionListener(new ActionListener() {

public void actionPerformed(ActionEvent e) {

JFrame frame = new JFrame("Notes"); 

frame.add(notes);

frame.add(new JButton(" Save"), BorderLayout.WEST);

frame.setSize(700,60); 

frame.setLocationRelativeTo(null);

frame.setVisible(true);

}

});


jmiUser.addActionListener(new ActionListener() {

public void actionPerformed(ActionEvent e) { 

JFrame frame = new JFrame();

frame.setTitle("User Info");

frame.setLocationRelativeTo(null); 

frame.setSize(300,200);

     frame.setVisible(true);

JPanel p1 = new JPanel();

p1.setLayout( new GridLayout(4,2,5,5));

p1.add(new JLabel("Firstname"));

p1.add(new JTextField(" "));

p1.add(new JLabel("Lastname"));

p1.add(new JTextField(" "));

p1.add(new JLabel("Age"));

p1.add(new JTextField(" "));

p1.add(new JLabel("Gender"));

p1.add(new JTextField(" "));


frame.add(p1, BorderLayout.CENTER);

JPanel p2 = new JPanel();

p2.setLayout( new GridLayout (4,1,10,10));

p2.add(new JButton("Save"));

p2.add(new JButton("Change"));

p2.add(new JButton("Print"));

p2.add(new JButton("Back"));


frame.add(p2, BorderLayout.EAST);

}

});

jmiExit.addActionListener(new ActionListener() {

public void actionPerformed(ActionEvent e) {

System.exit(0);

}

});


//-----------------------------------------------------FONT-----------------------------------------------------

jbtOne.setFont (font1); 

jbtTwo.setFont (font1);

jbtThree.setFont (font1); 

jbtFour.setFont (font1); 

jbtFive.setFont (font1); 

jbtSix.setFont (font1); 

jbtSeven.setFont (font1); 

jbtEight.setFont (font1); 

jbtNine.setFont (font1);

jbtZero.setFont (font1);

jbtEquals.setFont (font2);

jbtHistory.setFont (font2);

jbtPlus.setFont(font3);

jbtMinus.setFont(font3);

jbtDivide.setFont(font3);

jbtMulti.setFont(font3);

jbtOne.setBackground(Color.cyan);

jbtTwo.setBackground(Color.cyan);

jbtThree.setBackground(Color.cyan);

jbtFour.setBackground(Color.cyan);

jbtFive.setBackground(Color.cyan);

jbtSix.setBackground(Color.cyan);

jbtSeven.setBackground(Color.cyan);

jbtEight.setBackground(Color.cyan);

jbtNine.setBackground(Color.cyan);

jbtEquals.setBackground(Color.cyan);

jbtDivide.setBackground(Color.cyan);

jbtMulti.setBackground(Color.cyan);

jbtMinus.setBackground(Color.cyan);

jbtPlus.setBackground(Color.cyan);

jbtHistory.setBackground(Color.cyan);

jbtZero.setBackground(Color.cyan);

jlLabel.setFont (new Font("SansSerif", Font.BOLD, 40));

notes.setForeground(Color.white);

notes.setBackground(Color.black);

notes.setFont(new Font("SansSerif",Font.BOLD + Font.ITALIC, 12));




}


//-------------------------------------------------------------------------------------------------------------------------


public static void main(String[] args) {

Group8and12 frame = new Group8and12();

frame.setTitle("BSIT II-O");

frame.setLocationRelativeTo(null);

frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

frame.setSize(230, 260);

frame.setVisible(true);


}

}

---------------------------end of program------------------------


Print   —   Rate it:  up  down  flag this hub

Comments

RSS for comments on this Hub

No comments yet.

Submit a Comment

Members and Guests

Sign in or sign up and post using a hubpages account.


optional


  • No HTML is allowed in comments, but URLs will be hyperlinked
  • Comments are not for promoting your hubs or other sites

Documentation

1. INTRODUCTION

       What is the purpose this case study

The purpose of this case study is to be able to use all that we have learned and create a program that can demonstrate a simple purpose utilizing GUI and loops that we have learned. We also researched new commands and methods to be able to complete our program with the resources that we need. Although most of our members do not their own computer and those who have, do not have the right java software to practice or experiment, we still finished the program thanks to God. The purpose of this case study is also to practice and experiment the do’s and don’ts while making a java program and make our selves more familiar with the java programming language. To add more, this case study has given us opportunity to make a complete program unlike what we have done before like scraps and pieces of the whole thing. While doing this program we also discovered new things that we do not know before and make us look at this language deeper and analyze better. We also realized the meaning of things that we do not know what the purpose before like identifiers. Only when we used it that we knew how it happened and say “that’s it!” and then move forward.

What are the commands used in your program and define each command

1. first we declared the variables that we will use

int X,A,S = 0;

double B,C,D = 0;

2.Activated the strings to be used.

String history = " ";

String output  = " ";

String save = " ";

String save1= " ";

String save2 = " ";

3.this command creates the font to be used later, using an identifier for a font saves time rather than typing them individually for many objects like text, labels or buttons

Font font1 = new Font("SansSerif", Font.BOLD, 25);

Font font2 = new Font("SansSerif", Font.BOLD, 16);

Font font3 = new Font("SansSerif", Font.BOLD, 30);

4.this commands create the buttons to be used later in the program. Adding identifiers will make them available for multiple jframe and still maintain their purpose

private JButton jbtOpen = new JButton("Click To Open");

private JTextField notes = new JTextField("Write notes here");

rivate JLabel jlLabel = new JLabel ("0.00");   

5. This command initializes the Menu bar

JMenuBar jmbMenuBar= new JMenuBar();

6. This command creates the menu (jmFile) and gives it a display title.

JMenu jmFile = new JMenu ("File");   

7. This command creates a (alt + F) shortcut key to the Menu (jmFile).

jmFile.setMnemonic ('F');

8.This command creates a submenu Open saved (jmiOpen) inside the File menu (jmFile) and makes the display title for it.

JMenuItem jmiOpen = new JMenuItem ("Open Saved");

9. This command gives a (ctrl + O) shortcut key to the submenu Open (jmiOpen).

jmiOpen.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_O, ActionEvent.CTRL_MASK));

10. This command will add the submenu (jmiOpen) to the menu (jmFile) so that it will show up in the File menu.

jmFile.add(jmiOpen);

11. This command will add the menu File (jmFile) to the Menu Bar (jmbMenuBar).

jmbMenuBar.add(jmFile);

12. This command will add the Menu Bar (jmbMenuBar) so that it will display in the JFrame to be declared later.

setJMenuBar (jmbMenuBar);

13. This command creates the panel for the GUI where the buttons will be placed. And sets a grid layout of 4 columns, 4 rows and  with distance of 3 for each buttons

JPanel p1 = new JPanel();

p1.setLayout(new GridLayout(4, 4,3,3));

14. This commands adds the buttons made earlier like One(jbtOne)  the Panel (p1).

p1.add(jbtOne);

p1.add(jbtTwo);

p1.add(jbtThree);

p1.add(jbtDivide);

15. This command creates another panel(p2), the difference is that this panel uses BorderLayout as layout which uses NORTH, EAST, SOUTH, WEST and CENTER instead of grids.

JPanel p2 = new JPanel(new BorderLayout());

16. This Command adds the label(jlLabel) to the panel(p2) and assign its location as NORTH which is the location above the CENTER.

p2.add (jlLabel,BorderLayout.NORTH);

17. This Command adds the Panel(p1) inside another panel(p2) and assigns its location as CENTER below the Label(jlLabel).

p2.add (p1, BorderLayout.CENTER);  

18. This command adds the Panel(p2) to the Jframe.

add(p2, BorderLayout.CENTER);

19. This Command creates an action for the button(jbtOne) so that the statements inside it will execute when the button is clicked of pressed.

jbtOne.addActionListener(new ActionListener() {

              public void actionPerformed(ActionEvent e) {

                   C = C * 10 + 1;

                   jlLabel.setText(String.valueOf(C));

              }

          });

20. While this command updates the value of the JLabel(jlLabel) so that its value will change to the value of the variable(C) as string if the button is clicked

jlLabel.setText(String.valueOf(C));

21. This command creates an action for the button(jbtEquals) and sets a value of 1 for the integer(X) which will select the operation (D =  B + C) which is the plus operation.

jbtPlus.addActionListener(new ActionListener() {

          public void actionPerformed(ActionEvent e) {   

                   B = C;

                   C = 0;

                   X = 1;

          }

});

22. This command decides which kind of operation from +, -, \, *, will be used and displays the answer in the JLabel(jlLabel).

if (A < 10) {

     switch (X){

          case 1 :  D =  B + C ; break;

          case 2 :  D =  B - C ; break;

          case 3 :  D =  B / C ; break;

          case 4 :  D =  B * C ; break;        

          default: D =  D + C;

     }            

jlLabel.setText(String.valueOf(D));

     history += D + "\n";

     C = 0;

     D = 0;

     B = 0;                      

     A = A + 1;

23. This command will create an action to the submenu(jmiExit) which will close the whole program using the (System.exit(0);) Command.

               jmiExit.addActionListener(new ActionListener() {

              public void actionPerformed(ActionEvent e) {        

                   System.exit(0);

              }

          }); 

24. These command assigns the font(font1) which is pre declared earlier in the program using an identifier to the button(jbtOne).

jbtOne.setFont (font1);

25. This command assigns the color to be used as background color for the button(jbtOne).

jbtOne.setBackground(Color.cyan);

26.  These commands assigns the color, foreground, background and font to be used for the JTextField(notes).

notes.setForeground(Color.white);

notes.setBackground(Color.black);

notes.setFont(new Font("SansSerif",Font.BOLD + Font.ITALIC,12));

27. This command starts the Main method.

public static void main(String[] args) {

28. This command creates the JFrame(frame) and sets its title, location, default close operation and size.

Calculator  frame = new Calculator();

          frame.setTitle("Simple Calculator");

          frame.setLocationRelativeTo(null);

          frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

          frame.setSize(230, 260);

          frame.setVisible(true);

          frame.setBackground(Color.black);

C. Define the identifiers used in the program.

FONT

Font1 : This is the font to be used for the number buttons       1 – 9 for the panel(p1).

Font2 : This font is used for buttons equals(jbtEquals) and history(jbtHistory) and has a little smaller size than the numbers do just to it look balanced because uppercase letters are bigger than numbers in standard.

Font3 : This font will be used for the numerical operations plus, minus, divide and multiply. This font has bigger size so that it will balance in size since the signs are much smaller in standard than the numbers.

BUTTONS

jbtOpen1 to jbtOpen4 : these identifiers are used to identify a button that specifically opens a saved data neither if it is save1, save2, save3, or save4 depending on the selection of the user.

jbtOne: this is used to identify the button one. This identifier is also used to be able to add an action to the same button by using the command

(jmiAbout.addActionListener(new ActionListener() {

jbtTwo: this is used to identify the button two. This identifier is also used to be able to add an action to the same button

jbtThree: this is used to identify the button three. This identifier is also used to be able to add an action to the same button

jbtFour: this is used to identify the button . four identifier is also used to be able to add an action to the same button

jbtFive: this is used to identify the button five. This identifier is also used to be able to add an action to the same button

jbtSix: this is used to identify the button six. This identifier is also used to be able to add an action to the same button

jbtSeven: this is used to identify the button seven. This identifier is also used to be able to add an action to the same button

jbtEight: this is used to identify the button eight. This identifier is also used to be able to add an action to the same button

jbtNine: this is used to identify the button nine. This identifier is also used to be able to add an action to the same button

MENU BAR, MENU & SUBMENUS

jmMenuBar : This identifier is used to identify the menu bar which the submenus will be placed.

jmFile : This identifier is used to identify the menu that will be placed in a menu inside a menu bar

The same goes for

jmTools and jmOther

jmiOpen : This identifier is used to identify the submenu Open that will be placed inside a Menu in a Menu bar. This menu will open the saved data inside 4 save banks.

The same goes for the following identifier.

jmiSave : Its purpose is to save the data showed in the button(jbtHistory).

jmiExit : This used to close the whole program.

jmiDelete : This is used to delete all saved data.

jmiMulti : This is used to show a JOptionPane that will display the multiplication table.

jmiNotes : This submenu will show a JFrame where you may enter and save notes

jmiHelp : This is used to display the “how to use the program” in a JOption.

jmiAbout : This used to display a JFrame showing some information about the program.

Panels

p1: This is always used to identify first panel which is most of the time placed inside another panel. This identifier also is used to place the buttons, labels, and textfields inside the panel.

p2: This is always used to identify the second panel used in the program, usually the container of the first panel(p1). 

working