import java.awt.HeadlessException;
import javax.swing.JTextField;
import javax.swing.JOptionPane;
/**
*
* @author Saeed
*/
public class Calc extends java.awt.Frame {
public String x="",x1="",exp1,exp2,operand;
/** Creates new form Calc */
public Calc() {
initComponents();
}
/** 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.
*/
//
private void initComponents() {
btn0 = new javax.swing.JButton();
btn1 = new javax.swing.JButton();
btn2 = new javax.swing.JButton();
btn3 = new javax.swing.JButton();
btn4 = new javax.swing.JButton();
btn5 = new javax.swing.JButton();
btn6 = new javax.swing.JButton();
btn7 = new javax.swing.JButton();
btn8 = new javax.swing.JButton();
btn9 = new javax.swing.JButton();
jButton11 = new javax.swing.JButton();
txtScreen = new javax.swing.JTextField();
btnDot = new javax.swing.JButton();
btnPlus = new javax.swing.JButton();
btnMinus = new javax.swing.JButton();
btnMultiply = new javax.swing.JButton();
btnDivide = new javax.swing.JButton();
jButton17 = new javax.swing.JButton();
jButton18 = new javax.swing.JButton();
jButton19 = new javax.swing.JButton();
btnEqual = new javax.swing.JButton();
btnOnOff = new javax.swing.JButton();
btnClear = new javax.swing.JButton();
btnBkSpace = new javax.swing.JButton();
setBackground(java.awt.Color.lightGray);
setResizable(false);
setTitle("Calculator V 0.1.2.12 Beta");
addWindowListener(new java.awt.event.WindowAdapter() {
@Override
public void windowActivated(java.awt.event.WindowEvent evt) {
formWindowActivated(evt);
}
@Override
public void windowClosing(java.awt.event.WindowEvent evt) {
exitForm(evt);
}
@Override
public void windowOpened(java.awt.event.WindowEvent evt) {
formWindowOpened(evt);
}
});
btn0.setFont(new java.awt.Font("Lucida Sans Unicode", 1, 24));
btn0.setText("0");
btn0.setToolTipText("Zero");
btn0.setPreferredSize(new java.awt.Dimension(57, 41));
btn0.addActionListener(new java.awt.event.ActionListener() {
@Override
public void actionPerformed(java.awt.event.ActionEvent evt) {
btn0ActionPerformed(evt);
}
});
btn1.setFont(new java.awt.Font("Lucida Sans Unicode", 1, 24));
btn1.setText("1");
btn1.setToolTipText("One");
btn1.setPreferredSize(new java.awt.Dimension(57, 41));
btn1.addActionListener(new java.awt.event.ActionListener() {
@Override
public void actionPerformed(java.awt.event.ActionEvent evt) {
btn1ActionPerformed(evt);
}
});
btn2.setFont(new java.awt.Font("Lucida Sans Unicode", 1, 24));
btn2.setText("2");
btn2.setToolTipText("Two");
btn2.setPreferredSize(new java.awt.Dimension(57, 41));
btn2.addActionListener(new java.awt.event.ActionListener() {
@Override
public void actionPerformed(java.awt.event.ActionEvent evt) {
btn2ActionPerformed(evt);
}
});
btn3.setFont(new java.awt.Font("Lucida Sans Unicode", 1, 24));
btn3.setText("3");
btn3.setToolTipText("Three");
btn3.setPreferredSize(new java.awt.Dimension(57, 41));
btn3.addActionListener(new java.awt.event.ActionListener() {
@Override
public void actionPerformed(java.awt.event.ActionEvent evt) {
btn3ActionPerformed(evt);
}
});
btn4.setFont(new java.awt.Font("Lucida Sans Unicode", 1, 24));
btn4.setText("4");
btn4.setToolTipText("Four");
btn4.setPreferredSize(new java.awt.Dimension(57, 41));
btn4.addActionListener(new java.awt.event.ActionListener() {
@Override
public void actionPerformed(java.awt.event.ActionEvent evt) {
btn4ActionPerformed(evt);
}
});
btn5.setFont(new java.awt.Font("Lucida Sans Unicode", 1, 24));
btn5.setText("5");
btn5.setToolTipText("Five");
btn5.setPreferredSize(new java.awt.Dimension(57, 41));
btn5.addActionListener(new java.awt.event.ActionListener() {
@Override
public void actionPerformed(java.awt.event.ActionEvent evt) {
btn5ActionPerformed(evt);
}
});
btn6.setFont(new java.awt.Font("Lucida Sans Unicode", 1, 24));
btn6.setText("6");
btn6.setToolTipText("Six");
btn6.setPreferredSize(new java.awt.Dimension(57, 41));
btn6.addActionListener(new java.awt.event.ActionListener() {
@Override
public void actionPerformed(java.awt.event.ActionEvent evt) {
btn6ActionPerformed(evt);
}
});
btn7.setFont(new java.awt.Font("Lucida Sans Unicode", 1, 24));
btn7.setText("7");
btn7.setToolTipText("Seven");
btn7.setPreferredSize(new java.awt.Dimension(57, 41));
btn7.addActionListener(new java.awt.event.ActionListener() {
@Override
public void actionPerformed(java.awt.event.ActionEvent evt) {
btn7ActionPerformed(evt);
}
});
btn8.setFont(new java.awt.Font("Lucida Sans Unicode", 1, 24));
btn8.setText("8");
btn8.setToolTipText("Eight");
btn8.setPreferredSize(new java.awt.Dimension(57, 41));
btn8.addActionListener(new java.awt.event.ActionListener() {
@Override
public void actionPerformed(java.awt.event.ActionEvent evt) {
btn8ActionPerformed(evt);
}
});
btn9.setFont(new java.awt.Font("Lucida Sans Unicode", 1, 24));
btn9.setText("9");
btn9.setToolTipText("Nine");
btn9.setPreferredSize(new java.awt.Dimension(57, 41));
btn9.addActionListener(new java.awt.event.ActionListener() {
@Override
public void actionPerformed(java.awt.event.ActionEvent evt) {
btn9ActionPerformed(evt);
}
});
jButton11.setFont(new java.awt.Font("Lucida Sans Unicode", 1, 10));
jButton11.setForeground(new java.awt.Color(0, 0, 255));
jButton11.setText("+/-");
jButton11.setToolTipText("Plus / Minus");
jButton11.setPreferredSize(new java.awt.Dimension(57, 41));
jButton11.addActionListener(new java.awt.event.ActionListener() {
@Override
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton11ActionPerformed(evt);
}
});
txtScreen.setBackground(new java.awt.Color(204, 204, 204));
txtScreen.setFont(new java.awt.Font("Lucida Sans", 1, 30)); // NOI18N
txtScreen.setToolTipText("Enter digits by using given bottons.");
txtScreen.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.LOWERED));
txtScreen.setMargin(new java.awt.Insets(2, 2, 2, 2));
btnDot.setFont(new java.awt.Font("Lucida Sans Unicode", 1, 24));
btnDot.setText(".");
btnDot.setToolTipText("Point");
btnDot.setPreferredSize(new java.awt.Dimension(57, 41));
btnDot.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnDotActionPerformed(evt);
}
});
btnPlus.setFont(new java.awt.Font("Lucida Sans Unicode", 1, 24));
btnPlus.setForeground(new java.awt.Color(0, 0, 255));
btnPlus.setText("+");
btnPlus.setToolTipText("Plus");
btnPlus.setPreferredSize(new java.awt.Dimension(57, 41));
btnPlus.addActionListener(new java.awt.event.ActionListener() {
@Override
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnPlusActionPerformed(evt);
}
});
btnMinus.setFont(new java.awt.Font("Lucida Sans Unicode", 1, 24));
btnMinus.setForeground(new java.awt.Color(0, 0, 255));
btnMinus.setText("-");
btnMinus.setToolTipText("Minus");
btnMinus.setPreferredSize(new java.awt.Dimension(57, 41));
btnMinus.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnMinusActionPerformed(evt);
}
});
btnMultiply.setFont(new java.awt.Font("Lucida Sans Unicode", 1, 24));
btnMultiply.setForeground(new java.awt.Color(0, 0, 255));
btnMultiply.setText("x");
btnMultiply.setToolTipText("Multiply");
btnMultiply.setPreferredSize(new java.awt.Dimension(57, 41));
btnMultiply.addActionListener(new java.awt.event.ActionListener() {
@Override
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnMultiplyActionPerformed(evt);
}
});
btnDivide.setFont(new java.awt.Font("Lucida Sans Unicode", 1, 24));
btnDivide.setForeground(new java.awt.Color(0, 0, 255));
btnDivide.setText("/");
btnDivide.setToolTipText("Divide");
btnDivide.setMaximumSize(new java.awt.Dimension(57, 41));
btnDivide.setMinimumSize(new java.awt.Dimension(57, 41));
btnDivide.setPreferredSize(new java.awt.Dimension(57, 41));
btnDivide.addActionListener(new java.awt.event.ActionListener() {
@Override
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnDivideActionPerformed(evt);
}
});
jButton17.setFont(new java.awt.Font("Lucida Sans Unicode", 1, 12));
jButton17.setForeground(new java.awt.Color(0, 0, 255));
jButton17.setText("Sqrt");
jButton17.setToolTipText("Square Root");
jButton17.setPreferredSize(new java.awt.Dimension(57, 41));
jButton17.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton17ActionPerformed(evt);
}
});
jButton18.setFont(new java.awt.Font("Lucida Sans Unicode", 1, 24));
jButton18.setForeground(new java.awt.Color(0, 0, 255));
jButton18.setText("%");
jButton18.setToolTipText("Percentage");
jButton18.setPreferredSize(new java.awt.Dimension(57, 41));
jButton18.addActionListener(new java.awt.event.ActionListener() {
@Override
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton18ActionPerformed(evt);
}
});
jButton19.setFont(new java.awt.Font("Lucida Sans Unicode", 1, 14));
jButton19.setForeground(new java.awt.Color(0, 0, 255));
jButton19.setText("1/x");
jButton19.setToolTipText("Inverse");
jButton19.setPreferredSize(new java.awt.Dimension(57, 41));
jButton19.addActionListener(new java.awt.event.ActionListener() {
@Override
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton19ActionPerformed(evt);
}
});
btnEqual.setFont(new java.awt.Font("Lucida Sans Unicode", 1, 40));
btnEqual.setForeground(new java.awt.Color(0, 204, 102));
btnEqual.setText("=");
btnEqual.setToolTipText("Equal / Answer");
btnEqual.setPreferredSize(new java.awt.Dimension(57, 41));
btnEqual.addActionListener(new java.awt.event.ActionListener() {
@Override
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnEqualActionPerformed(evt);
}
});
btnOnOff.setFont(new java.awt.Font("Lucida Sans Unicode", 1, 12));
btnOnOff.setForeground(new java.awt.Color(255, 51, 51));
btnOnOff.setText("On/Off");
btnOnOff.setToolTipText("Switch On / Off Screen");
btnOnOff.setPreferredSize(new java.awt.Dimension(57, 41));
btnOnOff.addActionListener(new java.awt.event.ActionListener() {
@Override
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnOnOffActionPerformed(evt);
}
});
btnClear.setFont(new java.awt.Font("Lucida Sans Unicode", 1, 24));
btnClear.setForeground(new java.awt.Color(255, 51, 51));
btnClear.setText("C");
btnClear.setToolTipText("Clear Screen");
btnClear.setPreferredSize(new java.awt.Dimension(57, 41));
btnClear.addActionListener(new java.awt.event.ActionListener() {
@Override
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnClearActionPerformed(evt);
}
});
btnBkSpace.setFont(new java.awt.Font("Lucida Sans Unicode", 1, 14));
btnBkSpace.setForeground(new java.awt.Color(255, 51, 51));
btnBkSpace.setText("Back Space");
btnBkSpace.setToolTipText("Take back one digit");
btnBkSpace.setPreferredSize(new java.awt.Dimension(57, 41));
btnBkSpace.addActionListener(new java.awt.event.ActionListener() {
@Override
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnBkSpaceActionPerformed(evt);
}
});
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
this.setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addContainerGap()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(txtScreen, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 321, Short.MAX_VALUE)
.addGroup(layout.createSequentialGroup()
.addComponent(btnBkSpace, javax.swing.GroupLayout.DEFAULT_SIZE, 141, Short.MAX_VALUE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(btnClear, javax.swing.GroupLayout.PREFERRED_SIZE, 86, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(btnOnOff, javax.swing.GroupLayout.PREFERRED_SIZE, 82, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(btn4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGroup(layout.createSequentialGroup()
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(btn7, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addComponent(btn0, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(btn1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(btn5, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(btn8, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jButton11, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(btn2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(btn9, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(btn6, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(btnDot, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(btn3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(btnMinus, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(btnMultiply, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(btnDivide, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(btnPlus, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jButton17, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 69, Short.MAX_VALUE)
.addComponent(jButton18, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 69, Short.MAX_VALUE)
.addComponent(jButton19, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 69, Short.MAX_VALUE)
.addComponent(btnEqual, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 69, Short.MAX_VALUE))))
.addContainerGap())
);
layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {btn0, jButton11});
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(txtScreen, javax.swing.GroupLayout.PREFERRED_SIZE, 49, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(btnClear, javax.swing.GroupLayout.PREFERRED_SIZE, 41, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(btnBkSpace, javax.swing.GroupLayout.PREFERRED_SIZE, 41, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(btnOnOff, javax.swing.GroupLayout.PREFERRED_SIZE, 41, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addComponent(btn7, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(btn4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(btn1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(btn0, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(layout.createSequentialGroup()
.addComponent(btn8, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(btn5, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(btn2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jButton11, javax.swing.GroupLayout.PREFERRED_SIZE, 47, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(layout.createSequentialGroup()
.addComponent(btn9, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(btn6, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(btn3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(btnDot, javax.swing.GroupLayout.PREFERRED_SIZE, 47, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(layout.createSequentialGroup()
.addComponent(btnDivide, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(btnMultiply, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(btnMinus, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(btnPlus, javax.swing.GroupLayout.PREFERRED_SIZE, 47, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(layout.createSequentialGroup()
.addComponent(jButton17, javax.swing.GroupLayout.PREFERRED_SIZE, 41, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jButton18, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jButton19, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(btnEqual, javax.swing.GroupLayout.PREFERRED_SIZE, 47, javax.swing.GroupLayout.PREFERRED_SIZE)))
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
);
layout.linkSize(javax.swing.SwingConstants.VERTICAL, new java.awt.Component[] {btn0, jButton11});
pack();
}//
/** Exit the Application */
private void exitForm(java.awt.event.WindowEvent evt) {
System.exit(0);
}
private void btn0ActionPerformed(java.awt.event.ActionEvent evt) {
txtScreen.setText(txtScreen.getText()+btn0.getText());
}
private void jButton11ActionPerformed(java.awt.event.ActionEvent evt) {
JOptionPane.showMessageDialog(null, "Still not process this button \n Contact at +92-301-7640931 \n mbit.dbms@gmail.com", "Information",JOptionPane.INFORMATION_MESSAGE);
}
private void formWindowActivated(java.awt.event.WindowEvent evt) {
//txtScreen.setVisible(false);
}
private void btnDotActionPerformed(java.awt.event.ActionEvent evt) {
txtScreen.setText(txtScreen.getText()+btnDot.getText());
}
private void btnPlusActionPerformed(java.awt.event.ActionEvent evt) {
if ( txtScreen.getText().length()<=0 )
JOptionPane.showMessageDialog(null, "Screen Empty", "Error",JOptionPane.INFORMATION_MESSAGE);
else
exp1=txtScreen.getText();
operand=btnPlus.getText();
txtScreen.setText("");
}
private void btnMinusActionPerformed(java.awt.event.ActionEvent evt) {
if ( txtScreen.getText().length()<=0 )
JOptionPane.showMessageDialog(null, "Screen Empty", "Error",JOptionPane.INFORMATION_MESSAGE);
else
exp1=txtScreen.getText();
operand=btnMinus.getText();
txtScreen.setText("");
}
private void btnMultiplyActionPerformed(java.awt.event.ActionEvent evt) {
if ( txtScreen.getText().length()<=0 )
JOptionPane.showMessageDialog(null, "Screen Empty", "Error",JOptionPane.INFORMATION_MESSAGE);
else
exp1=txtScreen.getText();
operand=btnMultiply.getText();
txtScreen.setText("");
}
private void btnDivideActionPerformed(java.awt.event.ActionEvent evt) {
if ( txtScreen.getText().length()<=0 )
JOptionPane.showMessageDialog(null, "Screen Empty", "Error",JOptionPane.INFORMATION_MESSAGE);
else
exp1=txtScreen.getText();
operand=btnDivide.getText();
txtScreen.setText("");
}
private void jButton17ActionPerformed(java.awt.event.ActionEvent evt) {
JOptionPane.showMessageDialog(null, "Still not process this button \n Contact at +92-301-7640931 \n mbit.dbms@gmail.com", "Information",JOptionPane.INFORMATION_MESSAGE);
}
private void jButton18ActionPerformed(java.awt.event.ActionEvent evt) {
JOptionPane.showMessageDialog(null, "Still not process this button \n Contact at +92-301-7640931 \n mbit.dbms@gmail.com", "Information",JOptionPane.INFORMATION_MESSAGE);
}
private void jButton19ActionPerformed(java.awt.event.ActionEvent evt) {
JOptionPane.showMessageDialog(null, "Still not process this button \n Contact at +92-301-7640931 \n mbit.dbms@gmail.com", "Information",JOptionPane.INFORMATION_MESSAGE);
}
private void btnEqualActionPerformed(java.awt.event.ActionEvent evt) {
try{
if ( txtScreen.getText().length()<=0 ) {
JOptionPane.showMessageDialog(null, "Screen Empty", "Error",JOptionPane.WARNING_MESSAGE);
}
else
{
exp2=txtScreen.getText();
//Start the Process according to the Operator,
double n=(double) Double.parseDouble(exp1);
double m=(double) Double.parseDouble(exp2);
char op=operand.charAt(0);
switch(op){
case '/':
txtScreen.setText(Double.toString(n/m));
break;
case 'x':
txtScreen.setText(Double.toString(n*m));
break;
case '+':
txtScreen.setText(Double.toString(n+m));
break;
case '-':
txtScreen.setText(Double.toString(n-m));
break;
}// end of switch
}// End of else
}catch(HeadlessException | NumberFormatException e){
txtScreen.setText("Syntax Error");
}// End of try catch block
}
private void formWindowOpened(java.awt.event.WindowEvent evt) {
txtScreen.setHorizontalAlignment(JTextField.RIGHT);
txtScreen.setText("");
txtScreen.enableInputMethods(false);
setLocationRelativeTo(null);
}
private void btnOnOffActionPerformed(java.awt.event.ActionEvent evt) {
JOptionPane.showMessageDialog(null, "Still not process this button \n Contact at +92-301-7640931 \n mbit.dbms@gmail.com", "Information",JOptionPane.INFORMATION_MESSAGE);
}
private void btnClearActionPerformed(java.awt.event.ActionEvent evt) {
txtScreen.setText("");
}
private void btnBkSpaceActionPerformed(java.awt.event.ActionEvent evt) {
if ( txtScreen.getText().length()<=0 ) {
JOptionPane.showMessageDialog(null, "Screen Empty", "Error",JOptionPane.WARNING_MESSAGE);
}
else {
txtScreen.setText(txtScreen.getText().substring(0, txtScreen.getText().length()-1));
}
}
private void btn1ActionPerformed(java.awt.event.ActionEvent evt) {
txtScreen.setText(txtScreen.getText()+btn1.getText());
}
private void btn2ActionPerformed(java.awt.event.ActionEvent evt) {
txtScreen.setText(txtScreen.getText() + btn2.getText());
}
private void btn3ActionPerformed(java.awt.event.ActionEvent evt) {
txtScreen.setText(txtScreen.getText()+btn3.getText());
}
private void btn4ActionPerformed(java.awt.event.ActionEvent evt) {
txtScreen.setText(txtScreen.getText()+btn4.getText());
}
private void btn5ActionPerformed(java.awt.event.ActionEvent evt) {
txtScreen.setText(txtScreen.getText()+btn5.getText());
}
private void btn6ActionPerformed(java.awt.event.ActionEvent evt) {
txtScreen.setText(txtScreen.getText()+btn6.getText());
}
private void btn7ActionPerformed(java.awt.event.ActionEvent evt) {
txtScreen.setText(txtScreen.getText()+btn7.getText());
}
private void btn8ActionPerformed(java.awt.event.ActionEvent evt) {
txtScreen.setText(txtScreen.getText()+btn8.getText());
}
private void btn9ActionPerformed(java.awt.event.ActionEvent evt) {
txtScreen.setText(txtScreen.getText()+btn9.getText());
}
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
@Override
public void run() {
new Calc().setVisible(true);
}
});
}
// Variables declaration - do not modify
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;
private javax.swing.JButton btn7;
private javax.swing.JButton btn8;
private javax.swing.JButton btn9;
private javax.swing.JButton btnBkSpace;
private javax.swing.JButton btnClear;
private javax.swing.JButton btnDivide;
private javax.swing.JButton btnDot;
private javax.swing.JButton btnEqual;
private javax.swing.JButton btnMinus;
private javax.swing.JButton btnMultiply;
private javax.swing.JButton btnOnOff;
private javax.swing.JButton btnPlus;
private javax.swing.JButton jButton11;
private javax.swing.JButton jButton17;
private javax.swing.JButton jButton18;
private javax.swing.JButton jButton19;
private javax.swing.JTextField txtScreen;
// End of variables declaration
}
import javax.swing.JTextField;
import javax.swing.JOptionPane;
/**
*
* @author Saeed
*/
public class Calc extends java.awt.Frame {
public String x="",x1="",exp1,exp2,operand;
/** Creates new form Calc */
public Calc() {
initComponents();
}
/** 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.
*/
//
private void initComponents() {
btn0 = new javax.swing.JButton();
btn1 = new javax.swing.JButton();
btn2 = new javax.swing.JButton();
btn3 = new javax.swing.JButton();
btn4 = new javax.swing.JButton();
btn5 = new javax.swing.JButton();
btn6 = new javax.swing.JButton();
btn7 = new javax.swing.JButton();
btn8 = new javax.swing.JButton();
btn9 = new javax.swing.JButton();
jButton11 = new javax.swing.JButton();
txtScreen = new javax.swing.JTextField();
btnDot = new javax.swing.JButton();
btnPlus = new javax.swing.JButton();
btnMinus = new javax.swing.JButton();
btnMultiply = new javax.swing.JButton();
btnDivide = new javax.swing.JButton();
jButton17 = new javax.swing.JButton();
jButton18 = new javax.swing.JButton();
jButton19 = new javax.swing.JButton();
btnEqual = new javax.swing.JButton();
btnOnOff = new javax.swing.JButton();
btnClear = new javax.swing.JButton();
btnBkSpace = new javax.swing.JButton();
setBackground(java.awt.Color.lightGray);
setResizable(false);
setTitle("Calculator V 0.1.2.12 Beta");
addWindowListener(new java.awt.event.WindowAdapter() {
@Override
public void windowActivated(java.awt.event.WindowEvent evt) {
formWindowActivated(evt);
}
@Override
public void windowClosing(java.awt.event.WindowEvent evt) {
exitForm(evt);
}
@Override
public void windowOpened(java.awt.event.WindowEvent evt) {
formWindowOpened(evt);
}
});
btn0.setFont(new java.awt.Font("Lucida Sans Unicode", 1, 24));
btn0.setText("0");
btn0.setToolTipText("Zero");
btn0.setPreferredSize(new java.awt.Dimension(57, 41));
btn0.addActionListener(new java.awt.event.ActionListener() {
@Override
public void actionPerformed(java.awt.event.ActionEvent evt) {
btn0ActionPerformed(evt);
}
});
btn1.setFont(new java.awt.Font("Lucida Sans Unicode", 1, 24));
btn1.setText("1");
btn1.setToolTipText("One");
btn1.setPreferredSize(new java.awt.Dimension(57, 41));
btn1.addActionListener(new java.awt.event.ActionListener() {
@Override
public void actionPerformed(java.awt.event.ActionEvent evt) {
btn1ActionPerformed(evt);
}
});
btn2.setFont(new java.awt.Font("Lucida Sans Unicode", 1, 24));
btn2.setText("2");
btn2.setToolTipText("Two");
btn2.setPreferredSize(new java.awt.Dimension(57, 41));
btn2.addActionListener(new java.awt.event.ActionListener() {
@Override
public void actionPerformed(java.awt.event.ActionEvent evt) {
btn2ActionPerformed(evt);
}
});
btn3.setFont(new java.awt.Font("Lucida Sans Unicode", 1, 24));
btn3.setText("3");
btn3.setToolTipText("Three");
btn3.setPreferredSize(new java.awt.Dimension(57, 41));
btn3.addActionListener(new java.awt.event.ActionListener() {
@Override
public void actionPerformed(java.awt.event.ActionEvent evt) {
btn3ActionPerformed(evt);
}
});
btn4.setFont(new java.awt.Font("Lucida Sans Unicode", 1, 24));
btn4.setText("4");
btn4.setToolTipText("Four");
btn4.setPreferredSize(new java.awt.Dimension(57, 41));
btn4.addActionListener(new java.awt.event.ActionListener() {
@Override
public void actionPerformed(java.awt.event.ActionEvent evt) {
btn4ActionPerformed(evt);
}
});
btn5.setFont(new java.awt.Font("Lucida Sans Unicode", 1, 24));
btn5.setText("5");
btn5.setToolTipText("Five");
btn5.setPreferredSize(new java.awt.Dimension(57, 41));
btn5.addActionListener(new java.awt.event.ActionListener() {
@Override
public void actionPerformed(java.awt.event.ActionEvent evt) {
btn5ActionPerformed(evt);
}
});
btn6.setFont(new java.awt.Font("Lucida Sans Unicode", 1, 24));
btn6.setText("6");
btn6.setToolTipText("Six");
btn6.setPreferredSize(new java.awt.Dimension(57, 41));
btn6.addActionListener(new java.awt.event.ActionListener() {
@Override
public void actionPerformed(java.awt.event.ActionEvent evt) {
btn6ActionPerformed(evt);
}
});
btn7.setFont(new java.awt.Font("Lucida Sans Unicode", 1, 24));
btn7.setText("7");
btn7.setToolTipText("Seven");
btn7.setPreferredSize(new java.awt.Dimension(57, 41));
btn7.addActionListener(new java.awt.event.ActionListener() {
@Override
public void actionPerformed(java.awt.event.ActionEvent evt) {
btn7ActionPerformed(evt);
}
});
btn8.setFont(new java.awt.Font("Lucida Sans Unicode", 1, 24));
btn8.setText("8");
btn8.setToolTipText("Eight");
btn8.setPreferredSize(new java.awt.Dimension(57, 41));
btn8.addActionListener(new java.awt.event.ActionListener() {
@Override
public void actionPerformed(java.awt.event.ActionEvent evt) {
btn8ActionPerformed(evt);
}
});
btn9.setFont(new java.awt.Font("Lucida Sans Unicode", 1, 24));
btn9.setText("9");
btn9.setToolTipText("Nine");
btn9.setPreferredSize(new java.awt.Dimension(57, 41));
btn9.addActionListener(new java.awt.event.ActionListener() {
@Override
public void actionPerformed(java.awt.event.ActionEvent evt) {
btn9ActionPerformed(evt);
}
});
jButton11.setFont(new java.awt.Font("Lucida Sans Unicode", 1, 10));
jButton11.setForeground(new java.awt.Color(0, 0, 255));
jButton11.setText("+/-");
jButton11.setToolTipText("Plus / Minus");
jButton11.setPreferredSize(new java.awt.Dimension(57, 41));
jButton11.addActionListener(new java.awt.event.ActionListener() {
@Override
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton11ActionPerformed(evt);
}
});
txtScreen.setBackground(new java.awt.Color(204, 204, 204));
txtScreen.setFont(new java.awt.Font("Lucida Sans", 1, 30)); // NOI18N
txtScreen.setToolTipText("Enter digits by using given bottons.");
txtScreen.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.LOWERED));
txtScreen.setMargin(new java.awt.Insets(2, 2, 2, 2));
btnDot.setFont(new java.awt.Font("Lucida Sans Unicode", 1, 24));
btnDot.setText(".");
btnDot.setToolTipText("Point");
btnDot.setPreferredSize(new java.awt.Dimension(57, 41));
btnDot.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnDotActionPerformed(evt);
}
});
btnPlus.setFont(new java.awt.Font("Lucida Sans Unicode", 1, 24));
btnPlus.setForeground(new java.awt.Color(0, 0, 255));
btnPlus.setText("+");
btnPlus.setToolTipText("Plus");
btnPlus.setPreferredSize(new java.awt.Dimension(57, 41));
btnPlus.addActionListener(new java.awt.event.ActionListener() {
@Override
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnPlusActionPerformed(evt);
}
});
btnMinus.setFont(new java.awt.Font("Lucida Sans Unicode", 1, 24));
btnMinus.setForeground(new java.awt.Color(0, 0, 255));
btnMinus.setText("-");
btnMinus.setToolTipText("Minus");
btnMinus.setPreferredSize(new java.awt.Dimension(57, 41));
btnMinus.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnMinusActionPerformed(evt);
}
});
btnMultiply.setFont(new java.awt.Font("Lucida Sans Unicode", 1, 24));
btnMultiply.setForeground(new java.awt.Color(0, 0, 255));
btnMultiply.setText("x");
btnMultiply.setToolTipText("Multiply");
btnMultiply.setPreferredSize(new java.awt.Dimension(57, 41));
btnMultiply.addActionListener(new java.awt.event.ActionListener() {
@Override
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnMultiplyActionPerformed(evt);
}
});
btnDivide.setFont(new java.awt.Font("Lucida Sans Unicode", 1, 24));
btnDivide.setForeground(new java.awt.Color(0, 0, 255));
btnDivide.setText("/");
btnDivide.setToolTipText("Divide");
btnDivide.setMaximumSize(new java.awt.Dimension(57, 41));
btnDivide.setMinimumSize(new java.awt.Dimension(57, 41));
btnDivide.setPreferredSize(new java.awt.Dimension(57, 41));
btnDivide.addActionListener(new java.awt.event.ActionListener() {
@Override
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnDivideActionPerformed(evt);
}
});
jButton17.setFont(new java.awt.Font("Lucida Sans Unicode", 1, 12));
jButton17.setForeground(new java.awt.Color(0, 0, 255));
jButton17.setText("Sqrt");
jButton17.setToolTipText("Square Root");
jButton17.setPreferredSize(new java.awt.Dimension(57, 41));
jButton17.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton17ActionPerformed(evt);
}
});
jButton18.setFont(new java.awt.Font("Lucida Sans Unicode", 1, 24));
jButton18.setForeground(new java.awt.Color(0, 0, 255));
jButton18.setText("%");
jButton18.setToolTipText("Percentage");
jButton18.setPreferredSize(new java.awt.Dimension(57, 41));
jButton18.addActionListener(new java.awt.event.ActionListener() {
@Override
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton18ActionPerformed(evt);
}
});
jButton19.setFont(new java.awt.Font("Lucida Sans Unicode", 1, 14));
jButton19.setForeground(new java.awt.Color(0, 0, 255));
jButton19.setText("1/x");
jButton19.setToolTipText("Inverse");
jButton19.setPreferredSize(new java.awt.Dimension(57, 41));
jButton19.addActionListener(new java.awt.event.ActionListener() {
@Override
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton19ActionPerformed(evt);
}
});
btnEqual.setFont(new java.awt.Font("Lucida Sans Unicode", 1, 40));
btnEqual.setForeground(new java.awt.Color(0, 204, 102));
btnEqual.setText("=");
btnEqual.setToolTipText("Equal / Answer");
btnEqual.setPreferredSize(new java.awt.Dimension(57, 41));
btnEqual.addActionListener(new java.awt.event.ActionListener() {
@Override
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnEqualActionPerformed(evt);
}
});
btnOnOff.setFont(new java.awt.Font("Lucida Sans Unicode", 1, 12));
btnOnOff.setForeground(new java.awt.Color(255, 51, 51));
btnOnOff.setText("On/Off");
btnOnOff.setToolTipText("Switch On / Off Screen");
btnOnOff.setPreferredSize(new java.awt.Dimension(57, 41));
btnOnOff.addActionListener(new java.awt.event.ActionListener() {
@Override
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnOnOffActionPerformed(evt);
}
});
btnClear.setFont(new java.awt.Font("Lucida Sans Unicode", 1, 24));
btnClear.setForeground(new java.awt.Color(255, 51, 51));
btnClear.setText("C");
btnClear.setToolTipText("Clear Screen");
btnClear.setPreferredSize(new java.awt.Dimension(57, 41));
btnClear.addActionListener(new java.awt.event.ActionListener() {
@Override
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnClearActionPerformed(evt);
}
});
btnBkSpace.setFont(new java.awt.Font("Lucida Sans Unicode", 1, 14));
btnBkSpace.setForeground(new java.awt.Color(255, 51, 51));
btnBkSpace.setText("Back Space");
btnBkSpace.setToolTipText("Take back one digit");
btnBkSpace.setPreferredSize(new java.awt.Dimension(57, 41));
btnBkSpace.addActionListener(new java.awt.event.ActionListener() {
@Override
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnBkSpaceActionPerformed(evt);
}
});
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
this.setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addContainerGap()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(txtScreen, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 321, Short.MAX_VALUE)
.addGroup(layout.createSequentialGroup()
.addComponent(btnBkSpace, javax.swing.GroupLayout.DEFAULT_SIZE, 141, Short.MAX_VALUE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(btnClear, javax.swing.GroupLayout.PREFERRED_SIZE, 86, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(btnOnOff, javax.swing.GroupLayout.PREFERRED_SIZE, 82, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(btn4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGroup(layout.createSequentialGroup()
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(btn7, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addComponent(btn0, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(btn1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(btn5, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(btn8, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jButton11, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(btn2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(btn9, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(btn6, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(btnDot, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(btn3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(btnMinus, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(btnMultiply, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(btnDivide, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(btnPlus, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jButton17, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 69, Short.MAX_VALUE)
.addComponent(jButton18, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 69, Short.MAX_VALUE)
.addComponent(jButton19, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 69, Short.MAX_VALUE)
.addComponent(btnEqual, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 69, Short.MAX_VALUE))))
.addContainerGap())
);
layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {btn0, jButton11});
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(txtScreen, javax.swing.GroupLayout.PREFERRED_SIZE, 49, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(btnClear, javax.swing.GroupLayout.PREFERRED_SIZE, 41, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(btnBkSpace, javax.swing.GroupLayout.PREFERRED_SIZE, 41, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(btnOnOff, javax.swing.GroupLayout.PREFERRED_SIZE, 41, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addComponent(btn7, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(btn4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(btn1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(btn0, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(layout.createSequentialGroup()
.addComponent(btn8, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(btn5, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(btn2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jButton11, javax.swing.GroupLayout.PREFERRED_SIZE, 47, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(layout.createSequentialGroup()
.addComponent(btn9, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(btn6, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(btn3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(btnDot, javax.swing.GroupLayout.PREFERRED_SIZE, 47, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(layout.createSequentialGroup()
.addComponent(btnDivide, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(btnMultiply, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(btnMinus, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(btnPlus, javax.swing.GroupLayout.PREFERRED_SIZE, 47, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(layout.createSequentialGroup()
.addComponent(jButton17, javax.swing.GroupLayout.PREFERRED_SIZE, 41, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jButton18, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jButton19, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(btnEqual, javax.swing.GroupLayout.PREFERRED_SIZE, 47, javax.swing.GroupLayout.PREFERRED_SIZE)))
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
);
layout.linkSize(javax.swing.SwingConstants.VERTICAL, new java.awt.Component[] {btn0, jButton11});
pack();
}//
/** Exit the Application */
private void exitForm(java.awt.event.WindowEvent evt) {
System.exit(0);
}
private void btn0ActionPerformed(java.awt.event.ActionEvent evt) {
txtScreen.setText(txtScreen.getText()+btn0.getText());
}
private void jButton11ActionPerformed(java.awt.event.ActionEvent evt) {
JOptionPane.showMessageDialog(null, "Still not process this button \n Contact at +92-301-7640931 \n mbit.dbms@gmail.com", "Information",JOptionPane.INFORMATION_MESSAGE);
}
private void formWindowActivated(java.awt.event.WindowEvent evt) {
//txtScreen.setVisible(false);
}
private void btnDotActionPerformed(java.awt.event.ActionEvent evt) {
txtScreen.setText(txtScreen.getText()+btnDot.getText());
}
private void btnPlusActionPerformed(java.awt.event.ActionEvent evt) {
if ( txtScreen.getText().length()<=0 )
JOptionPane.showMessageDialog(null, "Screen Empty", "Error",JOptionPane.INFORMATION_MESSAGE);
else
exp1=txtScreen.getText();
operand=btnPlus.getText();
txtScreen.setText("");
}
private void btnMinusActionPerformed(java.awt.event.ActionEvent evt) {
if ( txtScreen.getText().length()<=0 )
JOptionPane.showMessageDialog(null, "Screen Empty", "Error",JOptionPane.INFORMATION_MESSAGE);
else
exp1=txtScreen.getText();
operand=btnMinus.getText();
txtScreen.setText("");
}
private void btnMultiplyActionPerformed(java.awt.event.ActionEvent evt) {
if ( txtScreen.getText().length()<=0 )
JOptionPane.showMessageDialog(null, "Screen Empty", "Error",JOptionPane.INFORMATION_MESSAGE);
else
exp1=txtScreen.getText();
operand=btnMultiply.getText();
txtScreen.setText("");
}
private void btnDivideActionPerformed(java.awt.event.ActionEvent evt) {
if ( txtScreen.getText().length()<=0 )
JOptionPane.showMessageDialog(null, "Screen Empty", "Error",JOptionPane.INFORMATION_MESSAGE);
else
exp1=txtScreen.getText();
operand=btnDivide.getText();
txtScreen.setText("");
}
private void jButton17ActionPerformed(java.awt.event.ActionEvent evt) {
JOptionPane.showMessageDialog(null, "Still not process this button \n Contact at +92-301-7640931 \n mbit.dbms@gmail.com", "Information",JOptionPane.INFORMATION_MESSAGE);
}
private void jButton18ActionPerformed(java.awt.event.ActionEvent evt) {
JOptionPane.showMessageDialog(null, "Still not process this button \n Contact at +92-301-7640931 \n mbit.dbms@gmail.com", "Information",JOptionPane.INFORMATION_MESSAGE);
}
private void jButton19ActionPerformed(java.awt.event.ActionEvent evt) {
JOptionPane.showMessageDialog(null, "Still not process this button \n Contact at +92-301-7640931 \n mbit.dbms@gmail.com", "Information",JOptionPane.INFORMATION_MESSAGE);
}
private void btnEqualActionPerformed(java.awt.event.ActionEvent evt) {
try{
if ( txtScreen.getText().length()<=0 ) {
JOptionPane.showMessageDialog(null, "Screen Empty", "Error",JOptionPane.WARNING_MESSAGE);
}
else
{
exp2=txtScreen.getText();
//Start the Process according to the Operator,
double n=(double) Double.parseDouble(exp1);
double m=(double) Double.parseDouble(exp2);
char op=operand.charAt(0);
switch(op){
case '/':
txtScreen.setText(Double.toString(n/m));
break;
case 'x':
txtScreen.setText(Double.toString(n*m));
break;
case '+':
txtScreen.setText(Double.toString(n+m));
break;
case '-':
txtScreen.setText(Double.toString(n-m));
break;
}// end of switch
}// End of else
}catch(HeadlessException | NumberFormatException e){
txtScreen.setText("Syntax Error");
}// End of try catch block
}
private void formWindowOpened(java.awt.event.WindowEvent evt) {
txtScreen.setHorizontalAlignment(JTextField.RIGHT);
txtScreen.setText("");
txtScreen.enableInputMethods(false);
setLocationRelativeTo(null);
}
private void btnOnOffActionPerformed(java.awt.event.ActionEvent evt) {
JOptionPane.showMessageDialog(null, "Still not process this button \n Contact at +92-301-7640931 \n mbit.dbms@gmail.com", "Information",JOptionPane.INFORMATION_MESSAGE);
}
private void btnClearActionPerformed(java.awt.event.ActionEvent evt) {
txtScreen.setText("");
}
private void btnBkSpaceActionPerformed(java.awt.event.ActionEvent evt) {
if ( txtScreen.getText().length()<=0 ) {
JOptionPane.showMessageDialog(null, "Screen Empty", "Error",JOptionPane.WARNING_MESSAGE);
}
else {
txtScreen.setText(txtScreen.getText().substring(0, txtScreen.getText().length()-1));
}
}
private void btn1ActionPerformed(java.awt.event.ActionEvent evt) {
txtScreen.setText(txtScreen.getText()+btn1.getText());
}
private void btn2ActionPerformed(java.awt.event.ActionEvent evt) {
txtScreen.setText(txtScreen.getText() + btn2.getText());
}
private void btn3ActionPerformed(java.awt.event.ActionEvent evt) {
txtScreen.setText(txtScreen.getText()+btn3.getText());
}
private void btn4ActionPerformed(java.awt.event.ActionEvent evt) {
txtScreen.setText(txtScreen.getText()+btn4.getText());
}
private void btn5ActionPerformed(java.awt.event.ActionEvent evt) {
txtScreen.setText(txtScreen.getText()+btn5.getText());
}
private void btn6ActionPerformed(java.awt.event.ActionEvent evt) {
txtScreen.setText(txtScreen.getText()+btn6.getText());
}
private void btn7ActionPerformed(java.awt.event.ActionEvent evt) {
txtScreen.setText(txtScreen.getText()+btn7.getText());
}
private void btn8ActionPerformed(java.awt.event.ActionEvent evt) {
txtScreen.setText(txtScreen.getText()+btn8.getText());
}
private void btn9ActionPerformed(java.awt.event.ActionEvent evt) {
txtScreen.setText(txtScreen.getText()+btn9.getText());
}
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
@Override
public void run() {
new Calc().setVisible(true);
}
});
}
// Variables declaration - do not modify
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;
private javax.swing.JButton btn7;
private javax.swing.JButton btn8;
private javax.swing.JButton btn9;
private javax.swing.JButton btnBkSpace;
private javax.swing.JButton btnClear;
private javax.swing.JButton btnDivide;
private javax.swing.JButton btnDot;
private javax.swing.JButton btnEqual;
private javax.swing.JButton btnMinus;
private javax.swing.JButton btnMultiply;
private javax.swing.JButton btnOnOff;
private javax.swing.JButton btnPlus;
private javax.swing.JButton jButton11;
private javax.swing.JButton jButton17;
private javax.swing.JButton jButton18;
private javax.swing.JButton jButton19;
private javax.swing.JTextField txtScreen;
// End of variables declaration
}
No comments:
Post a Comment