Scientific calcu

using other functions

Page 1 of 1

10 Replies - 978 Views - Last Post: 21 September 2009 - 02:36 AM Rate Topic: -----

#1 angel0lz  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 23
  • Joined: 19-July 08

Scientific calcu

Post icon  Posted 20 September 2009 - 06:27 AM

[code]/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/

/*
* ToMaRoCalc.java
*
* Created on Sep 19, 2009, 5:14:07 PM
*/

/**
*
* @author ronah
*/
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class ToMaRoCalc extends javax.swing.JFrame {

private double dataInput=0, dataInput2=0, result=0, changeOperation=0, memoryStorage=0, answer=0, number[], res;
private boolean pointy = true, operationPerformed = false, state = true;
private char operation = ' ';
private String buffer= "", buffer1="";


/** Creates new form ToMaRoCalc */
public ToMaRoCalc() {
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.
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {

jPanel1 = new javax.swing.JPanel();
hexaMode = new javax.swing.JRadioButton();
octMode = new javax.swing.JRadioButton();
decMode = new javax.swing.JRadioButton();
binMode = new javax.swing.JRadioButton();
posNeg = new javax.swing.JButton();
xSquared = new javax.swing.JButton();
xCubed = new javax.swing.JButton();
power = new javax.swing.JButton();
squareRoot = new javax.swing.JButton();
xRoot = new javax.swing.JButton();
memory = new javax.swing.JButton();
sin = new javax.swing.JButton();
cos = new javax.swing.JButton();
tan = new javax.swing.JButton();
log = new javax.swing.JButton();
ln = new javax.swing.JButton();
openPar = new javax.swing.JButton();
closePar = new javax.swing.JButton();
seven = new javax.swing.JButton();
four = new javax.swing.JButton();
eight = new javax.swing.JButton();
nine = new javax.swing.JButton();
del = new javax.swing.JButton();
clear = new javax.swing.JButton();
divide = new javax.swing.JButton();
times = new javax.swing.JButton();
five = new javax.swing.JButton();
six = new javax.swing.JButton();
two = new javax.swing.JButton();
three = new javax.swing.JButton();
one = new javax.swing.JButton();
zero = new javax.swing.JButton();
point = new javax.swing.JButton();
exp = new javax.swing.JButton();
plus = new javax.swing.JButton();
ans = new javax.swing.JButton();
minus = new javax.swing.JButton();
equals = new javax.swing.JButton();
cToK = new javax.swing.JButton();
kToC = new javax.swing.JButton();
toRoman = new javax.swing.JButton();
arrowUp = new javax.swing.JButton();
help = new javax.swing.JButton();
arrowLeft = new javax.swing.JButton();
arrowRight = new javax.swing.JButton();
arrowDown = new javax.swing.JButton();
jLayeredPane1 = new javax.swing.JLayeredPane();
input = new javax.swing.JTextField();
output = new javax.swing.JTextField();
off = new javax.swing.JToggleButton();

setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

jPanel1.setBackground(new java.awt.Color(0, 153, 153));
jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "ToMaRoCalc", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 0, 11), new java.awt.Color(255, 255, 51))); // NOI18N

hexaMode.setText("HEX");

octMode.setText("OCT");
octMode.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
octModeActionPerformed(evt);
}
});

decMode.setText("DEC");

binMode.setText("BIN");
binMode.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
binModeActionPerformed(evt);
}
});

posNeg.setFont(new java.awt.Font("Tahoma", 0, 16)); // NOI18N
posNeg.setText("");
posNeg.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
posNegActionPerformed(evt);
}
});

xSquared.setIcon(new javax.swing.ImageIcon(getClass().getResource("/newpackage/xsquared.JPG"))); // NOI18N
xSquared.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
xSquared.setMargin(new java.awt.Insets(2, 2, 2, 2));
xSquared.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
xSquaredActionPerformed(evt);
}
});

xCubed.setIcon(new javax.swing.ImageIcon(getClass().getResource("/newpackage/xcubed.JPG"))); // NOI18N

