Java Eclipse GUI Tutorial 2 # Creating A Simple Calculator Using JFrame

Java Eclipse GUI Tutorial 2 # Creating A Simple Calculator Using JFrame

ProgrammingKnowledge

9 лет назад

309,095 Просмотров

Ссылки и html тэги не поддерживаются


Комментарии:

@anuragyadav9680
@anuragyadav9680 - 20.01.2023 15:22

thanku

Ответить
@itsyaboi_jaja
@itsyaboi_jaja - 25.03.2022 04:47

Can i have the code pls

Ответить
@pasadena195
@pasadena195 - 01.11.2021 14:57

love u bro i managed to do my uni homework thanks to u!!!

Ответить
@radhikatikone3731
@radhikatikone3731 - 24.06.2021 15:50

Can we use window builder swing in JavaFX project?....Is this similar or two different things... please help me I'm so confused between this.

Ответить
@ayeshagujjar3791
@ayeshagujjar3791 - 04.05.2021 23:19

It was helpful<3

Ответить
@ousmanesangary658
@ousmanesangary658 - 08.09.2020 07:23

Did anyone notice wrong results in adding and subtracting??? I need help to this , why the answer is wrong after adding or substracting ??

Ответить
@rahatulashekinashik
@rahatulashekinashik - 14.08.2020 15:56

Thanks man!!!! <3

Ответить
@sturanovicms
@sturanovicms - 25.04.2020 16:31

Simple tasks but you go through everything! Thank you, you've explained it better than my university professor.

Ответить
@CB-xk4oz
@CB-xk4oz - 24.04.2020 01:18

Thank you once again for making such a user friendly , easy to understand video. I was able to make my program work well with your tips.

Ответить
@ahsanchaudhary910
@ahsanchaudhary910 - 08.04.2020 13:44

I just installed eclipse and I installed a new software which is the window builder. When I tried to open the design page I get the error " Unknown GUI toolkit". Hopefully you guys can help me

Ответить
@SkyRocket159
@SkyRocket159 - 17.02.2020 23:08

I will take this lebl

Ответить
@brianpuron1033
@brianpuron1033 - 12.11.2019 04:43

for some reason the frame of the windows that we can see on the right side seems like if it was cut off, but whenever i play the program it seems normal, does anyone knows why is that?

Ответить
@smakina1618
@smakina1618 - 25.10.2019 22:23

U ARE THE BEST THANK YOU SO MUCH REALLY

Ответить
@aakash4416
@aakash4416 - 14.09.2019 12:49

This program are not working in netbean why?????

Ответить
@akshataustin5483
@akshataustin5483 - 21.08.2019 11:24

sir scientific calculator

Ответить
@muhammadahsaam5920
@muhammadahsaam5920 - 20.01.2019 23:14

Nice video very helpfull thanks for uplooading

Ответить
@lakshmipriya8444
@lakshmipriya8444 - 11.01.2019 09:33

Could you please help me to do a program with check box;

Ответить
@asiyamahamoudabdi1235
@asiyamahamoudabdi1235 - 23.12.2018 10:39

iwonna that code please send me if you can

Ответить
@JahidHasan-zl7om
@JahidHasan-zl7om - 29.11.2018 08:24

i got the output, but ans comes wrong, what can i do?

Ответить
@monukumarmodi6551
@monukumarmodi6551 - 03.11.2018 22:28

How can I convert this into an software so that I need not to open eclipse and run again and again . I just want that by double click the software should run.

Ответить
@violeta4558
@violeta4558 - 25.10.2018 11:11

Exelent tutorial. But how we can create executable file which will be set to another computer and so will functional?

Ответить
@Ventixo
@Ventixo - 14.10.2018 21:05

If you want it to work with decimals, change "int" and "Integer" in the coding to "Double", like this:
Double num1, num2, ans;
try {
num1=Double.parseDouble(textFieldnum1.getText());
num2=Double.parseDouble(textFieldnum2.getText());
ans = num1 + num2;
textFieldans.setText(Double.toString(ans));
} catch (Exception c) {
JOptionPane.showMessageDialog(null, "This is a calculator you idiot. Only numbers.");
}

