User Tag List

12491Views
Page 1 of 3 123 LastLast
Results 1 to 10 of 26
  1. #1
    Elite Member Einhver's Avatar
    Join Date
    Mar 2015
    Location
    GMT+7
    Posts
    438
    Coins
    19
    Thumbs Up
    Received: 2
    Given: 0

    My First Java Application

    @Chillivanilli is my inspiration

    This is my first project



    Download : SimpleCalculator

    Source Code

    Main.java
    Code:
    /*
     * 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
    Code:
    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.WindowConstants.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.GroupLayout.Alignment.LEADING)
                        .addGroup(layout.createSequentialGroup()
                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.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.ComponentPlacement.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.ComponentPlacement.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.GroupLayout.Alignment.BASELINE)
                        .addComponent(PlusButton)
                        .addComponent(MinusButton)
                        .addComponent(MultiButton)
                        .addComponent(DivideButton))
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 54, Short.MAX_VALUE)
                    .addComponent(AnswerLabel)
                    .addGap(52, 52, 52))
            );
    
            jLabel2.getAccessibleContext().setAccessibleDescription("");
    
            pack();
        }// </editor-fold>                        
    
        private void SecondNumberTextActionPerformed(java.awt.event.ActionEvent evt) {                                                 
            // TODO add your handling code here:
        }                                                
    
        private void PlusButtonActionPerformed(java.awt.event.ActionEvent 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.ActionEvent 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.ActionEvent 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.ActionEvent 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.getClassName());
                        break;
                    }
                }
            } catch (ClassNotFoundException ex) {
                java.util.logging.Logger.getLogger(CalculatorForm.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
            } catch (InstantiationException ex) {
                java.util.logging.Logger.getLogger(CalculatorForm.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
            } catch (IllegalAccessException ex) {
                java.util.logging.Logger.getLogger(CalculatorForm.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
            } catch (javax.swing.UnsupportedLookAndFeelException ex) {
                java.util.logging.Logger.getLogger(CalculatorForm.class.getName()).log(java.util.logging.Level.SEVERE, 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                   
    }

    0 Not allowed! Not allowed!
    Last edited by Einhver; 04-06-2015 at 10:07 AM.

    http://steamcommunity.com/id/ebina
    http://chainfaucet.cf
    http://terabitcoin.ga

    So many paths to choose.

  2. #2
    私は正義です Ryuzaki's Avatar

    Join Date
    Feb 2015
    Location
    In your NIGHTMARE
    Posts
    2,960
    Coins
    0
    Thumbs Up
    Received: 478
    Given: 122
    Keep it up mate !

    0 Not allowed! Not allowed!

  3. #3
    Elite Member fedi96's Avatar

    Join Date
    Feb 2015
    Posts
    1,132
    Coins
    1
    Thumbs Up
    Received: 39
    Given: 28
    not bad keep it uy

    0 Not allowed! Not allowed!

  4. #4
    Elite Member Einhver's Avatar
    Join Date
    Mar 2015
    Location
    GMT+7
    Posts
    438
    Coins
    19
    Thumbs Up
    Received: 2
    Given: 0
    Quote Originally Posted by Ryuzaki View Post
    Keep it up mate !
    Quote Originally Posted by fedi96 View Post
    not bad keep it uy
    Thank you

    0 Not allowed! Not allowed!

    http://steamcommunity.com/id/ebina
    http://chainfaucet.cf
    http://terabitcoin.ga

    So many paths to choose.

  5. #5
    Elite Member onsali20's Avatar
    Join Date
    Nov 2014
    Location
    127.0.0.1
    Posts
    1,389
    Coins
    4
    Thumbs Up
    Received: 115
    Given: 12
    Thanks, I will download it, couz who needs the windows calculator anyway?
    Keep it going mate!

    0 Not allowed! Not allowed!
    Still M̶o̶d̶e̶r̶a̶t̶i̶n̶g̶...
    .//ban @user
    "Stay Low, go fast. Kill first, Die last. One shot, One kill. No luck, all Skill."

  6. #6
    Banned
    Join Date
    Mar 2015
    Posts
    205
    Coins
    2
    Thumbs Up
    Received: 8
    Given: 1
    keep goin, looks nice

    0 Not allowed! Not allowed!

  7. #7
    Elite Member Einhver's Avatar
    Join Date
    Mar 2015
    Location
    GMT+7
    Posts
    438
    Coins
    19
    Thumbs Up
    Received: 2
    Given: 0
    Quote Originally Posted by onsali20 View Post
    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

    Quote Originally Posted by pimmelhd View Post
    keep goin, looks nice
    Thanks bro

    0 Not allowed! Not allowed!

    http://steamcommunity.com/id/ebina
    http://chainfaucet.cf
    http://terabitcoin.ga

    So many paths to choose.

  8. #8
    Coder Chillivanilli's Avatar




    Join Date
    Jul 2014
    Posts
    1,200
    Coins
    103
    Thumbs Up
    Received: 273
    Given: 128
    Quote Originally Posted by Einhver View Post
    @Chillivanilli is my inspiration

    This is my first project



    Download : SimpleCalculator
    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

    0 Not allowed! Not allowed!

  9. #9
    Elite Member Einhver's Avatar
    Join Date
    Mar 2015
    Location
    GMT+7
    Posts
    438
    Coins
    19
    Thumbs Up
    Received: 2
    Given: 0
    Quote Originally Posted by Chillivanilli View Post
    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
    Be prepared , I will be a lot to ask about this. I hope you're pleased.

    0 Not allowed! Not allowed!

    http://steamcommunity.com/id/ebina
    http://chainfaucet.cf
    http://terabitcoin.ga

    So many paths to choose.

  10. #10
    Member sanjaro's Avatar
    Join Date
    Apr 2015
    Location
    Netizen
    Posts
    43
    Coins
    0
    Thumbs Up
    Received: 0
    Given: 0
    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

    0 Not allowed! Not allowed!

Page 1 of 3 123 LastLast

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •