• (3 Pages)
• 1
• 2
• 3

## Creating a Calculator using JFrame Rate Topic: 6 Votes //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'http://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=321933&amp;s=7f1f8900869e4b1b501ff9ae8cff2895&md5check=' + ipb.vars['secure_hash'], cur_rating: 5, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

### #31 sherons

Reputation: 0
• 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...

### #32 basi1111

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

Posted 05 April 2014 - 09:58 AM

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

### #33 AyazAly

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

Posted 03 May 2014 - 01:36 AM

schutzzz, 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);

@Override
public void actionPerformed(ActionEvent arg0) {
System.exit(0);

}
});
// AFTER SELECTING STANDARD IN VIEW

@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));

j2.setSize(270,400);
j2.setResizable(false);

P1.setLayout(new GridLayout(2,1));

JButton Button1 = new JButton(" 1 ");
Button1.setBackground(Color.black);
JButton Button2 = new JButton(" 2 ");
JButton Button3 = new JButton(" 3 ");
JPanel BP1 = new JPanel();
JButton Button4 = new JButton(" 4 ");
JButton Button5 = new JButton(" 5 ");
JButton Button6 = new JButton(" 6 ");
JPanel BP2 = new JPanel();
JButton Button7 = new JButton(" 7 ");
JButton Button8 = new JButton(" 8 ");
JButton Button9 = new JButton(" 9 ");
JPanel BP3 = new JPanel();
JButton Bplus = new JButton("+");
JButton Bminus = new JButton("-");
JButton Bmult = new JButton("*");
JButton Bdiv = new JButton("/");
JPanel BP4 = new JPanel();
JButton Bperc = new JButton("%");
JButton BDEL = new JButton("DEL");
JButton BCLR = new JButton("Clear");
JPanel BP5 = new JPanel();
JPanel BP6 = new JPanel();
JButton B0 = new JButton("         0        ");
JButton BEQL = new JButton("   =   ");

JButton Mplus = new JButton("M+");
JButton MR = new JButton("MR");
JButton MC = new JButton("MC");
JPanel BMemory = new JPanel();

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);

{
public void actionPerformed(ActionEvent e)
{
input="";
t1.setText(input);
t2.setText("");
}
});

{
public void actionPerformed(ActionEvent e)
{
input+="%";
result=result*100;
t1.setText(input);
t2.setText(""+result);

}
});

{
public void actionPerformed(ActionEvent e)
{
input+="+";
t1.setText("Result Saved in Memory");
Memory=result;
Fselect='+';
}
});

{
public void actionPerformed(ActionEvent e)
{
input+="+";
t1.setText("Memory Recalled");
t2.setText(""+Memory);

Fselect='+';
}
});

{
public void actionPerformed(ActionEvent e)
{
input+="+";
t1.setText("Memory Cleared");
t2.setText(""+Memory);
Memory = 0;
Fselect='+';
}
});

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

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

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

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

{

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

});

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

});

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

});

{

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

});

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

});

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

});

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

});

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

});

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

});

{
public void actionPerformed(ActionEvent e)
{
input+="0";
t2.setText(t2.getText() + 0);
t1.setText(input);
}

});
{
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) );
}
}
});

{
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));

j2.show();
j1.hide();

}
});
// AFTER SELECTING SCIENTIFIC IN VIEW

@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));

JButton Button1 = new JButton("  1 ");
JButton Button2 = new JButton("  2 ");
JButton Button3 = new JButton(" 3  ");
JPanel BP1 = new JPanel();
JButton Button4 = new JButton("  4 ");
JButton Button5 = new JButton("  5 ");
JButton Button6 = new JButton(" 6  ");
JPanel BP2 = new JPanel();
JButton Button7 = new JButton("  7 ");
JButton Button8 = new JButton("  8 ");
JButton Button9 = new JButton(" 9  ");
JPanel BP3 = new JPanel();
JButton Bplus = new JButton("+");
JButton Bminus = new JButton("-");
JButton Bmult = new JButton("*");
JButton Bdiv = new JButton("/");

JPanel BP4 = new JPanel();