Ответить
@musicandpoems4620
@musicandpoems4620 - 13.10.2018 22:08

i wrote JoptionPane but it is showing an error and error is about create a class JoptionPane or a package ...and many more ..so what we can use instead of it?? please reply

Ответить
@blackatomic1669
@blackatomic1669 - 24.08.2018 17:03

Well, i looked away for 20second and after I focused on the video again, everything was still the same.

Ответить
@2mathnav282
@2mathnav282 - 14.08.2018 11:17

u are really good and simple any one can understand u but man pls do it faster than that ;

Ответить
@lgx22
@lgx22 - 06.08.2018 10:45

great job man. you are awesome!

Ответить
@patrickedwinmoran2966
@patrickedwinmoran2966 - 08.07.2018 05:13

I have gone through the code and have found nothing that won't compile on the current Eclipse and Jave systems. Just in case any of you have made a typo you can't find, here is the code that works for me.
import java.awt.EventQueue;

import javax.swing.JFrame;
import javax.swing.JTextField;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JOptionPane;

import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;

public class Calc {

private JFrame frame;
private JTextField txtNum1;
private JTextField txtNum2;
private JButton btnSubtract;
private JLabel lblAnswIs;
private JTextField txtNum3;

/**
* Launch the application.
*/
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
Calc window = new Calc();
window.frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}

/********
* Create the application.
**********/
public Calc() {
initialize();
}

/*********
* Initialize the contents of the frame.
***********/
private void initialize() {
frame = new JFrame();
frame.setBounds(100, 100, 645, 302);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.getContentPane().setLayout(null);

txtNum1 = new JTextField();
txtNum1.setText(""); //Don't fill anything in here so user doesn't have to erase it.
txtNum1.setBounds(20, 21, 274, 26);
frame.getContentPane().add(txtNum1);
txtNum1.setColumns(10);

txtNum2 = new JTextField();
txtNum2.setText(""); //Don't fill anything in here so user doesn't have to erase it
txtNum2.setBounds(318, 21, 274, 26);
frame.getContentPane().add(txtNum2);
txtNum2.setColumns(10);

JButton btnAdd = new JButton("ADD");
btnAdd.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
int num1, num2, ans;

try {
num1 = Integer.parseInt(txtNum1.getText());
num2 = Integer.parseInt(txtNum2.getText());
ans = num1 + num2;
txtNum3.setText(Integer.toString(ans));// Take the int called ans, turn it into a String that represents an integer
} catch (NumberFormatException e1) {
JOptionPane.showMessageDialog(null, "Please Enter an Integer" + e1);
}

}
});
btnAdd.setBounds(18, 98, 117, 29);
frame.getContentPane().add(btnAdd);

btnSubtract = new JButton("SUBTRACT");
btnSubtract.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
int num1, num2, ans; // These declaration need to be repeated here because they are local in both places.

try {
num1 = Integer.parseInt(txtNum1.getText());
num2 = Integer.parseInt(txtNum2.getText());
ans = num1 - num2;
txtNum3.setText(Integer.toString(ans));// Take the int called ans, turn it into a String that represents an integer
} catch (NumberFormatException e2) {
JOptionPane.showMessageDialog(null, "Please Enter an Integer" + e2);
}

}
});
btnSubtract.setBounds(312, 98, 117, 29);
frame.getContentPane().add(btnSubtract);

lblAnswIs = new JLabel("The Answer is");
lblAnswIs.setBounds(53, 238, 149, 16);
frame.getContentPane().add(lblAnswIs);

txtNum3 = new JTextField();
txtNum3.setText(" "); //Don't fill anything in here so user doesn't have to erase it
txtNum3.setBounds(257, 233, 130, 26);
frame.getContentPane().add(txtNum3);
txtNum3.setColumns(10);
}
}

Ответить
@tanayparmar3020
@tanayparmar3020 - 27.05.2018 19:43

Sir mere me window builder encounter unexpected internal error aa rha he

Ответить
@darksithmartin
@darksithmartin - 18.05.2018 14:57

hi this is great, are you able to help me with a slightly more complicated version of what you have here. example; i need to input about 8 variables (different headcount/hours) then calculate auto or by button the total capability to pick cartons depending on the KPI rate and length of shift done 7 .25hrs or 7.5hrs. 3 of the variable have a different KPI rate so they have separate calculations. so the program adds all the seperate calcs then totals the possible amount and hours used.

Ответить
@fajarishizaki4292
@fajarishizaki4292 - 03.05.2018 04:26

Thanks sir

Ответить
@drean3807
@drean3807 - 23.04.2018 21:02

i have a question about JOptionPane.showMessageDialog.
lets say there is a box and i press add while the box is empty then JOptionPane.showMessageDialog shows.
is there a way to hide it ?

Ответить
@paavangupta3420
@paavangupta3420 - 11.04.2018 16:57

Sir, can i use the java scene builder with netbeans along with your tutorials.

Ответить
@computerbolter4079
@computerbolter4079 - 26.03.2018 08:13

By The Way, Which Screen Recorder Do You Use???

Ответить
@computerbolter4079
@computerbolter4079 - 26.03.2018 08:13

Thanks Sir, I'm Following You Since A Month And You Have Helped Me Very Much.

Ответить
@nickmurdoch4890
@nickmurdoch4890 - 19.02.2018 20:10

I keep getting an error on my (Exeption e) can anyone help me?

Ответить
@deaballgjati3601
@deaballgjati3601 - 10.02.2018 21:17

Everytime I close eclipse, the windowbuilder gets uninstalled itself.I have to reinstall when i open the eclipse again. Can u help me please?

Ответить
@maheshj
@maheshj - 16.01.2018 12:54

hi what if I am creating a login system and I want the components (like text box button) to always centre the screen regardless of window size whethere fullscreen or small window always in centre How??

Ответить
@enesard
@enesard - 11.01.2018 16:30

Great

Ответить
@RA-nc6bt
@RA-nc6bt - 28.11.2017 15:13

Ur teaching very nice plz provide Bangalore location address definitely join to ur organisation plzzzzzzzzzzzzzzzzzzzzzzzzzz i am looking for ur replay

Ответить
@karly658
@karly658 - 26.09.2017 16:15

are there any software better than eclipse and net beans?

Ответить
@musicinc7851
@musicinc7851 - 07.09.2017 12:11

i have.form files and java files. how to run those on eclipse. if you help me it will be giving new life to me

Ответить
@qaziaziz197
@qaziaziz197 - 19.08.2017 20:45

Great step by step, easy for beginners.

Ответить
@rahulzirpe9284
@rahulzirpe9284 - 05.07.2017 15:48

Code is executable but components of frame after executing are looking blur and not properly. please tell me the solution?

Ответить
@nagamallisupraja860
@nagamallisupraja860 - 21.05.2017 21:15

Thanku sooo much sir

Ответить
@nasywanmashud5367
@nasywanmashud5367 - 02.05.2017 20:11

Good video sir!! but may i know what if my input n my answer is float? can u help me sir

Ответить
@ruffryder756
@ruffryder756 - 01.05.2017 00:14

Great video!! How do you add the Sqrt and POW function to it?

Ответить
@nabeelahmed9875
@nabeelahmed9875 - 05.04.2017 00:58

i have added two more buttons of multiply and divide. now whenever i am calculating it is only giving exception and not performing the calculations. please help??

Ответить
@chadtv538
@chadtv538 - 25.01.2017 06:53

You dont have to convert the fucking integer to a string, just do textFieldAns.setText("" + ans);

It does the same thing bro.

Ответить
@nagahalomac
@nagahalomac - 23.01.2017 23:31

It doesn't work for (*) and (/) though

Ответить