Results 1 to 4 of 4
  1. #1
    swedishfished is offline Member
    Join Date
    Sep 2012
    Posts
    24
    Rep Power
    0

    Default Calculator help needed desperately!

    Help! I really need some help with this calculator I am trying to make. Please give me some criticism (I'm a big boy, I can take it).
    Here is the code:

    Java Code:
    import javax.swing.JFrame;
    import javax.swing.JTextField;
    import javax.swing.JPasswordField;
    import javax.swing.JOptionPane;
    import java.awt.FlowLayout;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import javax.swing.JComboBox;
    import javax.swing.plaf.basic.BasicComboBoxRenderer;
    import javax.swing.JFrame;
    import javax.swing.JList;
    import javax.swing.UIManager;
    import java.awt.Component;
    import java.util.HashSet;
    import java.util.Set;
    import java.lang.reflect.Array;
    
    
    public class tuna extends JFrame {
    
    		
    	
    
    private JTextField number1;
    private JTextField number2;
    private JTextField finalanswer;
    private JComboBox operation;
    	public tuna(){
    		super("Basic Calculator");
    		setLayout(new FlowLayout());
    		number1= new JTextField("Enter the first number: ",5);
    		number2 = new JTextField("Enter the second number: ", 5);
    		finalanswer = new JTextField(5);
    		finalanswer.setEditable(false);
    		String[] operators = {"times", "plus", "minus", "divided by"};
    		operation = new JComboBox(operators);
    		add(number1);
    		add(operation);
    		add(number2);
    		add(finalanswer);
    		thehandler handler= new thehandler();
    		number1.addActionListener(handler);
    		number2.addActionListener(handler);
    		operation.addActionListener(handler);
    		finalanswer.addActionListener(handler);
    	}
    	private class thehandler implements ActionListener{
    		public void actionPerformed(ActionEvent event){
    			if(event.getSource()==number1 || event.getSource()==number2){
    				
    				String y=number1.getText();
    				String x=number2.getText();
    				int a=Integer.parseInt(y);
    				int b=Integer.parseInt(x);
    				String[] operators = {"times", "plus", "minus", "divided by"};
    				String op=(String)operation.getSelectedItem();
    				int counter = 0;
    switch(op.charAt(0)){
    
    case 't':
    int result=a*b;
    JOptionPane.showMessageDialog(null,result);
    case 'p':
    int result2=a+b;
    JOptionPane.showMessageDialog(null,result2);
    
    case 'm':
    	int result3=a-b;
    	JOptionPane.showMessageDialog(null,result3);
    
    case 'd':
    	int result4=a/b;
    	JOptionPane.showMessageDialog(null,result4);
    
    }
    				}	
    			String op=(String)operation.getSelectedItem();
    			char child = op.charAt(0);
    
    		}	
    	}
    
    
    }
    Java Code:
    import javax.swing.JFrame;
    class apples {
    public static void main(String args[]){
    	
    	tuna object1=new tuna();
    	object1.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    	object1.setSize(500,500);
    	object1.setVisible(true);
    
    }
    }

  2. #2
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,189
    Rep Power
    19

    Default Re: Calculator help needed desperately!

    Do you have a specific question, or did you just want a code review? If the latter, I shall move this thread to Reviews/Advertising.

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  3. #3
    swedishfished is offline Member
    Join Date
    Sep 2012
    Posts
    24
    Rep Power
    0

    Default Re: Calculator help needed desperately!

    Mostly just a code review thanks

  4. #4
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,189
    Rep Power
    19

    Default Re: Calculator help needed desperately!

    Moved from New to Java

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

Similar Threads

  1. I desperately need help
    By dc2acgsr99 in forum Java Applets
    Replies: 5
    Last Post: 01-11-2014, 05:36 PM
  2. Help desperately needed - synchronized swaps
    By Chromatism in forum New To Java
    Replies: 3
    Last Post: 04-30-2012, 01:22 AM
  3. Replies: 15
    Last Post: 04-21-2012, 01:38 AM
  4. Calculator Program HELP NEEDED FAST! Homework assignment
    By SteroidalPsycho in forum New To Java
    Replies: 3
    Last Post: 03-05-2009, 04:02 AM
  5. Desperately need help
    By nel636 in forum New To Java
    Replies: 0
    Last Post: 12-03-2008, 12:43 AM

Tags for this Thread

Posting Permissions

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