power.setText("^");
power.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
powerActionPerformed(evt);
}
});

squareRoot.setText("√");
squareRoot.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
squareRootActionPerformed(evt);
}
});

xRoot.setIcon(new javax.swing.ImageIcon(getClass().getResource("/newpackage/xroot.JPG"))); // NOI18N
xRoot.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
xRootActionPerformed(evt);
}
});

memory.setText("M+");
memory.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
memoryActionPerformed(evt);
}
});

sin.setText("sin");
sin.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
sinActionPerformed(evt);
}
});

cos.setText("cos");
cos.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
cosActionPerformed(evt);
}
});

tan.setText("tan");
tan.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
tanActionPerformed(evt);
}
});

log.setText("log");
log.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
logActionPerformed(evt);
}
});

ln.setText("ln");
ln.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
lnActionPerformed(evt);
}
});

openPar.setText("(");

closePar.setText(")");

seven.setFont(new java.awt.Font("Arial", 0, 14)); // NOI18N
seven.setText("7");
seven.setMargin(new java.awt.Insets(2, 2, 2, 2));
seven.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
sevenActionPerformed(evt);
}
});

four.setFont(new java.awt.Font("Arial", 0, 14)); // NOI18N
four.setText("4");
four.setMargin(new java.awt.Insets(2, 2, 2, 2));
four.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
fourActionPerformed(evt);
}
});

eight.setFont(new java.awt.Font("Arial", 0, 14)); // NOI18N
eight.setText("8");
eight.setMargin(new java.awt.Insets(2, 2, 2, 2));
eight.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
eightActionPerformed(evt);
}
});

nine.setFont(new java.awt.Font("Arial", 0, 14)); // NOI18N
nine.setText("9");
nine.setMargin(new java.awt.Insets(2, 2, 2, 2));
nine.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
nineActionPerformed(evt);
}
});
nine.addKeyListener(new java.awt.event.KeyAdapter() {
public void keyPressed(java.awt.event.KeyEvent evt) {
nineKeyPressed(evt);
}
});

del.setFont(new java.awt.Font("Arial", 0, 14)); // NOI18N
del.setText("DEL");
del.setMargin(new java.awt.Insets(2, 2, 2, 2));
del.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
delActionPerformed(evt);
}
});

clear.setFont(new java.awt.Font("Arial", 0, 14)); // NOI18N
clear.setText("AC");
clear.setMargin(new java.awt.Insets(2, 2, 2, 2));
clear.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
clearActionPerformed(evt);
}
});

divide.setFont(new java.awt.Font("Arial", 0, 14)); // NOI18N
divide.setText("");
divide.setMargin(new java.awt.Insets(2, 2, 2, 2));
divide.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
divideActionPerformed(evt);
}
});

times.setFont(new java.awt.Font("Arial", 0, 14)); // NOI18N
times.setText("x");
times.setMargin(new java.awt.Insets(2, 2, 2, 2));
times.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
timesActionPerformed(evt);
}
});

five.setFont(new java.awt.Font("Arial", 0, 14)); // NOI18N
five.setText("5");
five.setMargin(new java.awt.Insets(2, 2, 2, 2));
five.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
fiveActionPerformed(evt);
}
});

six.setFont(new java.awt.Font("Arial", 0, 14)); // NOI18N
six.setText("6");
six.setMargin(new java.awt.Insets(2, 2, 2, 2));
six.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
sixActionPerformed(evt);
}
});

two.setFont(new java.awt.Font("Arial", 0, 14)); // NOI18N
two.setText("2");
two.setMargin(new java.awt.Insets(2, 2, 2, 2));
two.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
twoActionPerformed(evt);
}
});

three.setFont(new java.awt.Font("Arial", 0, 14)); // NOI18N
three.setText("3");
three.setMargin(new java.awt.Insets(2, 2, 2, 2));
three.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
threeActionPerformed(evt);
}
});

one.setFont(new java.awt.Font("Arial", 0, 14)); // NOI18N
one.setText("1");
one.setMargin(new java.awt.Insets(2, 2, 2, 2));
one.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
oneActionPerformed(evt);
}
});

zero.setFont(new java.awt.Font("Arial", 0, 14)); // NOI18N
zero.setText("0");
zero.setMargin(new java.awt.Insets(2, 2, 2, 2));
zero.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
zeroActionPerformed(evt);
}
});

point.setFont(new java.awt.Font("Arial", 0, 14)); // NOI18N
point.setText(".");
point.setMargin(new java.awt.Insets(2, 2, 2, 2));
point.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
pointActionPerformed(evt);
}
});

exp.setFont(new java.awt.Font("Arial", 0, 14)); // NOI18N
exp.setText("EXP");
exp.setMargin(new java.awt.Insets(2, 2, 2, 2));

plus.setFont(new java.awt.Font("Arial", 0, 14)); // NOI18N
plus.setText("+");
plus.setMargin(new java.awt.Insets(2, 2, 2, 2));
plus.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
plusActionPerformed(evt);
}
});

ans.setFont(new java.awt.Font("Arial", 0, 14)); // NOI18N
ans.setText("Ans");
ans.setMargin(new java.awt.Insets(2, 2, 2, 2));
ans.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
ansActionPerformed(evt);
}
});

minus.setFont(new java.awt.Font("Arial", 0, 14)); // NOI18N
minus.setText("-");
minus.setMargin(new java.awt.Insets(2, 2, 2, 2));
minus.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
minusActionPerformed(evt);
}
});

equals.setFont(new java.awt.Font("Arial", 0, 14)); // NOI18N
equals.setText("=");
equals.setMargin(new java.awt.Insets(2, 2, 2, 2));
equals.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
equalsActionPerformed(evt);
}
});

cToK.setText("from C to K");
cToK.setMargin(new java.awt.Insets(2, 2, 2, 2));

kToC.setText("from K to C");
kToC.setMargin(new java.awt.Insets(2, 2, 2, 2));

toRoman.setText("to Roman");
toRoman.setMargin(new java.awt.Insets(2, 2, 2, 2));

arrowUp.setText("↑");
arrowUp.setMargin(new java.awt.Insets(2, 2, 2, 2));

help.setText("?");
help.setMargin(new java.awt.Insets(2, 2, 2, 2));

arrowLeft.setText("←");
arrowLeft.setMargin(new java.awt.Insets(2, 2, 2, 2));

arrowRight.setText("→");
arrowRight.setMargin(new java.awt.Insets(2, 2, 2, 2));

arrowDown.setText("↓");
arrowDown.setMargin(new java.awt.Insets(2, 2, 2, 2));

input.setBackground(new java.awt.Color(255, 255, 255));
input.setEditable(false);
input.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
input.setHorizontalAlignment(javax.swing.JTextField.LEFT);
input.setBorder(null);
input.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
inputActionPerformed(evt);
}
});
input.setBounds(0, 20, 520, 20);
jLayeredPane1.add(input, javax.swing.JLayeredPane.DEFAULT_LAYER);

output.setBackground(new java.awt.Color(255, 255, 255));
output.setEditable(false);
output.setFont(new java.awt.Font("Tahoma", 0, 24)); // NOI18N
output.setHorizontalAlignment(javax.swing.JTextField.RIGHT);
output.setText("0.");
output.setBorder(null);
output.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
outputActionPerformed(evt);
}
});
output.setBounds(0, 40, 520, 50);
jLayeredPane1.add(output, javax.swing.JLayeredPane.DEFAULT_LAYER);

off.setText("OFF");
off.setMargin(new java.awt.Insets(2, 2, 2, 2));
off.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
offActionPerformed(evt);
}
});

javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
jPanel1.setLayout(jPanel1Layout);
jPanel1Layout.setHorizontalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addContainerGap()
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addComponent(jLayeredPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 533, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap())
.addGroup(jPanel1Layout.createSequentialGroup()
.addComponent(off, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(posNeg, javax.swing.GroupLayout.PREFERRED_SIZE, 63, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(sin, javax.swing.GroupLayout.PREFERRED_SIZE, 63, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(binMode))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addComponent(cos, javax.swing.GroupLayout.PREFERRED_SIZE, 63, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(tan, javax.swing.GroupLayout.PREFERRED_SIZE, 63, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(log, javax.swing.GroupLayout.PREFERRED_SIZE, 63, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(ln, javax.swing.GroupLayout.PREFERRED_SIZE, 63, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(jPanel1Layout.createSequentialGroup()
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addComponent(xSquared, javax.swing.GroupLayout.PREFERRED_SIZE, 63, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(xCubed, javax.swing.GroupLayout.PREFERRED_SIZE, 63, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(power, javax.swing.GroupLayout.PREFERRED_SIZE, 63, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(jPanel1Layout.createSequentialGroup()
.addComponent(decMode)
.addGap(18, 18, 18)
.addComponent(hexaMode)
.addGap(18, 18, 18)
.addComponent(octMode)))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(squareRoot, javax.swing.GroupLayout.PREFERRED_SIZE, 63, javax.swing.GroupLayout.PREFERRED_SIZE))))
.addGroup(jPanel1Layout.createSequentialGroup()
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
.addComponent(zero, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(four, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(one, javax.swing.GroupLayout.DEFAULT_SIZE, 44, Short.MAX_VALUE)
.addComponent(seven, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.PREFERRED_SIZE, 54, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addComponent(point, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(two, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(five, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(eight, javax.swing.GroupLayout.PREFERRED_SIZE, 55, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addComponent(exp, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(three, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(six, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(nine, javax.swing.GroupLayout.DEFAULT_SIZE, 57, Short.MAX_VALUE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addComponent(ans, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(plus, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(times, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(del, javax.swing.GroupLayout.DEFAULT_SIZE, 52, Short.MAX_VALUE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addComponent(equals, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(minus, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(divide, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(clear, javax.swing.GroupLayout.DEFAULT_SIZE, 55, Short.MAX_VALUE))
.addGap(18, 18, 18)
.addComponent(arrowLeft, javax.swing.GroupLayout.PREFERRED_SIZE, 26, javax.swing.GroupLayout.PREFERRED_SIZE)))
.addGap(7, 7, 7)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(arrowDown, javax.swing.GroupLayout.PREFERRED_SIZE, 41, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(help, javax.swing.GroupLayout.PREFERRED_SIZE, 43, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(arrowUp, javax.swing.GroupLayout.PREFERRED_SIZE, 40, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGa

Is This A Good Question/Topic? 0
  • +

Replies To: Scientific calcu

#2 mostyfriedman  Icon User is offline

  • The Algorithmi
  • member icon

Reputation: 727
  • View blog
  • Posts: 4,473
  • Joined: 24-October 08

Re: Scientific calcu

Posted 20 September 2009 - 06:30 AM

what's your question?
Was This Post Helpful? 0
  • +
  • -

#3 Crunch  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 139
  • View blog
  • Posts: 1,222
  • Joined: 28-July 09

Re: Scientific calcu

Posted 20 September 2009 - 06:38 AM

Explain Whats wrong with your code.
Was This Post Helpful? 0
  • +
  • -

#4 angel0lz  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 23
  • Joined: 19-July 08

Re: Scientific calcu

Posted 20 September 2009 - 06:40 AM

i dont know how to add the functions for sine cosine and tangent.. here's my code for the basic functions like addition, multiplication,etc..

private class NumberButtonHandler implements ActionListener
	{	

			public void actionPerformed(ActionEvent e)
			{		
				String buffer="";
				for(int i = 0; i<4; i++)
					b1[i].setEnabled(true);
				System.out.println("" + e.getActionCommand());
				if(e.getActionCommand().equals("1"))
				{
					buffer = tf1.getText();
					tf1.setText(buffer + "1");
					
				}
				else if(e.getActionCommand().equals("2"))
				{
					buffer = tf1.getText();
					tf1.setText(buffer + "2");
				}
				else if(e.getActionCommand().equals("3"))
				{
					buffer = tf1.getText();
					tf1.setText(buffer + "3");
				}
				else if(e.getActionCommand().equals("4"))
				{
					buffer = tf1.getText();
					tf1.setText(buffer + "4");
				}
				else if(e.getActionCommand().equals("5"))
				{
					buffer = tf1.getText();
					tf1.setText(buffer + "5");
				}
				else if(e.getActionCommand().equals("6"))
				{
					buffer = tf1.getText();
					tf1.setText(buffer + "6");
				}
				else if(e.getActionCommand().equals("7"))
				{
					buffer = tf1.getText();
					tf1.setText(buffer + "7");
				}
				else if(e.getActionCommand().equals("8"))
				{
					buffer = tf1.getText();
					tf1.setText(buffer + "8");
				}
				else if(e.getActionCommand().equals("9"))
				{
					buffer = tf1.getText();
					tf1.setText(buffer + "9");
				}
				else if(e.getActionCommand().equals("0"))
				{
					buffer = tf1.getText();
					tf1.setText(buffer + "0");
				}
				else if(e.getActionCommand().equals("."))
				{
						buffer = tf1.getText();
						tf1.setText(buffer + ".");
						b[10].setEnabled(false);
				}

			}
	}
	private class OperationButtonHandler implements ActionListener
	{
		public void actionPerformed(ActionEvent e)
		{
			String buffer = "", buffer1 = "";
			double number[], res;
			
			for(int i = 0; i<11; i++ )
						b[i].setEnabled(true);	
			System.out.println("" + e.getActionCommand());
			if(e.getActionCommand().equals("+"))
			{	buffer = tf1.getText();
				if(buffer.equals(""))
				{	JOptionPane.showMessageDialog(null, "can't do that!");
				}
				else
				{	for(int i =0; i < 4; i++)
						b1[i].setEnabled(false);
					tf1.setText(buffer + "+");
				}			
			}
			else if(e.getActionCommand().equals("-"))
			{	buffer = tf1.getText();
				if(buffer.equals(""))
				{	JOptionPane.showMessageDialog(null, "can't do that!");
				}
				else
				{	for(int i =0; i < 4; i++)
						b1[i].setEnabled(false);
					tf1.setText(buffer + "-");
				}			
			}
			
			else if(e.getActionCommand().equals("*"))
			{	buffer = tf1.getText();
				if(buffer.equals(""))
				{	JOptionPane.showMessageDialog(null, "can't do that!");
				}
				else
				{	for(int i =0; i < 4; i++)
						b1[i].setEnabled(false);
					tf1.setText(buffer + "*");
				}			
			}
			
			else if(e.getActionCommand().equals("/"))
			{	buffer = tf1.getText();
				if(buffer.equals(""))
				{	JOptionPane.showMessageDialog(null, "can't do that!");
				}
				else
				{	for(int i =0; i < 4; i++)
						b1[i].setEnabled(false);
					tf1.setText(buffer + "/");
				}			
			}
			
			else if(e.getActionCommand().equals("exe"))
			{

				buffer = tf1.getText();
				if(!(buffer.equals("")))
				{	char c = buffer.charAt((buffer.length()-1));
					if( c == '+' || c == '-' || c == '/' || c == '*' )
					buffer = buffer.substring(0, (buffer.length()-1));
				
					int counter = 0;
					for(int i=0; i<buffer.length(); i++)
					{	c = buffer.charAt(i);
						if( c == '+' || c == '-' || c == '/' || c == '*' )
						{	counter++;
							buffer1 = buffer1 + c;
						
						}
					
					}
					number = new double[counter+1];
			
					int  mark1 = 0 , mark2, j=0;
					for(int i=0; i<buffer.length(); i++)
					{	c = buffer.charAt(i);
						if( c == '+' || c == '-' || c == '/' || c == '*' )
						{	mark2 = i;
							number[j] = Double.parseDouble(buffer.substring(mark1, mark2));
							mark1 = mark2+1;
							System.out.println(""+number[j]);
							j++;	
						}
					}
					number[j] = Double.parseDouble(buffer.substring(mark1, buffer.length()));
					System.out.println(""+number[j]);
					double forDisp = number[0];
					for(int i = 0; i< counter; i++)
					{	
						if(buffer1.charAt(i) == '+')
						{	forDisp += number[i+1];	
						}

						else if(buffer1.charAt(i) == '-')
						{	forDisp -= number[i+1];	
						}
						else if(buffer1.charAt(i) == '*')
						{ 	forDisp *= number[i+1];	
						}
						else if(buffer1.charAt(i) == '/')
						{	forDisp /= number[i+1];	
						}
					}
					tf1.setText("" + forDisp);
					for(int i = 0; i<11; i++ )
						b[i].setEnabled(false);

				}
							
							
			}
			
			else if(e.getActionCommand().equals("AC"))
			{	
					
					tf1.setText("");
					
					for(int i = 0; i<11; i++ )
						b[i].setEnabled(true);

					for(int i = 0; i<6; i++)
						b1[i].setEnabled(true);
							
			}
			
		}
	}
	


}

Was This Post Helpful? 0
  • +
  • -

#5 Crunch  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 139
  • View blog
  • Posts: 1,222
  • Joined: 28-July 09

Re: Scientific calcu

Posted 20 September 2009 - 06:58 AM

Use the java math class

http://java.sun.com/.../lang/Math.html
Was This Post Helpful? 0
  • +
  • -

#6 macosxnerd101  Icon User is offline

  • Self-Trained Economist
  • member icon




Reputation: 10486
  • View blog
  • Posts: 38,858
  • Joined: 27-December 08

Re: Scientific calcu

Posted 20 September 2009 - 08:44 AM

Snowflakes is right. There are already functions defined for sine, cosine, and tangent. They accept angle measures in radians, and you can use the toDegrees() method in the math class to feed the angle measures to the trig functions in degrees.
Was This Post Helpful? 0
  • +
  • -

#7 angel0lz  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 23
  • Joined: 19-July 08

Re: Scientific calcu

Posted 21 September 2009 - 12:00 AM

what i mean is that i do not know how to add the trigo functions im my algorithm... my calculator evaluates equations like for example:
20+cos36-5 = ?? and it gives out the desired output..

hmm another question, how do we use binary,octal and hexadecimals? are they also predefined in java? in what class?
Was This Post Helpful? 0
  • +
  • -

#8 AntonWebsters  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 88
  • View blog
  • Posts: 428
  • Joined: 15-August 09

Re: Scientific calcu

Posted 21 September 2009 - 01:38 AM

In order to convert the Integer into either binary, octal or hex...this is how you do it.
int i = 1111111111;
String iStr = Integer.toBinaryString(i); // Conversion to binary
iStr = Integer.toOctalString(i); //Conversion to octal
iStr = Integer.toHexString(i); //Conversion to hex



As of the equation you were talking about...wouldn't this algorithm work?
double output = 20 + Math.cos(36) - 5;


This post has been edited by AntonWebsters: 21 September 2009 - 01:39 AM

Was This Post Helpful? 0
  • +
  • -

#9 angel0lz  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 23
  • Joined: 19-July 08

Re: Scientific calcu

Posted 21 September 2009 - 01:50 AM

how do we convert decimal numbers to binary? like for example.. 353.34 to binary? can we use double or float?
Was This Post Helpful? 0
  • +
  • -

#10 AntonWebsters  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 88
  • View blog
  • Posts: 428
  • Joined: 15-August 09

Re: Scientific calcu

Posted 21 September 2009 - 02:24 AM

There is no toBinaryString() and toOctalString() method in Double class and Float class...so I guess you can only convert Integers to Binary and Octal.
Was This Post Helpful? 0
  • +
  • -

#11 LaFayette  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 43
  • View blog
  • Posts: 326
  • Joined: 24-November 08

Re: Scientific calcu

Posted 21 September 2009 - 02:36 AM

There's a floatToIntBits() and a doubleToLongBits() method for float and double. These return bit layouts according to the IEEE 754 standard (sign+exponent+mantissa)!

This post has been edited by LaFayette: 21 September 2009 - 02:36 AM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1