Java calculator app 🖩

preview_player
Показать описание
Java simple calculator program w/ GUI

#Java #calculator #app

(NOT A COMPLETE CALCULATOR)
Рекомендации по теме
Комментарии
Автор

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

public class Calculator implements ActionListener{

JFrame frame;
JTextField textfield;
JButton[] numberButtons = new JButton[10];
JButton[] functionButtons = new JButton[9];
JButton addButton, subButton, mulButton, divButton;
JButton decButton, equButton, delButton, clrButton, negButton;
JPanel panel;

Font myFont = new Font("Ink Free", Font.BOLD, 30);

double num1=0, num2=0, result=0;
char operator;

Calculator(){

frame = new JFrame("Calculator");

frame.setSize(420, 550);
frame.setLayout(null);

textfield = new JTextField();
textfield.setBounds(50, 25, 300, 50);
textfield.setFont(myFont);


addButton = new JButton("+");
subButton = new JButton("-");
mulButton = new JButton("*");
divButton = new JButton("/");
decButton = new JButton(".");
equButton = new JButton("=");
delButton = new JButton("Del");
clrButton = new JButton("Clr");
negButton = new JButton("(-)");

functionButtons[0] = addButton;
functionButtons[1] = subButton;
functionButtons[2] = mulButton;
functionButtons[3] = divButton;
functionButtons[4] = decButton;
functionButtons[5] = equButton;
functionButtons[6] = delButton;
functionButtons[7] = clrButton;
functionButtons[8] = negButton;

for(int i =0;i<9;i++) {



}

for(int i =0;i<10;i++) {
numberButtons[i] = new JButton(String.valueOf(i));



}

negButton.setBounds(50, 430, 100, 50);
delButton.setBounds(150, 430, 100, 50);
clrButton.setBounds(250, 430, 100, 50);

panel = new JPanel();
panel.setBounds(50, 100, 300, 300);
panel.setLayout(new GridLayout(4, 4, 10, 10));




panel.add(addButton);



panel.add(subButton);



panel.add(mulButton);
panel.add(decButton);

panel.add(equButton);
panel.add(divButton);

frame.add(panel);
frame.add(negButton);
frame.add(delButton);
frame.add(clrButton);
frame.add(textfield);
frame.setVisible(true);
}

public static void main(String[] args) {

Calculator calc = new Calculator();
}

@Override
public void actionPerformed(ActionEvent e) {

for(int i=0;i<10;i++) {
if(e.getSource() == numberButtons[i]) {

}
}
{

}
{
num1 =
operator ='+';
textfield.setText("");
}
{
num1 =
operator ='-';
textfield.setText("");
}
{
num1 =
operator ='*';
textfield.setText("");
}
{
num1 =
operator ='/';
textfield.setText("");
}
{


switch(operator) {
case'+':
result=num1+num2;
break;
case'-':
result=num1-num2;
break;
case'*':
result=num1*num2;
break;
case'/':
result=num1/num2;
break;
}

num1=result;
}
{
textfield.setText("");
}
{
String string = textfield.getText();
textfield.setText("");
for(int i=0;i<string.length()-1;i++) {

}
}
{
double temp =
temp*=-1;

}
}
}

BroCodez
Автор

People are missing out on your amazing content. I am still learning Java, and your content helps a lot.

deepeshsingh
Автор

Most impressive. Very lucid coding. Congrats on teaching me a little more than I knew!

StefaanMeeuws
Автор

Came here straight after the 12 hour java tutorial. You are Awesome Bro. Keep 'em coming :)

ashkaneghbali
Автор

This tutorial was very good and even gave the challenge of fixing the Delete and Clear font size while keeping the rest of the numbers and functions font the same size

EbbieMonch
Автор

Started practice with GUI's and this helped a lot!

milesmiller
Автор

This channel is so underrated
I went through many tuto on youtube, but none of them was that good(sincerely), and this is in regards to any programming language
This developer is Gold

Sorjen
Автор

I just start learning java a month ago and a little bit confuse what to do, and i found your channel, its really help me to practice

rasisulhubbi
Автор

Thank you @BroCode ☺
It was really up to the point !

ChinmayaHelchel
Автор

Extremely helpful. Got my mini project done within 30 minutes referring your source code and guide. Thankkksss a lotttt ☺👏

zul_afluz
Автор

Thank you, Bro! My prayers to the algorithm.

alessandroformica
Автор

Thanks Bro I've learned something new today about Java especially that GUI.

karllouiserito
Автор

Amazing content as always man, thank you!

bellabrink
Автор

I just begun with Java and made my own calculator like this. But after finishing and seeing this video, there is a lot of things I could do to definetly reduce my code size.

BigBadBicycle
Автор

bro this was really awesome ....
my sir told it but it was too confusing
but your program was clean and neat....
thank you so much .

mansinaidu
Автор

Bro code, this is an amazing tutorial.Thank you Mann, you taught me alot here.

motivation.
Автор

yo bro, love it
thanks
keep up the good work

gyangaha
Автор

Thanks Bro !!
These tutorials are nice and quick to run through and show beginners like me how certain code works in a real app.
I find this more valuable than just a lesson on certain things like arrays.

I have noticed a slow down on the java vids, any chance of any new quick app tutorial vids?

FukSN
Автор

Thanks man. Believe it or not Ive been learning Java for years and until now Ive never actually wrote a fully functional calculator.

westonpeabody
Автор

You always perfect sir because your way of teaching is all the time perfect. Thank you so much sir.🥰

parkashkumar