PDA

View Full Version : My First Java Application



Einhver
04-01-2015, 12:32 PM
Chillivanilli is my inspiration :prettiness:

This is my first project :shout:

http://i.imgur.com/UbMcJdM.png

Download : SimpleCalculator (http://www.mediafire.com/download/7jerok1sotoedtm/SimpleCalculator.jar)

Source Code

Main.java


/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/

/**
*
* @author Ebina
*/
public class Main {

/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
CalculatorForm form = new CalculatorForm();
form.setVisible(true);
}

}



CalculatorForm.java


import javax.swing.JOptionPane;

/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/

/**
*
* @author Ebina
*/
public class CalculatorForm extends javax.swing.JFrame {

/**
* Creates new form CalculatorForm
*/
public CalculatorForm() {
initComponents();
}

/**
* This method is called from within the constructor to initialize the form.
* WARNING: Do NOT modify this code. The content of this method is always
* regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {

FirstNumberText = new javax.swing.JTextField();
SecondNumberText = new javax.swing.JTextField();
jLabel1 = new javax.swing.JLabel();
jLabel2 = new javax.swing.JLabel();
PlusButton = new javax.swing.JButton();
MinusButton = new javax.swing.JButton();
AnswerLabel = new javax.swing.JLabel();
MultiButton = new javax.swing.JButton();
DivideButton = new javax.swing.JButton();

setDefaultCloseOperation(javax.swing.WindowConstan ts.EXIT_ON_CLOSE);
setTitle("Simple Calculator by Einhver A2S.in");

SecondNumberText.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
SecondNumberTextActionPerformed(evt);
}
});

jLabel1.setText("First number");

jLabel2.setText("Second number");

PlusButton.setText("+");
PlusButton.setToolTipText("Plus");
PlusButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
PlusButtonActionPerformed(evt);
}
});

MinusButton.setText("-");
MinusButton.setToolTipText("Minus");
MinusButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
MinusButtonActionPerformed(evt);
}
});

AnswerLabel.setText("Answer is :");

MultiButton.setText("*");
MultiButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
MultiButtonActionPerformed(evt);
}
});

DivideButton.setText("/");
DivideButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
DivideButtonActionPerformed(evt);
}
});

javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout .Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addGroup(layout.createParallelGroup(javax.swing.G roupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.G roupLayout.Alignment.LEADING)
.addComponent(AnswerLabel)
.addGroup(layout.createSequentialGroup()
.addComponent(PlusButton)
.addGap(18, 18, 18)
.addComponent(MinusButton)
.addGap(18, 18, 18)
.addComponent(MultiButton)
.addGap(18, 18, 18)
.addComponent(DivideButton))
.addComponent(jLabel2)
.addComponent(jLabel1))
.addGap(0, 144, Short.MAX_VALUE))
.addComponent(FirstNumberText, javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(SecondNumberText))
.addContainerGap())
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout .Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(jLabel1)
.addPreferredGap(javax.swing.LayoutStyle.Component Placement.UNRELATED)
.addComponent(FirstNumberText, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(24, 24, 24)
.addComponent(jLabel2)
.addPreferredGap(javax.swing.LayoutStyle.Component Placement.UNRELATED)
.addComponent(SecondNumberText, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(37, 37, 37)
.addGroup(layout.createParallelGroup(javax.swing.G roupLayout.Alignment.BASELINE)
.addComponent(PlusButton)
.addComponent(MinusButton)
.addComponent(MultiButton)
.addComponent(DivideButton))
.addPreferredGap(javax.swing.LayoutStyle.Component Placement.RELATED, 54, Short.MAX_VALUE)
.addComponent(AnswerLabel)
.addGap(52, 52, 52))
);

jLabel2.getAccessibleContext().setAccessibleDescri ption("");

pack();
}// </editor-fold>

private void SecondNumberTextActionPerformed(java.awt.event.Act ionEvent evt) {
// TODO add your handling code here:
}

private void PlusButtonActionPerformed(java.awt.event.ActionEve nt evt) {
// TODO add your handling code here:
int number1, number2;
try {
number1 = Integer.parseInt(
this.FirstNumberText.getText());
}
catch (Exception e) {
JOptionPane.showMessageDialog(this, "Bad first number!", "Error", JOptionPane.ERROR_MESSAGE);
return;
}
try {
number2 = Integer.parseInt(
this.SecondNumberText.getText());
}
catch (Exception e) {
JOptionPane.showMessageDialog(this, "Bad second number!", "Error", JOptionPane.ERROR_MESSAGE);
return;
}
int answer = number1 + number2;
this.AnswerLabel.setText(
"Answer is : "+ answer);
}

private void MinusButtonActionPerformed(java.awt.event.ActionEv ent evt) {
// TODO add your handling code here:
int number1, number2;
try {
number1 = Integer.parseInt(
this.FirstNumberText.getText());
} catch (Exception e) {
JOptionPane.showMessageDialog(this, "Bad first number!", "Error", JOptionPane.ERROR_MESSAGE);
return;
}
try {
number2 = Integer.parseInt(
this.SecondNumberText.getText());
} catch (Exception e) {
JOptionPane.showMessageDialog(this, "Bad second number!", "Error", JOptionPane.ERROR_MESSAGE);
return;
}
int answer = number1 - number2;
this.AnswerLabel.setText(
"Answer is : " + answer);
}

private void MultiButtonActionPerformed(java.awt.event.ActionEv ent evt) {
// TODO add your handling code here:
int number1, number2;
try {
number1 = Integer.parseInt(
this.FirstNumberText.getText());
}
catch (Exception e) {
JOptionPane.showMessageDialog(this, "Bad first number!", "Error", JOptionPane.ERROR_MESSAGE);
return;
}
try {
number2 = Integer.parseInt(
this.SecondNumberText.getText());
}
catch (Exception e) {
JOptionPane.showMessageDialog(this, "Bad second number!", "Error", JOptionPane.ERROR_MESSAGE);
return;
}
int answer = number1 * number2;
this.AnswerLabel.setText(
"Answer is : "+ answer);
}

private void DivideButtonActionPerformed(java.awt.event.ActionE vent evt) {
// TODO add your handling code here:
int number1, number2;
try {
number1 = Integer.parseInt(
this.FirstNumberText.getText());
}
catch (Exception e) {
JOptionPane.showMessageDialog(this, "Bad first number!", "Error", JOptionPane.ERROR_MESSAGE);
return;
}
try {
number2 = Integer.parseInt(
this.SecondNumberText.getText());
}
catch (Exception e) {
JOptionPane.showMessageDialog(this, "Bad second number!", "Error", JOptionPane.ERROR_MESSAGE);
return;
}
int answer = number1 / number2;
this.AnswerLabel.setText(
"Answer is : "+ answer);
}

/**
* @param args the command line arguments
*/
public static void main(String args[]) {
/* Set the Nimbus look and feel */
//<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
/* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
* For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
*/
try {
for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
if ("Nimbus".equals(info.getName())) {
javax.swing.UIManager.setLookAndFeel(info.getClass Name());
break;
}
}
} catch (ClassNotFoundException ex) {
java.util.logging.Logger.getLogger(CalculatorForm. class.getName()).log(java.util.logging.Level.SEVER E, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(CalculatorForm. class.getName()).log(java.util.logging.Level.SEVER E, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(CalculatorForm. class.getName()).log(java.util.logging.Level.SEVER E, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(CalculatorForm. class.getName()).log(java.util.logging.Level.SEVER E, null, ex);
}
//</editor-fold>

/* Create and display the form */
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new CalculatorForm().setVisible(true);
}
});
}

// Variables declaration - do not modify
private javax.swing.JLabel AnswerLabel;
private javax.swing.JButton DivideButton;
private javax.swing.JTextField FirstNumberText;
private javax.swing.JButton MinusButton;
private javax.swing.JButton MultiButton;
private javax.swing.JButton PlusButton;
private javax.swing.JTextField SecondNumberText;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel2;
// End of variables declaration
}

Ryuzaki
04-01-2015, 12:43 PM
Keep it up mate ! :D

fedi96
04-01-2015, 01:01 PM
:notbad: not bad keep it uy

Einhver
04-01-2015, 01:04 PM
Keep it up mate ! :D


:notbad: not bad keep it uy

Thank you :feelbro:

onsali20
04-01-2015, 03:48 PM
Thanks, I will download it, couz who needs the windows calculator anyway? =)
Keep it going mate!

pimmelhd
04-01-2015, 03:51 PM
keep goin, looks nice

Einhver
04-01-2015, 04:18 PM
Thanks, I will download it, couz who needs the windows calculator anyway? =)
Keep it going mate!

Hahaha, whos know, maybe virus eat your windows calculator :shout:


keep goin, looks nice

Thanks bro

Chillivanilli
04-01-2015, 04:41 PM
Chillivanilli is my inspiration :prettiness:

This is my first project :shout:

http://i.imgur.com/UbMcJdM.png

Download : SimpleCalculator (http://www.mediafire.com/download/7jerok1sotoedtm/SimpleCalculator.jar)

Great to see that and great to hear im your inspiration :) I just saw this thread and although I'm still on vacation i decided to reply :)
Keep up the learning, I also made a calculator when I learned Java.
If you have any questions belonging to Java just Pm me when I'm back and I'll try to help you
Greetings from Egypt

Einhver
04-01-2015, 07:10 PM
Great to see that and great to hear im your inspiration :) I just saw this thread and although I'm still on vacation i decided to reply :)
Keep up the learning, I also made a calculator when I learned Java.
If you have any questions belonging to Java just Pm me when I'm back and I'll try to help you
Greetings from Egypt

OMG! Thank you so much master Chillivanilli :prettiness:
Be prepared , I will be a lot to ask about this. I hope you're pleased.
:love::love::love:

