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.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setSize(420, 550); frame.setLayout(null); textfield = new JTextField(); textfield.setBounds(50, 25, 300, 50); textfield.setFont(myFont); textfield.setEditable(false); 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
@vickysanth96534 жыл бұрын
it would be more easy to understad for beginners like me if you go slower than usual.. because i don't understand many terms like "ActionListener", interfaces etc.. it's like new to me since I'm a beginner..
@sidra32104 жыл бұрын
Nice👍🔥
@shokirovollohberdi4 жыл бұрын
@@komaltandle465 LOL
@agent47hitman753 жыл бұрын
@NOA777 the method Double.parseDouble() casts a value to a double type value. the getText() method is used to get the text from the text field. So Double.parseDouble(txtfield.getText()) is actually casting the string values to a double type value of whatever is written in the rext field as we can't perform calculation with string type of values.
@medjl60833 жыл бұрын
@NOA777 The method parseDouble() of wrapper class Double, convert string to double.
@deepeshsingh77174 жыл бұрын
People are missing out on your amazing content. I am still learning Java, and your content helps a lot.
@Bryysanity Жыл бұрын
how are you now on your Java journey?
@kylewc228611 ай бұрын
@@Bryysanity Im curious too
@ashkaneghbali27023 жыл бұрын
Came here straight after the 12 hour java tutorial. You are Awesome Bro. Keep 'em coming :)
@milesmiller95884 жыл бұрын
Started practice with GUI's and this helped a lot!
@AnsarAbbas-ed5ig2 жыл бұрын
off course same here bro😎
@AhsanSharief6 ай бұрын
00:03 How to make a simple calculator program using Java 03:50 Creating a Java calculator app with J buttons and J panel 07:05 Adding text field and buttons to the calculator app 10:42 Creating an array of JButtons 14:32 Adding delete and clear buttons to the calculator app interface. 17:54 Adding buttons to the panel 21:34 Adding functionality to decimal button and various math operations 26:25 Implementing Clear and Delete functionality in Java calculator app 30:17 Added functionality to the negative button, allowing the user to flip the sign of the number displayed in the text field. 33:44 How to make a very simple calculator using Java
@StefaanMeeuws3 жыл бұрын
Most impressive. Very lucid coding. Congrats on teaching me a little more than I knew!
@Sorjen1082 жыл бұрын
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
@flyetimadtravel21574 жыл бұрын
Bro You are legend. I am not a student I started learning JAVA to make my travel agency CRM.
@EbbieMonch2 жыл бұрын
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
@slonbeskonechen83104 жыл бұрын
Please, don't stop!!! More and more tutorials!!!!
@Zito_from_OHIO8 ай бұрын
the first sentence (Please, don't stop!!) remember me of a chat i had i chai 😏😏
@Ali424802 ай бұрын
@@Zito_from_OHIO
@alessandroformica68244 жыл бұрын
Thank you, Bro! My prayers to the algorithm.
@kumarkelash44234 жыл бұрын
you are really a great teacher you have made my life easy hahahah... God bless you sir
@zul_afluz Жыл бұрын
Extremely helpful. Got my mini project done within 30 minutes referring your source code and guide. Thankkksss a lotttt ☺👏
@rasisulhubbi93162 жыл бұрын
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
@westonpeabody80102 жыл бұрын
Thanks man. Believe it or not Ive been learning Java for years and until now Ive never actually wrote a fully functional calculator.
@manthanpatki1463 жыл бұрын
well I am just commenting to support you because this video has been really helpful and i learnt more ways to use GUI in java.
@BlueOrcas2 жыл бұрын
I knew bro couldn't miss the negative sign before. He just cares for us bros and was testing us to grow stronger💪
@noah774 жыл бұрын
Cool, this is nice. Awesome video. And also, I have finished creating my AI ChatBot!!
@BroCodez4 жыл бұрын
nice! Which app is it for?
@fmsabisai Жыл бұрын
This is an amazing tutorial, thumbs up. I would have loved to see how you handled division by 0. I have also noticed that its possible to have multiple dots in a number which would result in an error during calculations.
little bit late, but came across the tutorial right now. for multiple dots I did (most likely theres a better solution): if(e.getSource() == decButton) { boolean alrDec = false; for(int i = 0; i
@secretchannel21514 жыл бұрын
You are a true Bro. Thank you very much sir! Everyone keep commenting, liking and subbing to help the algorithm!
@mansinaidu Жыл бұрын
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 .
@karllouiserito3 жыл бұрын
Thanks Bro I've learned something new today about Java especially that GUI.
@கீர்த்திக்வாசன்-ர1ஞ3 жыл бұрын
awesome broo..keep rocking
@kemann38153 жыл бұрын
Amazing video. That robotic laugh at the end got me 😂
@gyangaha1094 жыл бұрын
yo bro, love it thanks keep up the good work
@Respects10311 ай бұрын
best yt for coding i learned many things from you thanks you so much bro code
@parkashkumar7652 жыл бұрын
You always perfect sir because your way of teaching is all the time perfect. Thank you so much sir.🥰
@biplobahmed65092 жыл бұрын
no caption king. learned a lot from you . thnaks for the quality content
@mohammedhh64882 жыл бұрын
Thank you very much for your assistance, you explained the code perfectly. Thumb Up.
@YaroMalik11 ай бұрын
Bro the goat. Just finished learning Java with you and am building my first project with you too
@BigBadBicycle Жыл бұрын
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.
@muhammadbsoul14592 жыл бұрын
Thanks pro Very helpful video Keep going
@suaddacic77284 жыл бұрын
Thanks man You explain java better than my teacher
@ChinmayaHelchel2 жыл бұрын
Thank you @BroCode ☺ It was really up to the point !
@ManuelErica6 ай бұрын
You're the man. Good job!
@thebeginner6132 жыл бұрын
Polich machaa.. You are great 👏🏻👏🏻
@Hypa_Playz Жыл бұрын
Nice content keep it up!!!🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥
@365motivation.92 жыл бұрын
Bro code,this is an amazing tutorial.Thank you Mann,you taught me alot here.
@grenadine94483 жыл бұрын
Awesome content !
@bellabrink86103 жыл бұрын
Amazing content as always man, thank you!
@gabrielvalentin31063 жыл бұрын
Excellent as always bro!
@alireza_programmer2 жыл бұрын
Thanks a million , It was really nice and perfect for a beginner like me
@halimaomar98202 жыл бұрын
I had a few problems with this application and I fixed one. It looks like when you use the negative button you can't click it first then click the number button you want to be negative. It will cause the program to crash. To fix this problem you can use a try and catch method plus a NumberFormatException. The NumberFormatException is an unchecked exception in Java that occurs when an attempt is made to convert a string with an incorrect format to a numeric value. Therefore, this exception is thrown when it is not possible to convert a string to a numeric type (e.g. int, float). It has this problem with negative values. However, the negative button works when you click the number button first then click the negative button. I still put this exception in just in case someone clicks the negative button first. It isn't a great fix because I would like the negative button to work both ways so it won't matter which you click first the number or the negative button. When I figure this out then I will update folks. First, I will attempt to replicate what my phone calculator does with negative buttons. They have a +/- option that has a few different behaviors that I can implement. The second problem I identified is that the functionality of the negative button doesn't work. I checked Bro Code's source code and copied then pasted it on my Eclipse file but still has the same problem. I knew it would but I wanted to make sure it wasn't just me. When you trying adding or multiplying or dividing a number against a negative number it will convert the negative number to -1. No matter what value your negative number is. For example it's -8, it will convert it to -1. Example 1, 3 * -8 = -24, but the calculator will process the equation like this: 3 * -1 = -3. I think maybe I can add a case to the switch statement so I'm going to try that first. Or I can add a loop to the negative button to address the -1 problem. As I said before, when I have solutions for this then I will post it to my comment thread.
@halimaomar98202 жыл бұрын
Update: I found a solution to the problem I identified with negative numbers. This solution I tested and it works. Negative value numbers won't automatic be converted to -1 but will have the value you intended. Code: if (e.getSource() == negButton) { double num = Double.parseDouble(textfield.getText()); if (num >= 0) { double resultneg = num * -1; textfield.setText(resultneg + " "); } else { double resultpos = num * -1; textfield.setText(resultpos + " "); } If you notice I changed the button to no longer just be a negative button but a +/- button. I did this because of the calculator apps today on phones and computers are setup with +/- functions.
@halimaomar98202 жыл бұрын
Full solution code fixing all the bugs/errors: try { if (e.getSource() == negButton) { double num = Double.parseDouble(textfield.getText()); if (num >= 0) { double resultneg = num * -1; textfield.setText(resultneg + ""); } else { double resultpos = num * -1; textfield.setText(resultpos + ""); } } } catch (NumberFormatException num) { System.out.println( "NumberFormatException occurred"); }
@Rakavi-h4f3 ай бұрын
@@halimaomar9820 if else condition to check num > 0 or less than or equal to zero , pretty much does the same function as the original bro code.Though it checks explicitly,the results are the same Btw, the two possible errors that you have spotted out are correct but unfortunately there is no solution for those in your code
@orlandohunter27853 жыл бұрын
Bro! These videos are awesome 👏
@mohdaman59282 жыл бұрын
i truly learn a lot man thanks
@athulretnakar19073 ай бұрын
Thankyou for your valuable content 😍
@kampfer63752 жыл бұрын
Very well explained 👍
@LiyaAi-fm9ec5 ай бұрын
Very beautiful, Love it!
@ritikrajput2894 Жыл бұрын
Wonderful Tutorial
@JEE-nf1cv Жыл бұрын
This was indeed Helpful brother Thanks for the tutorial
@animegaming7116 Жыл бұрын
the package come back as error what to do
@shibildas2 жыл бұрын
Bro, that was awesome ❤️
@B_lla008 Жыл бұрын
thanks for clean work it really help me !you are super good :)
@quikmath80712 жыл бұрын
Awesome tutorial
@anilsilwal17733 жыл бұрын
Great teaching
@wolanus4 жыл бұрын
Another great video. Thanks!
@alvydagr81082 жыл бұрын
Wow even though your style is different, its super easy to understand and frankly, might make me do my calculator over just because It seems easier the way you did it
@HenocDossou Жыл бұрын
Very cool! Helped me alot!
@khusanbekgafurov2 жыл бұрын
Awesome job I like it Thanks
@athenkosinyombolo42753 жыл бұрын
This was really helpful
@helpdesk95353 жыл бұрын
Thanks for the help Big Bro!
@etude59426 ай бұрын
Thank you so much for the perfect explanation ❤❤❤❤😭
@sci-figameguy82413 жыл бұрын
Hey I was wondering if you could help me, I'm making this using IntelliJ right now and at 6:40 when I run it to check if a frame comes up I get the error: "Error: Could not find or load main class Main" and I see you don't have a main class either but for some reason yours works?
@mahaalibrahim79344 жыл бұрын
That’s was a lot of code thanks for your effort
@Ahmad-jc7by Жыл бұрын
so enjoyable, thanks for this Man
@omeraran93983 жыл бұрын
I love your channel.
@sudhikrishnana97782 жыл бұрын
Great program👍👍👍
@Dontwatchthischannel5 ай бұрын
Incase you guys didnt know, calc is short for calculator, im just speaking in slang...
@meguminsatou1591 Жыл бұрын
man Thank you i really need this tutorial for my computer programming 2
@manasapanda92482 жыл бұрын
Amazing video I really enjoy this as this is very useful in my program
@maikemvictorine91002 жыл бұрын
Simple and underatandable
@ahmedshifa Жыл бұрын
Amazing content, thank you!
@djziomsuper3 жыл бұрын
Great video!
@Sub-w3x2 жыл бұрын
Very Hard working of ur life shows
@cutie3127 Жыл бұрын
Your amazing Content makes me to passionate about java more... I thought to left but ...
@garvitarora496011 ай бұрын
Also my comments on you is "Thanks you very much, Bro!"
@soumelee5661 Жыл бұрын
thanks bro for this video!! very helpful :)
@Gaminiheraliyawala Жыл бұрын
Dear Bro you are simply amazing... ❤❤💐💐being sooo... generous in sharing your wealth of knowledge and you certainly deserve a very big appreciation for making me impressed to learn Java programming. God Bless You Bro...🙏🙏. I really loved it and impatient to try it ASAP..... 👌👌👍👍
@Sapocrate3 жыл бұрын
Thanks! (I appreciate also the 420 on the preview)
@divyakale1271 Жыл бұрын
Thanks Wonderful video ! This video is easy to understand and very helpful.
@omersond48913 жыл бұрын
very helpful video. i understand for loops, if() more than before
@ThunderHockeyTFL3 жыл бұрын
big thanks, very helpful video! subbed
@kkirs95612 жыл бұрын
great video tbf
@alien3200 Жыл бұрын
20:35 He was scared for life 😂😂
@letsgame1082 жыл бұрын
Thank you so much bro. this is really amazing
@ОлегДомащенко-ы7б Жыл бұрын
great example. Thanks
@ashnasanam2173 жыл бұрын
Underrated!
@ThePraQNome Жыл бұрын
Great tutorial, thank you.
@abdialemu8391 Жыл бұрын
you are a hero!
@chiyuzhang3089 Жыл бұрын
Thanks Bro, great video!
@ryandavis7103 жыл бұрын
Great tutorial
@ShahzadKhan-jg3hl3 жыл бұрын
Well defined. Thank you.
@Dejuk22 Жыл бұрын
well done bro🙌 thank you!!
@vasilizaitsev72463 жыл бұрын
Great work bro
@raziqraz50433 жыл бұрын
Thank you bro Awesome video
@lener63453 жыл бұрын
Congratulations you have cracked the youtube algorithm
@Baltazar_Gunar3 жыл бұрын
i just finish second book about java. A Beginners Guide and Complete Reference from Herbert SCHİLDT. I was looking for an example of real GUI software that wasn't beyond my knowledge and actually did something. So I could get an idea of the general programming structure. Your video help me a lot about this. Thank you.
@infotechlab2 жыл бұрын
hey bro! thanks a lot for this amazing content..
@rudranagariya85463 жыл бұрын
Thank you so much bro you are the only best coder
@stanislavdimitrov1643 Жыл бұрын
Great, fantastic. It may seem a little but too advanced at the beginning, but you can try it and see:)