• (3 Pages)
  • +
  • 1
  • 2
  • 3

Creating a Calculator using JFrame Rate Topic: ***** 5 Votes

#31 sherons  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 03-April 14

Posted 03 April 2014 - 01:19 PM

Thank you very much for the code.. its a big learning purpose for me...
Was This Post Helpful? 0
  • +
  • -

#32 basi1111  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 02-April 14

Posted 05 April 2014 - 09:58 AM

I want to delete +/- button... what should i do ? please help....

This post has been edited by Skydiver: 06 May 2014 - 06:40 AM
Reason for edit:: Removed unnecessary quote.

Was This Post Helpful? 0
  • +
  • -

#33 AyazAly  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 03-May 14

Posted 03 May 2014 - 01:36 AM

View Postschutzzz, on 15 November 2013 - 05:43 AM, said:

It appears to me from the limited information you gave me you might have an extra bracket } in there.


Please help me , i've made this calculator but it cant solve multiple inputs , Like ( 4+4+4 = 12 , but it just calculates 2 ( 4+4+4 = 8 , 4+4 = 8 , etc ) i need help so that this calc can calculate multiple inputs

//MADE BY AYAZ, 1st JAVA Project
import javax.swing.*;

import java.awt.*;
import java.awt.event.*;


public class GUI_Class {

	static double Input1, Input2, Memory, result;
	static char Fselect;
	static String input="";
	