sanjaro
04-05-2015, 08:31 PM
Good job mate. It's really simple, but everyone have their start. I'm glad that you posted calculator with GUI, because most of people do console ones lol. You can post more of your work in the future here, it's always some kind of motivation to learn more about Java by getting attention from other people :D

Ussagui
04-05-2015, 08:38 PM
Chillivanilli is my inspiration :prettiness:

This is my first project :shout:

http://i.imgur.com/UbMcJdM.png

Download : SimpleCalculator (http://www.mediafire.com/download/7jerok1sotoedtm/SimpleCalculator.jar)
Nice mate! It's a good start! I'm learning java at school, but i haven't study yet :s i will start tomorrow cause i want to be awesome like Chillivanilli :P eheh


Great to see that and great to hear im your inspiration :) I just saw this thread and although I'm still on vacation i decided to reply :)
Keep up the learning, I also made a calculator when I learned Java.
If you have any questions belonging to Java just Pm me when I'm back and I'll try to help you
Greetings from Egypt

Enjoy your vecation! Because when you come back people will ask for you a lot! ahah :D


ps: if i really start studying tomorrow like i said and do an aplication i will share it like Einhver! :)

Ussagui
04-05-2015, 08:39 PM
Einhver what IDE do you use btw?

can you share code? ...

EdgarT
04-05-2015, 08:50 PM
Next time if you post your applications then post also source code. This way other coders might look it and give you some useful advices :)

legendclaw24
04-05-2015, 08:54 PM
Very nice.. Keep it up :)

fedi96
04-05-2015, 08:56 PM
Einhver , all members are waiting your great code :cool2: :shout:

Ussagui
04-05-2015, 10:38 PM
Einhver , all members are waiting your great code :cool2: :shout:

ahah you made me laugh fedi96 xD in a good way, not making fun of his application/code! :)

Einhver
04-06-2015, 10:03 AM
Einhver what IDE do you use btw?

can you share code? ...

NetBeans IDE 8.0.2


Very nice.. Keep it up :)

Thanks :smile:


Next time if you post your applications then post also source code. This way other coders might look it and give you some useful advices :)


Einhver , all members are waiting your great code :cool2: :shout:

I'll update with the Source Code :shout:

Einhver
04-06-2015, 10:09 AM
sanjaro Now you can see the Source Code :shout:

Ussagui
04-06-2015, 11:37 AM
sanjaro Now you can see the Source Code :shout:

Thanks! Maby you should try Eclips :)

sanjaro
04-06-2015, 11:40 AM
I think that your coding-style is good. How long are you interested in Java?


Thanks! Maby you should try Eclips :)
Eclipse and Netbeans are both good and i don't see much difference between them lol. I think that Eclipse is just more popular.

Ussagui
04-06-2015, 11:58 AM
I think that your coding-style is good. How long are you interested in Java?


Eclipse and Netbeans are both good and i don't see much difference between them lol. I think that Eclipse is just more popular.

Maby it's my computer problem ... but my NetBeans take more time to "process" than Eclipse :/ and i think its better get used to use Eclipse cause if you one day will programming with another language Eclipse will do it and you will already know how to use it ...

sanjaro
04-06-2015, 12:07 PM
Maby it's my computer problem ... but my NetBeans take more time to "process" than Eclipse :/ and i think its better get used to use Eclipse cause if you one day will programming with another language Eclipse will do it and you will already know how to use it ...

Right Eclipse offers different laguages so i often change between Java and PHP using Eclipse. I think it is issue with your comp, because i don't this kind of problems. Okay let's stop the spam in his thread because he would get angry that we spam under his awesome calculator about stupid IDE's xD

Einhver
04-06-2015, 12:17 PM
I think that your coding-style is good. How long are you interested in Java?


Eclipse and Netbeans are both good and i don't see much difference between them lol. I think that Eclipse is just more popular.

I study Java in My University but I never doing project, now I already graduated.
And I see Chillivanilli bot created with Java, I love it and trying to make my own project with java (Starting to love Java more)


Thanks! Maby you should try Eclips :)

I am familiar with NetBeans for now, at University I am using Eclipse. More love NetBeans GUI :smile:

Also NetBeans have other language programing like PHP, HTML, C/C++

http://i.imgur.com/SNIizS8.png

onsali20
04-06-2015, 05:19 PM
I study Java in My University but I never doing project, now I already graduated.
And I see Chillivanilli bot created with Java, I love it and trying to make my own project with java (Starting to love Java more)



I am familiar with NetBeans for now, at University I am using Eclipse. More love NetBeans GUI :smile:

Also NetBeans have other language programing like PHP, HTML, C/C++

http://i.imgur.com/SNIizS8.png

Added you on steam mate, my new acc for cs : go omerprogangsta
Accept.

Einhver
04-06-2015, 05:22 PM
Added you on steam mate, my new acc for cs : go omerprogangsta
Accept.

I don't see with that name, PM me your steam link.

onsali20
04-06-2015, 05:50 PM
I don't see with that name, PM me your steam link.

Okay, I got in my onasli20 account - tfcbwacky99 | glocualcu