Naija Talk community
Would you like to react to this message? Create an account in a few clicks or log in to continue.
Naija Talk community

Ghana Lotto Results, F-t-a Satellite Technology, Sport forcast, ICT forum.
 
HomePublicationsSearchLatest imagesRegisterLog in

 

 How to programme a scientific calculator

Go down 
3 posters
AuthorMessage
John bull
Enthusiast
Enthusiast



Posts : 1864

How to programme a scientific calculator Empty
PostSubject: How to programme a scientific calculator   How to programme a scientific calculator Empty2011-02-13, 15:49

First of all download JDK, NETBEANS.
Back to top Go down
stay
Senior
Senior



Posts : 1196
Location : Earth

How to programme a scientific calculator Empty
PostSubject: Re: How to programme a scientific calculator   How to programme a scientific calculator Empty2011-02-13, 15:57

where can i download it and after dloading it wat next
Back to top Go down
http://www.great-star.webs.com
John bull
Enthusiast
Enthusiast



Posts : 1864

How to programme a scientific calculator Empty
PostSubject: Re: How to programme a scientific calculator   How to programme a scientific calculator Empty2011-02-13, 16:18

For JDK [You must be registered and logged in to see this link.]
Back to top Go down
John bull
Enthusiast
Enthusiast



Posts : 1864

How to programme a scientific calculator Empty
PostSubject: Re: How to programme a scientific calculator   How to programme a scientific calculator Empty2011-02-13, 16:20

For Netbeans [You must be registered and logged in to see this link.]
Back to top Go down
stay
Senior
Senior



Posts : 1196
Location : Earth

How to programme a scientific calculator Empty
PostSubject: Re: How to programme a scientific calculator   How to programme a scientific calculator Empty2011-02-13, 16:56

thanks
Back to top Go down
http://www.great-star.webs.com
abou1
Senior
Senior
abou1


Posts : 1277
Location : naija

How to programme a scientific calculator Empty
PostSubject: Re: How to programme a scientific calculator   How to programme a scientific calculator Empty2011-02-18, 12:46

what next oga jb?
Back to top Go down
http://alanengservices.webs.com
abou1
Senior
Senior
abou1


Posts : 1277
Location : naija

How to programme a scientific calculator Empty
PostSubject: Re: How to programme a scientific calculator   How to programme a scientific calculator Empty2011-02-18, 12:49

pls i need someone to teach me c++
Back to top Go down
http://alanengservices.webs.com
John bull
Enthusiast
Enthusiast



Posts : 1864

How to programme a scientific calculator Empty
PostSubject: Re: How to programme a scientific calculator   How to programme a scientific calculator Empty2011-02-18, 18:16

I only specialize in java.
Back to top Go down
John bull
Enthusiast
Enthusiast



Posts : 1864

How to programme a scientific calculator Empty
PostSubject: Re: How to programme a scientific calculator   How to programme a scientific calculator Empty2011-02-28, 15:12