	public static void main(String[] args){
	
		final JFrame j1 = new JFrame();
		j1.setBackground(Color.WHITE);
		JPanel MP = new JPanel();
		JPanel SMAIN = new JPanel();
		j1.setSize(270,350);
		j1.setLocation(100, 100);

		j1.setTitle("Project-Calculator");
		j1.setResizable(false);
		JMenuBar menu = new JMenuBar();
		JMenu m1 = new JMenu("File");
		JMenuItem i1 = new JMenuItem("Exit"); 
		i1.addActionListener(new ActionListener() {
			
			@Override
			public void actionPerformed(ActionEvent arg0) {
				System.exit(0);
				
			}
		});
// AFTER SELECTING STANDARD IN VIEW
		JMenu m2 = new JMenu("View");
		JMenuItem i2 = new JMenuItem("Standard Calculator");
			i2.addActionListener(new ActionListener() {
				
				@Override
				public void actionPerformed(ActionEvent arg0) {
					
					 JFrame j2 = new JFrame();
					JPanel MP = new JPanel();
					JPanel SMAIN = new JPanel();
					j2.setTitle("Standard-Calculator");
					j2.setLocation(300, 250);
					j2.setSize(270,350);
					j2.setResizable(false);
								
				
								
								
								
							final TextField t1 = new TextField(20);
							final TextField t2 = new TextField(10);
								
							Font f = new Font("Verdena",21,21);
							Font f1 = new Font("Candara",15,15);
								
							t1.setFont(f1);
							t2.setFont(f);
							
							t1.setEditable(false);
							t2.setEditable(false);
							
							
							JPanel P1 = new JPanel();
							P1.setLayout(new GridLayout(2,1));
							P1.add(t1,BorderLayout.NORTH);
							P1.add(t2,BorderLayout.SOUTH);

							j2.add(P1);
							j2.add(MP,BorderLayout.NORTH);
								
							
					j2.setSize(270,400);
					j2.setResizable(false);
					
					
					P1.setLayout(new GridLayout(2,1));
					P1.add(t1,BorderLayout.NORTH);
					P1.add(t2,BorderLayout.SOUTH);
					
					j2.add(P1);
					j2.add(MP,BorderLayout.NORTH);
					
					
					JButton Button1 = new JButton(" 1 "); 
					Button1.setBackground(Color.black);
					JButton Button2 = new JButton(" 2 "); 
					JButton Button3 = new JButton(" 3 "); 
						JPanel BP1 = new JPanel();
						BP1.add(Button1,BorderLayout.EAST);
						BP1.add(Button2,BorderLayout.CENTER);
						BP1.add(Button3,BorderLayout.WEST);
					JButton Button4 = new JButton(" 4 "); 
					JButton Button5 = new JButton(" 5 "); 
					JButton Button6 = new JButton(" 6 "); 
						JPanel BP2 = new JPanel();
						BP2.add(Button4,BorderLayout.EAST);
						BP2.add(Button5,BorderLayout.CENTER);
						BP2.add(Button6,BorderLayout.WEST);
					JButton Button7 = new JButton(" 7 "); 
					JButton Button8 = new JButton(" 8 "); 
					JButton Button9 = new JButton(" 9 "); 
						JPanel BP3 = new JPanel();
						BP3.add(Button7,BorderLayout.EAST);
						BP3.add(Button8,BorderLayout.CENTER);
						BP3.add(Button9,BorderLayout.WEST);
					JButton Bplus = new JButton("+"); 
					JButton Bminus = new JButton("-"); 
					JButton Bmult = new JButton("*"); 
					JButton Bdiv = new JButton("/"); 
						JPanel BP4 = new JPanel();
						BP4.add(Bplus,BorderLayout.EAST);
						BP4.add(Bminus,BorderLayout.CENTER);
						BP4.add(Bmult,BorderLayout.WEST);
						BP4.add(Bdiv,BorderLayout.WEST);
					JButton Bperc = new JButton("%");
					JButton BDEL = new JButton("DEL"); 
					JButton BCLR = new JButton("Clear"); 
						JPanel BP5 = new JPanel();
						BP5.add(Bperc,BorderLayout.EAST);
						BP5.add(BDEL,BorderLayout.CENTER);
						BP5.add(BCLR,BorderLayout.WEST);
					JPanel BP6 = new JPanel(); 
						JButton B0 = new JButton("         0        ");
						JButton BEQL = new JButton("   =   ");
						BP6.add(B0);
						BP6.add(BEQL);

						
						JButton Mplus = new JButton("M+"); 
						JButton MR = new JButton("MR"); 
						JButton MC = new JButton("MC");
							JPanel BMemory = new JPanel();
							BMemory.add(Mplus,BorderLayout.EAST);
							BMemory.add(MR,BorderLayout.CENTER);
							BMemory.add(MC,BorderLayout.WEST);
						

							 BCLR.setBackground(Color.LIGHT_GRAY);
							 BCLR.setForeground(Color.black);
							 Button1.setBackground(Color.LIGHT_GRAY);
							 Button1.setForeground(Color.black);
							 Button2.setBackground(Color.LIGHT_GRAY);
							 Button2.setForeground(Color.black);
							 Button3.setBackground(Color.LIGHT_GRAY);
							 Button3.setForeground(Color.black);
							 Button4.setBackground(Color.LIGHT_GRAY);
							 Button4.setForeground(Color.black);
							 Button5.setBackground(Color.LIGHT_GRAY);
							 Button5.setForeground(Color.black);
							 Button6.setBackground(Color.LIGHT_GRAY);
							 Button6.setForeground(Color.black);
							 Button7.setBackground(Color.LIGHT_GRAY);
							 Button7.setForeground(Color.black);
							 Button8.setBackground(Color.LIGHT_GRAY);
							 Button8.setForeground(Color.black);
							 Button9.setBackground(Color.LIGHT_GRAY);
							 Button9.setForeground(Color.black);
							 B0.setBackground(Color.LIGHT_GRAY);
							 B0.setForeground(Color.black);
							 BDEL.setBackground(Color.LIGHT_GRAY);
							 BDEL.setForeground(Color.black);
							 BEQL.setBackground(Color.LIGHT_GRAY);
							 BEQL.setForeground(Color.black);
							 Bdiv.setBackground(Color.LIGHT_GRAY);
							 Bdiv.setForeground(Color.black);
							 Bplus.setBackground(Color.LIGHT_GRAY);
							 Bplus.setForeground(Color.black);
							 Bminus.setBackground(Color.LIGHT_GRAY);
							 Bminus.setForeground(Color.black);
							 Bmult.setBackground(Color.LIGHT_GRAY);
							 Bmult.setForeground(Color.black);
							 MR.setBackground(Color.GREEN);
							 MR.setForeground(Color.black);
							 MC.setBackground(Color.GREEN);
							 MC.setForeground(Color.BLACK);
							 Mplus.setBackground(Color.GREEN);
							 Mplus.setForeground(Color.BLACK);
							 Bperc.setBackground(Color.LIGHT_GRAY);
							 Bperc.setForeground(Color.black);
					
							 
						 BCLR.addActionListener( new ActionListener()
							{
							public void actionPerformed(ActionEvent e)
							{
							input="";
							t1.setText(input);
							t2.setText("");	
							}
							});
							 
						 Bperc.addActionListener( new ActionListener()
							{
							public void actionPerformed(ActionEvent e)
							{
							input+="%";
							result=result*100;
							t1.setText(input);
							t2.setText(""+result);
							
							}
							});		
							 
						Mplus.addActionListener( new ActionListener()
						{
						public void actionPerformed(ActionEvent e)
						{
						input+="+";
						t1.setText("Result Saved in Memory");
						Memory=result;
						Fselect='+';
						}
						});	
						
						MR.addActionListener( new ActionListener()
						{
						public void actionPerformed(ActionEvent e)
						{
						input+="+";
						t1.setText("Memory Recalled");
						t2.setText(""+Memory);
						
						Fselect='+';
						}
						});	
						
						MC.addActionListener( new ActionListener()
						{
						public void actionPerformed(ActionEvent e)
						{
						input+="+";
						t1.setText("Memory Cleared");
						t2.setText(""+Memory);
						Memory = 0;
						Fselect='+';
						}
						});	
						
					
						Bplus.addActionListener( new ActionListener()
						{
						public void actionPerformed(ActionEvent e)
						{
						input+="+";
						Input1 = Double.parseDouble( t2.getText());
						t2.setText("");
						t1.setText(input);
						Fselect='+';
						}
					});

					Bdiv.addActionListener( new ActionListener()
					{
						public void actionPerformed(ActionEvent e)
						{
							input+="/";
						Input1 = Double.parseDouble( t2.getText());
						t2.setText("");
						t1.setText(input);
						Fselect='/';
						}
					});
					
					Bminus.addActionListener( new ActionListener()
					{
						public void actionPerformed(ActionEvent e)
						{
							input+="-";
						Input1 = Double.parseDouble( t2.getText());
						t2.setText("");
						t1.setText(input);
						Fselect='-';
						}
					});
					
					Bmult.addActionListener( new ActionListener()
					{
						public void actionPerformed(ActionEvent e)
						{
							input+="*";
						Input1 = Double.parseDouble( t2.getText());
						t2.setText("");
						t1.setText(input);
						Fselect='x';
						}
					});
					
					Button9.addActionListener( new ActionListener()
					{
					
						public void actionPerformed(ActionEvent e)
						{
							input+="9";
						t2.setText(t2.getText() + 9);
						t1.setText(input);
						}
					
					});

					Button8.addActionListener( new ActionListener()
					{
						public void actionPerformed(ActionEvent e)
						{
							input+="8";
						t2.setText(t2.getText() + 8);
						t1.setText(input);
						}
					
					});

					Button7.addActionListener( new ActionListener()
					{
						public void actionPerformed(ActionEvent e)
						{
							input+="7";
						t2.setText(t2.getText() + 7);
						t1.setText(input);
						}
				
					});

					Button6.addActionListener( new ActionListener()
					{
						
						public void actionPerformed(ActionEvent e)
						{
							input+="6";
						t2.setText(t2.getText() + 6);
						t1.setText(input);
						}
					
					});

					Button5.addActionListener( new ActionListener()
					{
						public void actionPerformed(ActionEvent e)
						{
							input+="5";
						t2.setText(t2.getText() + 5);
						t1.setText(input);
						}
					
					});

					Button4.addActionListener( new ActionListener()
					{
						public void actionPerformed(ActionEvent e)
						{
							input+="4";
						t2.setText(t2.getText() + 4);
						t1.setText(input);
						}
					
					});

					Button3.addActionListener( new ActionListener()
					{
						public void actionPerformed(ActionEvent e)
						{
							input+="3";
							t2.setText(t2.getText() + 3);
							t1.setText(input);
						}
					
					});

					Button2.addActionListener( new ActionListener()
					{
						public void actionPerformed(ActionEvent e)
						{
							input+="2";
						t2.setText(t2.getText() + 2);
						t1.setText(input);
						}
				
					});

					
					Button1.addActionListener( new ActionListener()
							
					{
						public void actionPerformed(ActionEvent e)
						{
							input+="1";
						t2.setText(t2.getText() + 1);
						t1.setText(input);
						}
					
					});

					B0.addActionListener( new ActionListener()
					{
						public void actionPerformed(ActionEvent e)
						{
							input+="0";
						t2.setText(t2.getText() + 0);
						t1.setText(input);
						}
					
					});
					BDEL.addActionListener( new ActionListener()
					{
						public void actionPerformed(ActionEvent e)
						{
						String strng = t2.getText();
						t2.setText("");
						String strn1 = input;
						t1.setText("");
						
						
						for(int j=0 ;j<(strn1.length()-1);j++){
						
							t1.setText(t1.getText()+ strn1.charAt(j));
							}
						input=strn1.substring(0,strn1.length()-1);
						for(int i=0; i<(strng.length()-1); i++ )
						{
						t2.setText(t2.getText() + strng.charAt(i) );
						}
						}
					});
					
					
					
					BEQL.addActionListener( new ActionListener()
					{
						public void actionPerformed(ActionEvent e)
						{
						
							
						Input2= Double.parseDouble( t2.getText());
						
						t2.setText("");

						switch(Fselect)
						{
						case '+':
							
						result=Input1+Input2;
						break;
						
						case '-':
							
						result=Input1-Input2;
						break;
						
						case 'x':
							
						result=Input1*Input2;
						break;
						
						case '/':
									
						result=Input1/Input2;
						break;
					
						}

						t2.setText(""+ result);
						}
					});
						
					JPanel BUTTONPanel = new JPanel();
					BUTTONPanel.setLayout(new GridLayout(7,1));
					BUTTONPanel.add(BMemory);
					BUTTONPanel.add(BP1);
					BUTTONPanel.add(BP2);
					BUTTONPanel.add(BP3);
					BUTTONPanel.add(BP6);
					BUTTONPanel.add(BP4);
					BUTTONPanel.add(BP5);
				
					SMAIN.add(P1,BorderLayout.NORTH);
					SMAIN.add(BUTTONPanel,BorderLayout.SOUTH);
					
					j2.add(SMAIN);
					j2.show();
					j1.hide();
					
				}	
			});
// AFTER SELECTING SCIENTIFIC IN VIEW
	JMenuItem i3 = new JMenuItem("Scientific Calculator");
	
		i3.addActionListener(new ActionListener() {
			
			@Override
			public void actionPerformed(ActionEvent arg0) {
				
				JFrame j3 = new JFrame();
				JPanel MP = new JPanel();
				JPanel SMAIN = new JPanel();
				j3.setTitle("Scientific-Calculator");
				j3.setSize(300,460);
				j3.setLocation(350, 250);
				j3.setResizable(false);
				
				final TextField t1 = new TextField(25);
				final TextField t2 = new TextField(15);
				
				Font f = new Font("Verdena",21,21);
				Font f1 = new Font("Candara",15,15);
				
				t1.setFont(f1);
				t2.setFont(f);
				

				JPanel P1 = new JPanel();
				P1.setLayout(new GridLayout(2,1));
				P1.add(t1,BorderLayout.NORTH);
				P1.add(t2,BorderLayout.SOUTH);

				j3.add(P1);
				j3.add(MP,BorderLayout.NORTH);
				
				
				JButton Button1 = new JButton("  1 "); 
				JButton Button2 = new JButton("  2 "); 
				JButton Button3 = new JButton(" 3  "); 
					JPanel BP1 = new JPanel();
					BP1.add(Button1,BorderLayout.EAST);
					BP1.add(Button2,BorderLayout.CENTER);
					BP1.add(Button3,BorderLayout.WEST);
				JButton Button4 = new JButton("  4 "); 
				JButton Button5 = new JButton("  5 "); 
				JButton Button6 = new JButton(" 6  "); 
					JPanel BP2 = new JPanel();
					BP2.add(Button4,BorderLayout.EAST);
					BP2.add(Button5,BorderLayout.CENTER);
					BP2.add(Button6,BorderLayout.WEST);
				JButton Button7 = new JButton("  7 "); 
				JButton Button8 = new JButton("  8 "); 
				JButton Button9 = new JButton(" 9  "); 
					JPanel BP3 = new JPanel();
					BP3.add(Button7,BorderLayout.EAST);
					BP3.add(Button8,BorderLayout.CENTER);
					BP3.add(Button9,BorderLayout.WEST);
				JButton Bplus = new JButton("+"); 
				JButton Bminus = new JButton("-"); 
				JButton Bmult = new JButton("*");
				JButton Bdiv = new JButton("/"); 

					JPanel BP4 = new JPanel();
					BP4.add(Bplus,BorderLayout.EAST);
					BP4.add(Bminus,BorderLayout.CENTER);
					BP4.add(Bmult,BorderLayout.WEST);
					BP4.add(Bdiv,BorderLayout.WEST);
				
				JButton BCLR = new JButton("Clear");
				JButton BDEL = new JButton("DEL"); 
				JButton BEQL = new JButton("  =  ");
				
					JPanel BP5 = new JPanel();
					BP5.add(BCLR,BorderLayout.EAST);
					BP5.add(BEQL,BorderLayout.CENTER);
					BP5.add(BDEL,BorderLayout.WEST);
					
				JPanel BP0 = new JPanel();
					JButton B0 = new JButton("       0     ");
					JButton B00 = new JButton("    00      ");
					BP0.add(B0,BorderLayout.EAST);
					BP0.add(B00,BorderLayout.WEST);
					
					JPanel BP9 = new JPanel();
					JButton Bfact = new JButton("   !   ");
					JButton BSquare = new JButton("  ^2   ");
					JButton BCube = new JButton("  ^3  ");
					BP9.add(Bfact,BorderLayout.EAST);
					BP9.add(BSquare,BorderLayout.CENTER);
					BP9.add(BCube,BorderLayout.WEST);
					
					JButton Bsin = new JButton("  Sin"); 
					JButton Bcos = new JButton("Cos  "); 
					JButton Btan = new JButton(" Tan ");
					
						JPanel BP7 = new JPanel();
						BP7.add(Bsin,BorderLayout.EAST);
						BP7.add(Bcos,BorderLayout.CENTER);
						BP7.add(Btan,BorderLayout.WEST);
						

						

					JButton Bsinh = new JButton("Sinh"); 
					JButton Bcosh = new JButton("Cosh"); 
					JButton Btanh = new JButton("Tanh");
					
						JPanel BP8 = new JPanel();
						BP8.add(Bsinh,BorderLayout.EAST);
						BP8.add(Bcosh,BorderLayout.CENTER);
						BP8.add(Btanh,BorderLayout.WEST);
						

						 Button1.setBackground(Color.BLACK);
						 Button1.setForeground(Color.WHITE);
						 Button2.setBackground(Color.BLACK);
						 Button2.setForeground(Color.WHITE);
						 Button3.setBackground(Color.BLACK);
						 Button3.setForeground(Color.WHITE);
						 Button4.setBackground(Color.BLACK);
						 Button4.setForeground(Color.WHITE);
						 Button5.setBackground(Color.BLACK);
						 Button5.setForeground(Color.WHITE);
						 Button6.setBackground(Color.BLACK);
						 Button6.setForeground(Color.WHITE);
						 Button7.setBackground(Color.BLACK);
						 Button7.setForeground(Color.WHITE);
						 Button8.setBackground(Color.BLACK);
						 Button8.setForeground(Color.WHITE);
						 Button9.setBackground(Color.BLACK);
						 Button9.setForeground(Color.WHITE);
						 BCLR.setBackground(Color.BLACK);
						 BCLR.setForeground(Color.WHITE);
						 B0.setBackground(Color.BLACK);
						 B0.setForeground(Color.WHITE);
						 B00.setBackground(Color.BLACK);
						 B00.setForeground(Color.WHITE);
						 Bplus.setBackground(Color.BLACK);
						 Bplus.setForeground(Color.WHITE);
						 Bdiv.setBackground(Color.BLACK);
						 Bdiv.setForeground(Color.WHITE);
						 Bminus.setBackground(Color.BLACK);
						 Bminus.setForeground(Color.WHITE);
						 Bmult.setBackground(Color.BLACK);
						 Bmult.setForeground(Color.WHITE);
						 Bfact.setBackground(Color.gray);
						 Bfact.setForeground(Color.black);
						 BEQL.setBackground(Color.BLACK);
						 BEQL.setForeground(Color.WHITE);
						 BDEL.setBackground(Color.BLACK);
						 BDEL.setForeground(Color.WHITE);
						 BSquare.setBackground(Color.gray);
						 BSquare.setForeground(Color.black);
						 BCube.setBackground(Color.gray);
						 BCube.setForeground(Color.black);
						 Bsin.setBackground(Color.gray);
						 Bsin.setForeground(Color.black);
						 Bcos.setBackground(Color.gray);
						 Bcos.setForeground(Color.black);
						 Btan.setBackground(Color.gray);
						 Btan.setForeground(Color.black);
						 Bsinh.setBackground(Color.gray);
						 Bsinh.setForeground(Color.black);
						 Bcosh.setBackground(Color.gray);
						 Bcosh.setForeground(Color.black);
						 Btanh.setBackground(Color.gray);
						 Btanh.setForeground(Color.black);
						 
						 
					BSquare.addActionListener( new ActionListener()
					{
						public void actionPerformed(ActionEvent e)
						{
						input+="^2";
						double n = Double.parseDouble(t2.getText());
			            double a = Math.pow(n, 2);
			            t2.setText(String.valueOf(a));
			            t1.setText(input);
			        }
			        
						
					});
					
					BCube.addActionListener( new ActionListener()
					{
						public void actionPerformed(ActionEvent e)
						{
						input+="^3";
						double Input1 = Double.parseDouble(t2.getText());
			            double a1 = Math.pow(Input1, 3);
			            t2.setText(String.valueOf(a1));
			            t1.setText(input);
			        }
	
					});
					
				
					
					Bsin.addActionListener( new ActionListener()
					{
						public void actionPerformed(ActionEvent e)
						{
							input+="Sin(";
						double Input2 = Double.parseDouble(t2.getText());
			            double a2 = Math.sin(Input2*Math.PI/180);
			            t2.setText(String.valueOf(a2));
			            t1.setText(input);
			            }
			        
						
					});
					
					Bcos.addActionListener( new ActionListener()
					{
						public void actionPerformed(ActionEvent e)
						{
							input+="Cos(";
						double n3 = Double.parseDouble(t2.getText());
			            double a3 = Math.cos(n3*Math.PI/180);
			            t2.setText(String.valueOf(a3));
			            t1.setText(input);
			            }
			        
						
					});
					
					Btan.addActionListener( new ActionListener()
					{
						public void actionPerformed(ActionEvent e)
						{
						input+="Tan(";
						double n4 = Double.parseDouble(t2.getText());
			            double a4 = Math.tan(n4*Math.PI/180);
			            t2.setText(String.valueOf(a4));
			            t1.setText(input);
			            }
			        
					});
					
					BCLR.addActionListener( new ActionListener()
					{
					public void actionPerformed(ActionEvent e)
					{
					input="";
					t2.setText("");
					t1.setText(input);
					}
				});

					
					
					Bfact.addActionListener( new ActionListener()
					{
						public void actionPerformed(ActionEvent e)
						{
							input+="!";
					    double n5 = Integer.parseInt(t2.getText());
					    double fact = 1;
			            for(double i = 1;i<=n5;i++){
			                fact = fact * i;
			            }
			            t2.setText(String.valueOf(fact));
						t1.setText(input);
						
			        }
						
					});
					
					BDEL.addActionListener( new ActionListener()
					{
						public void actionPerformed(ActionEvent e)
						{
						String strng = t2.getText();
						t2.setText("");
						String strn1 = input;
						t1.setText("");
						
						
						for(int j=0 ;j<(strn1.length()-1);j++){
						
							t1.setText(t1.getText()+ strn1.charAt(j));
							}
						input=strn1.substring(0,strn1.length()-1);
						for(int i=0; i<(strng.length()-1); i++ )
						{
						t2.setText(t2.getText() + strng.charAt(i) );
						}
						}
					});
					
					
					BEQL.addActionListener( new ActionListener()
					{
						public void actionPerformed(ActionEvent e)
						{
						double result=0;
							
						Input2= Double.parseDouble( t2.getText());
						
						t2.setText("");

						switch(Fselect)
						{
						case '+':
							
						result=Input1+Input2;
						break;
						
						case '-':
							
						result=Input1-Input2;
						break;
						
						case 'x':
							
						result=Input1*Input2;
						break;
						
						case '/':
									
						result=Input1/Input2;
						break;

						}

						t2.setText(""+ result);
						}
					});
					

					
					Bplus.addActionListener( new ActionListener()
						{
						public void actionPerformed(ActionEvent e)
						{
						input+="+";
						Input1 = Double.parseDouble( t2.getText());
						t2.setText("");
						Fselect='+';
						t1.setText(input);
						}
					});

					Bdiv.addActionListener( new ActionListener()
					{
						public void actionPerformed(ActionEvent e)
						{
						input+="+";
						Input1 = Double.parseDouble( t2.getText());
						t2.setText("");
						Fselect='/';
						t1.setText(input);

						}
					});
					
					Bminus.addActionListener( new ActionListener()
					{
						public void actionPerformed(ActionEvent e)
						{
							input+="-";
						Input1 = Double.parseDouble( t2.getText());
						t2.setText("");
						Fselect='-';
						t1.setText(input);

						}
					});
					
					Bmult.addActionListener( new ActionListener()
					{
						public void actionPerformed(ActionEvent e)
						{
							input+="*";
						Input1 = Double.parseDouble( t2.getText());
						t2.setText("");
						Fselect='x';
						t1.setText(input);

						}
					});
					
					Button9.addActionListener( new ActionListener()
					{
					
						public void actionPerformed(ActionEvent e)
						{
							input+="9";
						t2.setText(t2.getText() + 9);
						t1.setText(input);

						}
					
					});

					Button8.addActionListener( new ActionListener()
					{
						public void actionPerformed(ActionEvent e)
						{
							input+="8";
						t2.setText(t2.getText() + 8);
						t1.setText(input);

						}
					
					});

					Button7.addActionListener( new ActionListener()
					{
						public void actionPerformed(ActionEvent e)
						{
						input+="7";
						t2.setText(t2.getText() + 7);
						t1.setText(input);

						}
				
					});

					Button6.addActionListener( new ActionListener()
					{
						public void actionPerformed(ActionEvent e)
						{
						input+="6";
						t2.setText(t2.getText() + 6);
						t1.setText(input);

						}
					
					});

					Button5.addActionListener( new ActionListener()
					{
						public void actionPerformed(ActionEvent e)
						{
							input+="5";
						t2.setText(t2.getText() + 5);
						t1.setText(input);

						}
					
					});

					Button4.addActionListener( new ActionListener()
					{
						public void actionPerformed(ActionEvent e)
						{
							input+="4";
						t2.setText(t2.getText() + 4);
						t1.setText(input);
						}
				
					});

					Button3.addActionListener( new ActionListener()
					{
						public void actionPerformed(ActionEvent e)
						{
							input+="3";
							t2.setText(t2.getText() + 3);
							t1.setText(input);

						}
					
					});

					Button2.addActionListener( new ActionListener()
					{
						public void actionPerformed(ActionEvent e)
						{
							input+="2";
						t2.setText(t2.getText() + 2);
						t1.setText(input);
						}
				
					});

					
					Button1.addActionListener( new ActionListener()
							
					{
						public void actionPerformed(ActionEvent e)
						{
							input+="1";
						t2.setText(t2.getText() + 1);
						t1.setText(input);
}
					
					});

					B0.addActionListener( new ActionListener()
					{
						public void actionPerformed(ActionEvent e)
						{
							input+="0";
						t2.setText(t2.getText() + 0);
						t1.setText(input);
						}
					
					});
					
					B00.addActionListener( new ActionListener()
					{
						public void actionPerformed(ActionEvent e)
						{
							input+="00";
						t2.setText(t2.getText() + 0);
						t2.setText(t2.getText() + 0);
						t1.setText(input);
						}
					
					});
					
					
				JPanel BUTTONPanel = new JPanel();
				BUTTONPanel.setLayout(new GridLayout(10,1));
				
				
				BUTTONPanel.add(BP1);
				BUTTONPanel.add(BP2);
				BUTTONPanel.add(BP3);
				BUTTONPanel.add(BP0);
				BUTTONPanel.add(BP4);
				BUTTONPanel.add(BP5);
				BUTTONPanel.add(BP9);
				BUTTONPanel.add(BP7);
				BUTTONPanel.add(BP8);
				
				
				SMAIN.add(P1,BorderLayout.NORTH);
				SMAIN.add(BUTTONPanel,BorderLayout.SOUTH);
				
				j3.add(SMAIN);
				j3.show();
				j1.hide();
				
			}
		});

	// MAIN WINDOW    DETAILS OF DEVELOPERS	
		m1.add(i1);
		m2.add(i2);
		m2.add(i3);
		
		JPanel P1 = new JPanel();
		P1.setLayout(new GridLayout(8,1));
		TextField mainTxt = new TextField("        Group Members  ",20);
		TextField mainTxt1 = new TextField("A y a z  K a r i m",20);
		TextField mainTxt2 = new TextField("A w a i s  K h a n",20);
		TextField mainTxt3 = new TextField("A s a d  R a u f",20);
		mainTxt.setEditable(false);
		mainTxt1.setEditable(false);
		mainTxt2.setEditable(false);
		mainTxt3.setEditable(false);
		Font f = new Font("New Times Roman",21,21);
		Font f1 = new Font("Candara",15,15);
		mainTxt.setFont(f);
		mainTxt.setForeground(Color.WHITE);
		mainTxt.setBackground(Color.RED);
		mainTxt1.setFont(f1);
		mainTxt2.setFont(f1);
		mainTxt3.setFont(f1);
		
		TextField mainTxt4 = new TextField("    Developed by ^AAA^",20);
		mainTxt4.setEditable(false);
		mainTxt4.setFont(f);
		mainTxt4.setForeground(Color.WHITE);
		mainTxt4.setBackground(Color.BLACK);
		P1.add(mainTxt,BorderLayout.NORTH);
		P1.add(mainTxt1,BorderLayout.NORTH);
		P1.add(mainTxt2,BorderLayout.NORTH);
		P1.add(mainTxt3,BorderLayout.NORTH);

		j1.add(mainTxt4,BorderLayout.SOUTH);
		
		
		MP.add(menu,BorderLayout.EAST);
		menu.add(m1,BorderLayout.EAST);
		menu.add(m2,BorderLayout.EAST);
		
		j1.add(P1);
		j1.add(MP,BorderLayout.NORTH);
		
		SMAIN.add(P1,BorderLayout.NORTH);

		
		j1.add(SMAIN);
		j1.show();
		
		
	
		

	}

}


