NotesWhat is notes.io?

Notes brand slogan

Notes - notes.io

package Calculator;

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

public class Calculator extends JFrame {

private static JButton sum;
private static JButton sub;
private static JButton mul;
private static JButton div;

private static Container c;
private static JTextArea text;
private static JButton[] arrayBtn;
private static JButton equ;
private static double buffer1 ;
private static double buffer2 ;
private static String operation = "";
private static boolean is = false;

public Calculator() {

setSize(500, 500);
c = getContentPane();
c.setLayout(new GridLayout(5, 3, 10, 10));

text = new JTextArea();
text.setText("Result");
text.setFont(new Font("Arial", Font.PLAIN, 20));
text.setEditable(false);
c.add(text);

sum = new JButton("+");
sum.setFont(new Font("Arial", Font.PLAIN, 40));

sum.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent ae) {

operation = "+";
is = true;
buffer1=buffer1*100;
}
});
c.add(sum);

sub = new JButton("-");
sub.setFont(new Font("Arial", Font.PLAIN, 40));

sub.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent ae) {

operation = "-";
is = true;
buffer1=buffer1*100;

}
});
c.add(sub);

mul = new JButton("*");
mul.setFont(new Font("Arial", Font.PLAIN, 40));
mul.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent ae) {

operation = "*";
is = true;
buffer1=buffer1*100;

}
});
c.add(mul);

div = new JButton("/");
div.setFont(new Font("Arial", Font.PLAIN, 40));
div.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent ae) {

operation = "/";
is = true;
buffer1=buffer1*100;

}
});
c.add(div);

equ = new JButton("=");
equ.addActionListener(new ActionListener() {

public void actionPerformed(ActionEvent ae) {

buffer2=buffer2*100;


if (operation == "+") {
text.setText(buffer1 + "+" + buffer2 + "=" + (buffer1 + buffer2));
} else if (operation == "-") {
text.setText("" + (buffer1 - buffer2));
}
if (operation == "*") {
text.setText("" + (buffer1 * buffer2));
}
if (operation == "/") {
text.setText("" + (buffer1 / buffer2));
}

buffer1 = 0;
buffer2 = 0;
operation = "";
is = false;

}
});
c.add(equ);
equ.setFont(new Font("Arial", Font.PLAIN, 40));

arrayBtn = new JButton[10];

for (int i = 0; i < arrayBtn.length - 1; i++) {
arrayBtn[i] = new JButton("" + (i + 1));
arrayBtn[i].setFont(new Font("Arial", Font.PLAIN, 40));
arrayBtn[i].addActionListener(new ActionListener() {

public void actionPerformed(ActionEvent ae) {

for (int x = 0; x < arrayBtn.length; x++) {
if (arrayBtn[x] == ae.getSource()) {

/*
if (!is) { buffer1 = Double.parseDouble(""+buffer1+(x + 1));
*/

if (!is) {
String s = String.valueOf(buffer1) + String.valueOf((x + 1));
System.out.println(s);
buffer1 = Double.parseDouble(s);
} else if (is) {

String s2 = String.valueOf(buffer2) + String.valueOf((x + 1));
System.out.println(s2);
buffer2 = Double.parseDouble(s2);

}
}

}

}
});
c.add(arrayBtn[i]);

}

}

public static void main(String[] args) {

Calculator frame = new Calculator();
frame.setVisible(true);
frame.setDefaultCloseOperation(EXIT_ON_CLOSE);

}

}
     
 
what is notes.io
 

Notes.io is a web-based application for taking notes. You can take your notes and share with others people. If you like taking long notes, notes.io is designed for you. To date, over 8,000,000,000 notes created and continuing...

With notes.io;

  • * You can take a note from anywhere and any device with internet connection.
  • * You can share the notes in social platforms (YouTube, Facebook, Twitter, instagram etc.).
  • * You can quickly share your contents without website, blog and e-mail.
  • * You don't need to create any Account to share a note. As you wish you can use quick, easy and best shortened notes with sms, websites, e-mail, or messaging services (WhatsApp, iMessage, Telegram, Signal).
  • * Notes.io has fabulous infrastructure design for a short link and allows you to share the note as an easy and understandable link.

Fast: Notes.io is built for speed and performance. You can take a notes quickly and browse your archive.

Easy: Notes.io doesn’t require installation. Just write and share note!

Short: Notes.io’s url just 8 character. You’ll get shorten link of your note when you want to share. (Ex: notes.io/q )

Free: Notes.io works for 12 years and has been free since the day it was started.


You immediately create your first note and start sharing with the ones you wish. If you want to contact us, you can use the following communication channels;


Email: [email protected]

Twitter: http://twitter.com/notesio

Instagram: http://instagram.com/notes.io

Facebook: http://facebook.com/notesio



Regards;
Notes.io Team

     
 
Shortened Note Link
 
 
Looding Image
 
     
 
Long File
 
 

For written notes was greater than 18KB Unable to shorten.

To be smaller than 18KB, please organize your notes, or sign in.