JButton BCLR = new JButton("Clear");
JButton BDEL = new JButton("DEL");
JButton BEQL = new JButton("  =  ");

JPanel BP5 = new JPanel();

JPanel BP0 = new JPanel();
JButton B0 = new JButton("       0     ");
JButton B00 = new JButton("    00      ");

JPanel BP9 = new JPanel();
JButton Bfact = new JButton("   !   ");
JButton BSquare = new JButton("  ^2   ");
JButton BCube = new JButton("  ^3  ");

JButton Bsin = new JButton("  Sin");
JButton Bcos = new JButton("Cos  ");
JButton Btan = new JButton(" Tan ");

JPanel BP7 = new JPanel();

JButton Bsinh = new JButton("Sinh");
JButton Bcosh = new JButton("Cosh");
JButton Btanh = new JButton("Tanh");

JPanel BP8 = new JPanel();

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);

{
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);
}

});

{
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);
}

});

{
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);
}

});

{
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);
}

});

{
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);
}

});

{
public void actionPerformed(ActionEvent e)
{
input="";
t2.setText("");
t1.setText(input);
}
});

{
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);

}

});

{
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) );
}
}
});

{
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);
}
});

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

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

}
});

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

}
});

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

}
});

{

public void actionPerformed(ActionEvent e)
{
input+="9";
t2.setText(t2.getText() + 9);
t1.setText(input);

}

});

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

}

});

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

}

});

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

}

});

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

}

});

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

});

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

}

});

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

});

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

});

{
public void actionPerformed(ActionEvent e)
{
input+="0";
t2.setText(t2.getText() + 0);
t1.setText(input);
}

});

{
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));

j3.show();
j1.hide();

}
});

// MAIN WINDOW    DETAILS OF DEVELOPERS

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);

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.

### #34 AyazAly

Reputation: 0
• 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.

### #35 Flukeshot

• A little too OCD

Reputation: 417
• 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

### #36 Yeti303

Reputation: 0
• 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 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.

### #37 mozum

Reputation: 0
• Posts: 5
• Joined: 01-June 14

Posted 16 June 2014 - 10:03 AM

schutzzz, 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

### #38 polLux401

Reputation: 0
• Posts: 16
• 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.

### #39 nlh101

Reputation: 0
• 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

### #40 AlexRa

Reputation: 0
• Posts: 2
• Joined: 23-March 15

Posted 23 March 2015 - 02:20 PM

I need to customize the calculator display so that it will be able to show up to last 10 calculation steps including result and functions ( +, -, /, x, and = ). This display can have vertical scroll as well .

I could not find a solution to keep these steps in a temporary variable to recall them again ...

Could you help me ?

### #41 macosxnerd101

• Games, Graphs, and Auctions

Reputation: 11039
• Posts: 41,325
• Joined: 27-December 08

Posted 23 March 2015 - 03:03 PM

AlexRa- You are welcome to post in the main Java forum. However, please remember to include your good faith efforts so folks can better assist you.

### #42 AlexRa

Reputation: 0
• Posts: 2
• Joined: 23-March 15

Posted 23 March 2015 - 04:55 PM

macosxnerd101, on 23 March 2015 - 03:03 PM, said:

AlexRa- You are welcome to post in the main Java forum. However, please remember to include your good faith efforts so folks can better assist you. />

Thank you for you suggestions. I thought I would receive help sooner if I posted my question regarding the calculator here:-)

to add scroll bar to the display I changed the codes as follow :

for(int i = 0; i < 18; i++) {
button[i] = new JButton();
button[i].setText(buttonString[i]);
button[i].setFont(font);
}

display.setFont(font);
display.setEditable(false);
display.setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT);
display.setPreferredSize(displayDimension);
scroll.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
for(int i = 0; i < 2; i++)

### #43 macosxnerd101

• Games, Graphs, and Auctions

Reputation: 11039
• Posts: 41,325
• Joined: 27-December 08

Posted 23 March 2015 - 05:07 PM

Probably not. Please post help questions in the help forums rather than other folks' tutorials. Also, please use code tags.