package JavaProject2;

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class Calculator2 extends JFrame implements ActionListener {
CardLayout cl = new CardLayout();
JPanel paneOne = new JPanel();
JPanel paneTwo = new JPanel();

// Jmenu and items
JMenuBar m = new JMenuBar();
JMenu o = new JMenu("Options");
JMenu l = new JMenu("View");
JMenu h = new JMenu("Help");
JMenuItem jhelp = new JMenuItem("Help");
JMenuItem jclassic = new JMenuItem("Classic");
JMenuItem jmetal = new JMenuItem("Metal");
JMenuItem jbasic = new JMenuItem("Basic");
JMenuItem st = new JMenuItem("Standard");
JMenuItem sc = new JMenuItem("Scientific");

// JButtons for bothscientifc and standard calculators;
JButton b1 = new JButton("1");
JButton b01 = new JButton("1");
JButton b2 = new JButton("2");
JButton b02 = new JButton("2");
JButton b3 = new JButton("3");
JButton b03 = new JButton("3");
JButton b4 = new JButton("4");
JButton b04 = new JButton("4");
JButton b5 = new JButton("5");
JButton b05 = new JButton("5");
JButton b6 = new JButton("6");
JButton b06 = new JButton("6");
JButton b7 = new JButton("7");
JButton b07 = new JButton("7");
JButton b8 = new JButton("8");
JButton b08 = new JButton("8");
JButton b9 = new JButton("9");
JButton b09 = new JButton("9");
JButton b0 = new JButton("0");
JButton b00 = new JButton("0");
JButton b10 = new JButton("+");
JButton b010 = new JButton("+");
JButton b11 = new JButton("-");
JButton b011 = new JButton("-");
JButton b12 = new JButton("*");
JButton b012 = new JButton("*");
JButton b13 = new JButton("/");
JButton b013 = new JButton("/");
JButton b14 = new JButton("=");
JButton b014 = new JButton("=");
JButton b15 = new JButton("+/-");
JButton b015 = new JButton("+/-");
JButton b16 = new JButton(".");
JButton b016 = new JButton(".");
JButton b17 = new JButton("c");
JButton b017 = new JButton("c");
JButton b18 = new JButton("ce");
JButton b018 = new JButton("ce");
JButton b019 = new JButton("sin");
JButton b020 = new JButton("tan");
JButton b021 = new JButton("cos");

JLabel blank = new JLabel("");
JLabel blank1 = new JLabel("");
JLabel blank2 = new JLabel("");
JLabel blank3 = new JLabel("");

JTextField textBox = new JTextField("", 18);
JTextField textBox2 = new JTextField("", 18);

//VARIABLES FOR THE OPERATORS, VALUES AND THE TOTAL
char operator;
float total = 0;
float value1;
float value2;
double total2 = 0;

//Constructor
public Calculator2() {

super("CALCULATOR");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setSize(300, 300);

o.add(st);
o.add(sc);
l.add(jmetal);
l.add(jclassic);
l.add(jbasic);
h.add(jhelp);
m.add(o);
m.add(l);
m.add(h);
setJMenuBar(m);

//ADDING ACTION LISTENERS TO ALL THE BUTTONS
st.addActionListener(this);
sc.addActionListener(this);
jmetal.addActionListener(this);
jclassic.addActionListener(this);
jbasic.addActionListener(this);
jhelp.addActionListener(this);
//Standard Calculator!!!
b1.addActionListener(this);
b2.addActionListener(this);
b3.addActionListener(this);
b4.addActionListener(this);
b5.addActionListener(this);
b6.addActionListener(this);
b7.addActionListener(this);
b8.addActionListener(this);
b9.addActionListener(this);
b0.addActionListener(this);
b10.addActionListener(this);
b11.addActionListener(this);
b12.addActionListener(this);
b13.addActionListener(this);
b14.addActionListener(this);
b15.addActionListener(this);
b16.addActionListener(this);
b17.addActionListener(this);
b18.addActionListener(this);

//Scientific Calculator!!!!!
b01.addActionListener(this);
b02.addActionListener(this);
b03.addActionListener(this);
b04.addActionListener(this);
b05.addActionListener(this);
b06.addActionListener(this);
b07.addActionListener(this);
b08.addActionListener(this);
b09.addActionListener(this);
b00.addActionListener(this);
b010.addActionListener(this);
b011.addActionListener(this);
b012.addActionListener(this);
b013.addActionListener(this);
b014.addActionListener(this);
b015.addActionListener(this);
b016.addActionListener(this);
b017.addActionListener(this);
b018.addActionListener(this);
b019.addActionListener(this);
b020.addActionListener(this);
b021.addActionListener(this);

//For standard
//ADD TOP PANEL
JPanel textPane = new JPanel();
BorderLayout border = new BorderLayout();
textPane.add(textBox, BorderLayout.NORTH);
paneOne.add(textPane);
//ADD BOTTOM PANEL
JPanel bottom = new JPanel();
GridLayout grid = new GridLayout(5, 4);
bottom.setLayout(grid);
bottom.add(b7);
bottom.add(b8);
bottom.add(b9);
bottom.add(b13);
bottom.add(b4);
bottom.add(b5);
bottom.add(b6);
bottom.add(b12);
bottom.add(b1);
bottom.add(b2);
bottom.add(b3);
bottom.add(b11);
bottom.add(b0);
bottom.add(b15);
bottom.add(b16);
bottom.add(b10);
bottom.add(b17);
bottom.add(b18);
bottom.add(blank);
bottom.add(b14);
paneOne.add(bottom);


//For scientific
//ADD TOP PANEL(textBox2.getText())
JPanel textPane2 = new JPanel();
BorderLayout border2 = new BorderLayout();
textPane2.add(textBox2, BorderLayout.NORTH);
paneTwo.add(textPane2);
//ADD BOTTOM PANEL

JPanel bottom2 = new JPanel();
bottom2.setLayout(grid);
bottom2.add(b07);
bottom2.add(b08);
bottom2.add(b09);
bottom2.add(b013);bottom2.add(b019);
bottom2.add(b04);
bottom2.add(b05);
bottom2.add(b06);
bottom2.add(b012);bottom2.add(b020);
bottom2.add(b01);
bottom2.add(b02);
bottom2.add(b03);
bottom2.add(b011);bottom2.add(b021);
bottom2.add(b00);
bottom2.add(b015);
bottom2.add(b016);
bottom2.add(b010);
bottom2.add(blank2);
bottom2.add(b017);
bottom2.add(b018);
bottom2.add(blank);
bottom2.add(b014);



paneTwo.add(bottom2);
this.getContentPane().setLayout(cl);
this.getContentPane().add(paneOne, "One");
getContentPane().add(paneTwo, "Two");
//pack();
this.setVisible(true);

}


public void actionPerformed(ActionEvent evt) {
int leng2;
String tex;
String leng;
Object source = evt.getSource();

//look and feel action listener
if (source == jmetal) {
try {
UIManager.setLookAndFeel(
"javax.swing.plaf.metal.MetalLookAndFeel");
SwingUtilities.updateComponentTreeUI(this);
} catch (Exception e) { }
}

//look and feel action listener
if (source == jbasic) {
try {
UIManager.setLookAndFeel(
"javax.swing.plaf.basic.BasicLookAndFeel");
SwingUtilities.updateComponentTreeUI(this);
} catch (Exception e) { }
}

//look and feel action listener
if (source == jclassic) {
try {
UIManager.setLookAndFeel(
UIManager.getSystemLookAndFeelClassName());
SwingUtilities.updateComponentTreeUI(this);
} catch (Exception e) { }
}

if (source == st) {
cl.show(getContentPane(), "One");
} else if (source == sc) {
cl.show(getContentPane(), "Two");
}

//Help menu action Listener
if (source == jhelp) {
JOptionPane.showMessageDialog(null,"Calculator: this program functions like any other calculator simply click on the various buttons to get the result you want, you can also change the look and feel of the calculator by choosing one from the view menu. This calculator has two modes scientific and standard these can be chosen from the otions menu.");
}

//Standard Calculator!!!!!!!!!!!!!
//Action for when the numeric buttons are pressed
if (source == b1) {
textBox.setText(textBox.getText() + "1");
} else if (source == b2) {
textBox.setText(textBox.getText() + "2");
} else if (source == b3) {
textBox.setText(textBox.getText() + "3");
} else if (source == b4) {
textBox.setText(textBox.getText() + "4");
} else if (source == b5) {
textBox.setText(textBox.getText() + "5");
} else if (source == b6) {
textBox.setText(textBox.getText() + "6");
} else if (source == b7) {
textBox.setText(textBox.getText() + "7");
} else if (source == b8) {
textBox.setText(textBox.getText() + "8");
} else if (source == b9) {
textBox.setText(textBox.getText() + "9");
} else if (source == b0) {
textBox.setText(textBox.getText() + "0");
}


if (source == b15) {
textBox.setText("-" + textBox.getText());
}

if (source == b16) {
textBox.setText(textBox.getText() + ".");
}

// Action Listener for when c is pressed. Deletes the last char in the textBox
if (source == b17) {
tex = textBox.getText();
leng2 = (tex.length() - 1);
leng = tex.substring(0, leng2);
textBox.setText(leng);
}

// Action listeners for when the ce is pressed. Clears the entire textBox
if (source == b18) {
textBox.setText("");
}



// Action listener for when the + sign is pressed
if (source == b10) {
value1 = Float.parseFloat(textBox.getText());
textBox.setText("");
operator = '+';
}

// Action listener for when the - sign is pressed
if (source == b11) {
value1 = Float.parseFloat(textBox.getText());
textBox.setText("");
operator = '-';
}

// Action listener for when the * sign is pressed
if (source == b12) {
value1 = Float.parseFloat(textBox.getText());
textBox.setText("");
operator = '*';
}

// Action listener for when the / sign is pressed
if (source == b13) {
value1 = Float.parseFloat(textBox.getText());
textBox.setText("");
operator = '/';
}

// Action listener for the equals sign
if (source == b14) {
value2 = Float.parseFloat(textBox.getText());
if (operator == '+') {
total = value1 + value2;
} else if (operator == '-') {
total = value1 - value2;
} else if (operator == '*') {
total = value1 * value2;
} else if (operator == '/') {
// warning message when a number is divided by zero
if (value2 == 0) {
Object[] options = { "OK", "CANCEL" };
JOptionPane.showOptionDialog(null, "Click OK to continue", "Warning",
JOptionPane.DEFAULT_OPTION, JOptionPane.WARNING_MESSAGE,
null, options, options[0]);
textBox.setText("error");
} else if (value2 != 0) {
total = value1 / value2;
textBox.setText("" + total);
}
}

textBox.setText("" + total);
}

//Scientific Calculator!!!!!!!!!!!!!!
//Action for when the numeric buttons are pressed
if (source == b01) {
textBox2.setText(textBox2.getText() + "1");
} else if (source == b02) {
textBox2.setText(textBox2.getText() + "2");
} else if (source == b03) {
textBox2.setText(textBox2.getText() + "3");
} else if (source == b04) {
textBox2.setText(textBox2.getText() + "4");
} else if (source == b05) {
textBox2.setText(textBox2.getText() + "5");
} else if (source == b06) {
textBox2.setText(textBox2.getText() + "6");
} else if (source == b07) {
textBox2.setText(textBox2.getText() + "7");
} else if (source == b08) {
textBox2.setText(textBox2.getText() + "8");
} else if (source == b09) {
textBox2.setText(textBox2.getText() + "9");
} else if (source == b00) {
textBox2.setText(textBox2.getText() + "0");
}


if (source == b015) {
textBox2.setText("-" + textBox2.getText());
}

if (source == b016) {
textBox2.setText(textBox2.getText() + ".");
}

// Action Listener for when c is pressed. Deletes the last char in the textBox2
if (source == b017) {
tex = textBox2.getText();
leng2 = (tex.length() - 1);
leng = tex.substring(0, leng2);
textBox2.setText(leng);
}

// Action listeners for when the ce is pressed. Clears the entire textBox2
if (source == b018) {
textBox2.setText("");
}



// Action listener for when the + sign is pressed
if (source == b010) {
value1 = Float.parseFloat(textBox2.getText());
textBox2.setText("");
operator = '+';
}

// Action listener for when the - sign is pressed
if (source == b011) {
value1 = Float.parseFloat(textBox2.getText());
textBox2.setText("");
operator = '-';
}

// Action listener for when the * sign is pressed
if (source == b012) {
value1 = Float.parseFloat(textBox2.getText());
textBox2.setText("");
operator = '*';
}

// Action listener for when the / sign is pressed
if (source == b013) {
value1 = Float.parseFloat(textBox2.getText());
textBox2.setText("");
operator = '/';
}

// Action listener for when SIN is pressed
if (source == b019) {
value1 = Float.parseFloat(textBox2.getText());
textBox2.setText("");
operator = 's';
}

// Action listener for when TAN is pressed
if (source == b020) {
value1 = Float.parseFloat(textBox2.getText());
textBox2.setText("");
operator = 't';
}

// Action listener for when COS is pressed
if (source == b021) {
value1 = Float.parseFloat(textBox2.getText());
textBox2.setText("");
operator = 'c';
}

// Action listener for the equals sign
if (source == b014) {
//value2 = Float.parseFloat(textBox2.getText());
if (operator == '+') {
value2 = Float.parseFloat(textBox2.getText());
total = value1 + value2;
textBox2.setText("" + total);
} else if (operator == '-') {
value2 = Float.parseFloat(textBox2.getText());
total = value1 - value2;
textBox2.setText("" + total);
} else if (operator == '*') {
value2 = Float.parseFloat(textBox2.getText());
total = value1 * value2;
textBox2.setText("" + total);
} else if (operator == '/') {
value2 = Float.parseFloat(textBox2.getText());
// warning message when a number is divided by zero
if (value2 == 0) {
Object[] options = { "OK", "CANCEL" };
JOptionPane.showOptionDialog(null, "Click OK to continue", "Warning",
JOptionPane.DEFAULT_OPTION, JOptionPane.WARNING_MESSAGE,
null, options, options[0]);
textBox2.setText("error");
} else if (value2 != 0){
total = value1 / value2;
textBox2.setText("" + total);
}
} else if (operator == 's') {
total2 = Math.sin(value1);
textBox2.setText("" + total2);
} else if (operator == 't') {
total2 = Math.tan(value1);
textBox2.setText("" + total2);
} else if (operator == 'c') {
total2 = Math.cos(value1);
textBox2.setText("" + total2);
}

}
repaint();

}


//MAIN METHOD
public static void main(String[] arguments) {
Calculator2 frame = new Calculator2();
}
}
Back to top Go down
Sponsored content





How to programme a scientific calculator Empty
PostSubject: Re: How to programme a scientific calculator   How to programme a scientific calculator Empty

Back to top Go down
 
How to programme a scientific calculator
Back to top 
Page 1 of 1
 Similar topics
-
» Re: Study Abroad Programme in Technology Related Programme ( Scholarship)
» Satellite Dish Look Angle Heading Calculator
» UNECE Internship Programme
» Increase Your Earnings With the best Investment programme
» Google Business Internship Programme 2015

Permissions in this forum:You cannot reply to topics in this forum
Naija Talk community :: TECHNOLOGY :: Computer-
Jump to: