More Related Content Similar to New text document Similar to New text document (20) New text document1. package scientific_calculater;
import javax.swing.JOptionPane;
/**
*
* @author Younis
*/
public class Calculater extends javax.swing.JFrame {
private double total1=0.0;
private double total2=0.0;
private double total3=1.0,d;
int sum;
private char math_operater;
/**
* Creates new form Calculater
*/
public Calculater() {
initComponents();
}
private void getOperater(String Btntext)
{
math_operater=Btntext.charAt(0);
total1=total1+Double.parseDouble(calculateroutput.getText());
calculateroutput.setText("");
}
/**
* This method is called from within the constructor to initialize the form.
* WARNING: Do NOT modify this code. The content of this method is always
* regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {
jSlider1 = new javax.swing.JSlider();
jPanel1 = new javax.swing.JPanel();
RemainderBtn = new javax.swing.JButton();
MultiplyBtn = new javax.swing.JButton();
ClearBtn = new javax.swing.JButton();
PowerBtn = new javax.swing.JButton();
MinusBtn = new javax.swing.JButton();
Btn9 = new javax.swing.JButton();
DivideBtn = new javax.swing.JButton();
Btn6 = new javax.swing.JButton();
Btn7 = new javax.swing.JButton();
Btn8 = new javax.swing.JButton();
Btn4 = new javax.swing.JButton();
Btn5 = new javax.swing.JButton();
Btn2 = new javax.swing.JButton();
EqualityBtn = new javax.swing.JButton();
Btn0 = new javax.swing.JButton();
ORBtn = new javax.swing.JButton();
ANDBtn = new javax.swing.JButton();
NORBtn = new javax.swing.JButton();
NANDBtn = new javax.swing.JButton();
pointBtn = new javax.swing.JButton();
SquarerootBtn = new javax.swing.JButton();
SignBtn = new javax.swing.JButton();
jScrollPane1 = new javax.swing.JScrollPane();
calculateroutput = new javax.swing.JTextPane();
PlusBtn = new javax.swing.JButton();
Btn3 = new javax.swing.JButton();
Btn1 = new javax.swing.JButton();
2. setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
jPanel1.setBackground(new java.awt.Color(102, 102, 102));
jPanel1.setBorder(new javax.swing.border.MatteBorder(null));
jPanel1.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
RemainderBtn.setText("%");
RemainderBtn.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
RemainderBtnActionPerformed(evt);
}
});
MultiplyBtn.setText("*");
MultiplyBtn.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
MultiplyBtnActionPerformed(evt);
}
});
ClearBtn.setText("C");
ClearBtn.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
ClearBtnActionPerformed(evt);
}
});
PowerBtn.setText("^");
PowerBtn.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
PowerBtnActionPerformed(evt);
}
});
MinusBtn.setText("-");
MinusBtn.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
MinusBtnActionPerformed(evt);
}
});
Btn9.setText("9");
Btn9.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
Btn9ActionPerformed(evt);
}
});
DivideBtn.setText("/");
DivideBtn.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
DivideBtnActionPerformed(evt);
}
});
Btn6.setText("6");
Btn6.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
Btn6ActionPerformed(evt);
}
});
Btn7.setText("7");
3. Btn7.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
Btn7ActionPerformed(evt);
}
});
Btn8.setText("8");
Btn8.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
Btn8ActionPerformed(evt);
}
});
Btn4.setText("4");
Btn4.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
Btn4ActionPerformed(evt);
}
});
Btn5.setText("5");
Btn5.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
Btn5ActionPerformed(evt);
}
});
Btn2.setText("2");
Btn2.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
Btn2ActionPerformed(evt);
}
});
EqualityBtn.setText("=");
EqualityBtn.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
EqualityBtnActionPerformed(evt);
}
});
Btn0.setText("0");
Btn0.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
Btn0ActionPerformed(evt);
}
});
ORBtn.setText("|");
ORBtn.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
ORBtnActionPerformed(evt);
}
});
ANDBtn.setText("&");
ANDBtn.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
ANDBtnActionPerformed(evt);
}
});
NORBtn.setText("NOR");
NORBtn.addActionListener(new java.awt.event.ActionListener() {
4. public void actionPerformed(java.awt.event.ActionEvent evt) {
NORBtnActionPerformed(evt);
}
});
NANDBtn.setText("NAND");
NANDBtn.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
NANDBtnActionPerformed(evt);
}
});
pointBtn.setText(".");
pointBtn.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
pointBtnActionPerformed(evt);
}
});
SquarerootBtn.setLabel("Square root");
SquarerootBtn.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
SquarerootBtnActionPerformed(evt);
}
});
SignBtn.setText("-+");
SignBtn.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
SignBtnActionPerformed(evt);
}
});
calculateroutput.setEditable(false);
calculateroutput.addKeyListener(new java.awt.event.KeyAdapter() {
public void keyPressed(java.awt.event.KeyEvent evt) {
calculateroutputKeyPressed(evt);
}
});
jScrollPane1.setViewportView(calculateroutput);
PlusBtn.setText("+");
PlusBtn.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
PlusBtnActionPerformed(evt);
}
});
Btn3.setText("3");
Btn3.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
Btn3ActionPerformed(evt);
}
});
Btn1.setText("1");
Btn1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
Btn1ActionPerformed(evt);
}
});
javax.swing.GroupLayout jPanel1Layout = new
javax.swing.GroupLayout(jPanel1);
5. jPanel1.setLayout(jPanel1Layout);
jPanel1Layout.setHorizontalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addGap(22, 22, 22)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LE
ADING, false)
.addComponent(jScrollPane1)
.addGroup(jPanel1Layout.createSequentialGroup()
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LE
ADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addComponent(Btn8,
javax.swing.GroupLayout.PREFERRED_SIZE, 50,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(Btn9,
javax.swing.GroupLayout.PREFERRED_SIZE, 50,
javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(jPanel1Layout.createSequentialGroup()
.addComponent(Btn6,
javax.swing.GroupLayout.PREFERRED_SIZE, 50,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(Btn7,
javax.swing.GroupLayout.PREFERRED_SIZE, 50,
javax.swing.GroupLayout.PREFERRED_SIZE)))
.addGap(6, 6, 6)
.addComponent(PowerBtn,
javax.swing.GroupLayout.PREFERRED_SIZE, 50,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(PlusBtn,
javax.swing.GroupLayout.PREFERRED_SIZE, 60,
javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(jPanel1Layout.createSequentialGroup()
.addComponent(ClearBtn,
javax.swing.GroupLayout.PREFERRED_SIZE, 50,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(RemainderBtn,
javax.swing.GroupLayout.PREFERRED_SIZE, 50,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(SignBtn,
javax.swing.GroupLayout.PREFERRED_SIZE, 50,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(MinusBtn,
javax.swing.GroupLayout.PREFERRED_SIZE, 60,
javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(jPanel1Layout.createSequentialGroup()
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LE
ADING)
6. .addComponent(Btn4,
javax.swing.GroupLayout.PREFERRED_SIZE, 50,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(Btn2,
javax.swing.GroupLayout.PREFERRED_SIZE, 50,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(Btn0,
javax.swing.GroupLayout.PREFERRED_SIZE, 50,
javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(6, 6, 6)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LE
ADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addComponent(Btn1,
javax.swing.GroupLayout.PREFERRED_SIZE, 50,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(NANDBtn,
javax.swing.GroupLayout.PREFERRED_SIZE, 120,
javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TR
AILING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addComponent(MultiplyBtn,
javax.swing.GroupLayout.PREFERRED_SIZE, 50,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(DivideBtn,
javax.swing.GroupLayout.PREFERRED_SIZE, 60,
javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LE
ADING, false)
.addGroup(jPanel1Layout.createSequentialGroup()
.addComponent(Btn3,
javax.swing.GroupLayout.PREFERRED_SIZE, 50,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(pointBtn,
javax.swing.GroupLayout.PREFERRED_SIZE, 50,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED,
javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(NORBtn,
javax.swing.GroupLayout.PREFERRED_SIZE, 60,
javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING,
jPanel1Layout.createSequentialGroup()
.addComponent(Btn5,
javax.swing.GroupLayout.PREFERRED_SIZE, 50,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(ANDBtn,
javax.swing.GroupLayout.PREFERRED_SIZE, 50,
javax.swing.GroupLayout.PREFERRED_SIZE)
7. .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(ORBtn,
javax.swing.GroupLayout.PREFERRED_SIZE, 60,
javax.swing.GroupLayout.PREFERRED_SIZE))))))
.addGroup(jPanel1Layout.createSequentialGroup()
.addComponent(EqualityBtn,
javax.swing.GroupLayout.PREFERRED_SIZE, 105,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED,
javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(SquarerootBtn,
javax.swing.GroupLayout.PREFERRED_SIZE, 118,
javax.swing.GroupLayout.PREFERRED_SIZE)))
.addContainerGap(20, Short.MAX_VALUE))
);
jPanel1Layout.setVerticalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addGap(68, 68, 68)
.addComponent(jScrollPane1,
javax.swing.GroupLayout.PREFERRED_SIZE, 49,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BA
SELINE)
.addComponent(ClearBtn,
javax.swing.GroupLayout.PREFERRED_SIZE, 30,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(RemainderBtn,
javax.swing.GroupLayout.PREFERRED_SIZE, 30,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(SignBtn,
javax.swing.GroupLayout.PREFERRED_SIZE, 30,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(MinusBtn,
javax.swing.GroupLayout.PREFERRED_SIZE, 30,
javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BA
SELINE)
.addComponent(Btn8, javax.swing.GroupLayout.PREFERRED_SIZE,
30, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(Btn9, javax.swing.GroupLayout.PREFERRED_SIZE,
30, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(PowerBtn,
javax.swing.GroupLayout.PREFERRED_SIZE, 30,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(PlusBtn,
javax.swing.GroupLayout.PREFERRED_SIZE, 30,
javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LE
ADING)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BA
8. SELINE)
.addComponent(Btn7,
javax.swing.GroupLayout.PREFERRED_SIZE, 30,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(DivideBtn,
javax.swing.GroupLayout.PREFERRED_SIZE, 30,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(MultiplyBtn,
javax.swing.GroupLayout.PREFERRED_SIZE, 30,
javax.swing.GroupLayout.PREFERRED_SIZE))
.addComponent(Btn6, javax.swing.GroupLayout.PREFERRED_SIZE,
30, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BA
SELINE)
.addComponent(Btn4, javax.swing.GroupLayout.PREFERRED_SIZE,
30, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(Btn5, javax.swing.GroupLayout.PREFERRED_SIZE,
30, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(ORBtn, javax.swing.GroupLayout.PREFERRED_SIZE,
30, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(ANDBtn,
javax.swing.GroupLayout.PREFERRED_SIZE, 30,
javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BA
SELINE)
.addComponent(Btn2, javax.swing.GroupLayout.PREFERRED_SIZE,
30, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(NORBtn,
javax.swing.GroupLayout.PREFERRED_SIZE, 30,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(pointBtn,
javax.swing.GroupLayout.PREFERRED_SIZE, 30,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(Btn3, javax.swing.GroupLayout.PREFERRED_SIZE,
30, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BA
SELINE)
.addComponent(Btn0, javax.swing.GroupLayout.PREFERRED_SIZE,
30, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(NANDBtn,
javax.swing.GroupLayout.PREFERRED_SIZE, 30,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(Btn1, javax.swing.GroupLayout.PREFERRED_SIZE,
30, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BA
SELINE)
.addComponent(EqualityBtn,
javax.swing.GroupLayout.PREFERRED_SIZE, 30,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(SquarerootBtn,
javax.swing.GroupLayout.PREFERRED_SIZE, 30,
javax.swing.GroupLayout.PREFERRED_SIZE))
9. .addContainerGap(88, Short.MAX_VALUE))
);
javax.swing.GroupLayout layout = new
javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(100, 100, 100)
.addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap(66, Short.MAX_VALUE))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(110, 110, 110)
.addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap(127, Short.MAX_VALUE))
);
pack();
}// </editor-fold>
private void Btn2ActionPerformed(java.awt.event.ActionEvent evt) {
String btn2=calculateroutput.getText()+Btn2.getText();
calculateroutput.setText(btn2);
}
private void Btn0ActionPerformed(java.awt.event.ActionEvent evt) {
String btn0=calculateroutput.getText()+Btn0.getText();
calculateroutput.setText(btn0);
}
private void Btn1ActionPerformed(java.awt.event.ActionEvent evt) {
String btn1=calculateroutput.getText()+Btn1.getText();
calculateroutput.setText(btn1);
}
private void Btn3ActionPerformed(java.awt.event.ActionEvent evt) {
String btn3=calculateroutput.getText()+Btn3.getText();
calculateroutput.setText(btn3);
}
private void Btn4ActionPerformed(java.awt.event.ActionEvent evt) {
String btn4=calculateroutput.getText()+Btn4.getText();
calculateroutput.setText(btn4);
}
private void Btn5ActionPerformed(java.awt.event.ActionEvent evt) {
10. String btn5=calculateroutput.getText()+Btn5.getText();
calculateroutput.setText(btn5);
}
private void Btn6ActionPerformed(java.awt.event.ActionEvent evt) {
String btn6=calculateroutput.getText()+Btn6.getText();
calculateroutput.setText(btn6);
}
private void Btn7ActionPerformed(java.awt.event.ActionEvent evt) {
String btn7=calculateroutput.getText()+Btn7.getText();
calculateroutput.setText(btn7);
}
private void Btn8ActionPerformed(java.awt.event.ActionEvent evt) {
String btn8=calculateroutput.getText()+Btn8.getText();
calculateroutput.setText(btn8);
}
private void Btn9ActionPerformed(java.awt.event.ActionEvent evt) {
String btn9=calculateroutput.getText()+Btn9.getText();
calculateroutput.setText(btn9);
}
private void PlusBtnActionPerformed(java.awt.event.ActionEvent evt) {
String Btntext=PlusBtn.getText();
getOperater(Btntext);
}
private void EqualityBtnActionPerformed(java.awt.event.ActionEvent evt) {
switch(math_operater)
{
case '+':
total2=total1+Double.parseDouble(calculateroutput.getText());
calculateroutput.setText(Double.toString(total1)+"+"+calculateroutput.getText()
+"="+"n"+Double.toString(total2));
total1=0;
break;
case '-':
total2=total1-Double.parseDouble(calculateroutput.getText());
calculateroutput.setText(Double.toString(total1)+"-"+calculateroutput.getText()
+"="+"n"+Double.toString(total2));
total1=0;
break;
case '*':
total2=total1*Double.parseDouble(calculateroutput.getText());
calculateroutput.setText(Double.toString(total1)+"*"+calculateroutput.getText()
+"="+"n"+Double.toString(total2));
total1=0;
12. {
JOptionPane.showMessageDialog(null, "Please input binary
number and must be single bit");
}
total2=0;
total1=0;
break;
case 'N':
if(Integer.parseInt(calculateroutput.getText())==1 ||
Integer.parseInt(calculateroutput.getText())==0)
{
total2=total1+Double.parseDouble(calculateroutput.getText());
if(total2==0)
{
calculateroutput.setText("True");
}
else
{
calculateroutput.setText("False");
}
}
else
{
JOptionPane.showMessageDialog(null, "Please input binary
number and must be single bit");
}
total2=0;
total1=0;
break;
case 'n':
if(Integer.parseInt(calculateroutput.getText())==1 ||
Integer.parseInt(calculateroutput.getText())==0)
{
total2=total1*Double.parseDouble(calculateroutput.getText());
if(total2==0)
{
calculateroutput.setText("True");
}
else
{
calculateroutput.setText("False");
}
}
else
{
JOptionPane.showMessageDialog(null, "Please input binary
number and must be single bit");
}
total2=0;
total1=0;
break;
}
}
private void MinusBtnActionPerformed(java.awt.event.ActionEvent evt) {
String Btntext=MinusBtn.getText();
getOperater(Btntext);
}
13. private void DivideBtnActionPerformed(java.awt.event.ActionEvent evt) {
String Btntext=DivideBtn.getText();
getOperater(Btntext);
}
private void MultiplyBtnActionPerformed(java.awt.event.ActionEvent evt) {
String Btntext=MultiplyBtn.getText();
getOperater(Btntext);
}
private void ClearBtnActionPerformed(java.awt.event.ActionEvent evt) {
total2=0;
total3=1;
sum=0;
calculateroutput.setText("");
}
private void SquarerootBtnActionPerformed(java.awt.event.ActionEvent evt) {
double number=Double.parseDouble(calculateroutput.getText());
if(calculateroutput.getText().charAt(0)=='-')
{
JOptionPane.showMessageDialog(null, "Invalid number");
}
else
{
double squareroot=number/2;
do
{
d=squareroot;
squareroot=(d+(number/d))/2;
}
while((d-squareroot)!=0);
calculateroutput.setText(Double.toString(squareroot));
}
}
private void pointBtnActionPerformed(java.awt.event.ActionEvent evt) {
String btnpoint=calculateroutput.getText()+pointBtn.getText();
calculateroutput.setText(btnpoint);
}
private void RemainderBtnActionPerformed(java.awt.event.ActionEvent evt) {
String Btntext=RemainderBtn.getText();
getOperater(Btntext);
}
private void PowerBtnActionPerformed(java.awt.event.ActionEvent evt) {
String Btntext=PowerBtn.getText();
getOperater(Btntext);
}
private void SignBtnActionPerformed(java.awt.event.ActionEvent evt) {
String Sign=Double.toString(total1-
Double.parseDouble(calculateroutput.getText()));
14. calculateroutput.setText(Sign);
}
private void calculateroutputKeyPressed(java.awt.event.KeyEvent evt) {
JOptionPane.showMessageDialog(null, "Input through Buttons");
String str=calculateroutput.getText();
str="";
calculateroutput.setText(str);
}
private void ORBtnActionPerformed(java.awt.event.ActionEvent evt) {
if(Double.parseDouble(calculateroutput.getText())==1 ||
Double.parseDouble(calculateroutput.getText())==0)
{
String OR=ORBtn.getText();
getOperater(OR);
}
else
{
JOptionPane.showMessageDialog(null, "Please input binary number and
Must be a single Bit");
}
}
private void ANDBtnActionPerformed(java.awt.event.ActionEvent evt) {
if(Double.parseDouble(calculateroutput.getText())==1 ||
Double.parseDouble(calculateroutput.getText())==0)
{
String AND=ANDBtn.getText();
getOperater(AND);
}
else
{
JOptionPane.showMessageDialog(null, "Please input binary number and
Must be a single Bit");
}
}
private void NORBtnActionPerformed(java.awt.event.ActionEvent evt) {
if(Double.parseDouble(calculateroutput.getText())==1 ||
Double.parseDouble(calculateroutput.getText())==0)
{
getOperater("N");
}
else
{
JOptionPane.showMessageDialog(null, "Please input binary number and
Must be a single Bit");
}
}
private void NANDBtnActionPerformed(java.awt.event.ActionEvent evt) {
if(Double.parseDouble(calculateroutput.getText())==1 ||
Double.parseDouble(calculateroutput.getText())==0)
{
getOperater("n");
}
15. else
{
JOptionPane.showMessageDialog(null, "Please input binary number and
Must be a single Bit");
}
}
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
/* Set the Nimbus look and feel */
//<editor-fold defaultstate="collapsed" desc=" Look and feel setting
code (optional) ">
/* If Nimbus (introduced in Java SE 6) is not available, stay with the
default look and feel.
* For details see
http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
*/
try {
for (javax.swing.UIManager.LookAndFeelInfo info :
javax.swing.UIManager.getInstalledLookAndFeels()) {
if ("Nimbus".equals(info.getName())) {
javax.swing.UIManager.setLookAndFeel(info.getClassName());
break;
}
}
} catch (ClassNotFoundException ex) {
java.util.logging.Logger.getLogger(Calculater.class.getName()).log(java.util.log
ging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(Calculater.class.getName()).log(java.util.log
ging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(Calculater.class.getName()).log(java.util.log
ging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(Calculater.class.getName()).log(java.util.log
ging.Level.SEVERE, null, ex);
}
//</editor-fold>
/* Create and display the form */
java.awt.EventQueue.invokeLater(new Runnable() {
@Override
public void run() {
new Calculater().setVisible(true);
}
});
}
// Variables declaration - do not modify
private javax.swing.JButton ANDBtn;
private javax.swing.JButton Btn0;
private javax.swing.JButton Btn1;
private javax.swing.JButton Btn2;
private javax.swing.JButton Btn3;
private javax.swing.JButton Btn4;
private javax.swing.JButton Btn5;
private javax.swing.JButton Btn6;
16. private javax.swing.JButton Btn7;
private javax.swing.JButton Btn8;
private javax.swing.JButton Btn9;
private javax.swing.JButton ClearBtn;
private javax.swing.JButton DivideBtn;
private javax.swing.JButton EqualityBtn;
private javax.swing.JButton MinusBtn;
private javax.swing.JButton MultiplyBtn;
private javax.swing.JButton NANDBtn;
private javax.swing.JButton NORBtn;
private javax.swing.JButton ORBtn;
private javax.swing.JButton PlusBtn;
private javax.swing.JButton PowerBtn;
private javax.swing.JButton RemainderBtn;
private javax.swing.JButton SignBtn;
private javax.swing.JButton SquarerootBtn;
private javax.swing.JTextPane calculateroutput;
private javax.swing.JPanel jPanel1;
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JSlider jSlider1;
private javax.swing.JButton pointBtn;
// End of variables declaration
}