This post has been edited by Skydiver: 06 May 2014 - 06:39 AM
Reason for edit:: Put code in code tags. Learn to do this yourself.

Was This Post Helpful? 0
  • +
  • -

#34 AyazAly  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 03-May 14

Posted 04 May 2014 - 01:34 AM

Can you give me an easy code. Calculator code. which can calculate more than 2 inputs.
like 5+5+5+5+5+5 = ....
i saw many ppl have made different calculators but they are same in working as my calculator which calculates like this

4+4 = 8 .
4+4+4 = 8.

it only calculates 2 inputs.

i am waiting for your reply. with the solution :) thanks
Was This Post Helpful? 0
  • +
  • -

#35 Flukeshot  Icon User is offline

  • A little too OCD
  • member icon

Reputation: 415
  • View blog
  • Posts: 1,030
  • Joined: 14-November 12

Posted 06 May 2014 - 03:13 AM

If you study the functionality of the default windows calculator program, you'll notice that if you make multiple inputs it will calculate the current problem and use that as the "first input" of the new problem. To achieve this, all you have to do is insert a logic clause somewhere that causes the +-/* keys to have a multiple functionality. That is..

1. IF (there is already 2 inputs) act like an = key first
2. act like a +-/* key
Was This Post Helpful? 0
  • +
  • -

#36 Yeti303  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 23-May 14

Posted 23 May 2014 - 06:34 AM

First, I would like to thank you for this tutorial, it's very informative and straightforward.
From a QA point of view, I would like to draw your attention to the following scenario:

When you already have a number on the display with a "." in it, for example "18.0" , and you press the "." button, it keeps adding it to the string and things gets messed up, after further operations, the calculator throws the following exception:

Exception in thread "AWT-EventQueue-0" java.lang.NumberFormatException: multiple points
at sun.misc.FloatingDecimal.readJavaFormatString(FloatingDecimal.java:1101)
at java.lang.Double.parseDouble(Double.java:540)
at Calculator.getResult(Calculator.java:126)
at Calculator.actionPerformed(Calculator.java:222)
...

To mitigate this, I added the following condition to the "." button action, so it won't do anything if there is a "." already in the number on the display.

if(ae.getSource() == button[12] && !display.getText().contains("."))
                display.append(".");


I hope this helps, and please let me know if you have a better solution to this.
Was This Post Helpful? 0
  • +
  • -

#37 mozum  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 01-June 14

Posted 16 June 2014 - 10:03 AM

View Postschutzzz, on 07 July 2013 - 08:59 PM, said:

No problem! :)/> let me know if you need any further explination on anything.
Hello sir. your create calculator code was very interested. infact the for loop were manupulated was very fascinating. But I dont think I have proper understanding of what the double temporary field does in the get result method. I think it is to hold the display input momentarily. I want to know how it does this especially as it concern negative input.

Mozum
Was This Post Helpful? 0
  • +
  • -

#38 polLux401  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 8
  • Joined: 19-May 14

Posted 31 July 2014 - 07:09 AM

Thanks for posting a tutorial for this calculator. I need something small to work on the side while I'm taking class. This should be a good contender.
Was This Post Helpful? 0
  • +
  • -

#39 nlh101  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 03-August 14

Posted 03 August 2014 - 05:39 AM

Is there a way to change the color of the borders and backgrounds to #0099CC? I have already tried, but NetBeans keeps failing the builds. Is it possible, or am I just dreaming in code?

References:
http://www.coderanch...ackground-color
Was This Post Helpful? 0
  • +
  • -

  • (3 Pages)
  • +
  • 1
  • 2
  • 3