+ Reply to Thread
Results 1 to 7 of 7

Thread: java help with codes (please)..

  1. #1
    anirtak143 is offline x10 Sophmore anirtak143 is an unknown quantity at this point
    Join Date
    Mar 2008
    Location
    Philippines
    Posts
    213

    Smile java help with codes (please)..

    hey guys. i need help here.. ^^ kindly fix this class for me.. ^^ its just a small java program, but it wont compile and i dont know why.. kindly fix it please. ^^

    thanks. heres the code..

    Code:
    import java.awt.*;
    import javax.swing.*;
    import java.awt.event.*;
    
    public class Project2 implements ActionListener{
        private JFrame MainFrame;
        private JTextField TF1;
        private JLabel Label1, Label2;
        private JPanel Panel1, Panel2, Panel3, Panel4, Panel5;
        private JButton AddButton, SubtractButton, MultiplyButton, DivideButton, ModuloButton,EqualsButton;
        private double D1 = 0, D2;
        private char OpDone = 'e';
        private String UserInput;
    
    public static void main(String[] args)
    { new Project2();
    }
    
    public Project2{
        MainFrame = new JFrame("Kevin Mabul's Calculator");
        
        Panel1 = new JPanel();
        Panel2 = new JPanel();
        Panel3 = new JPanel();
        Panel4 = new JPanel();
        Panel5 = new JPanel();
        
        Label1 = new JLabel("Patience is a virtue");
        Label2 = new JLabel("Java is a versatile language");
        
        AddButton = new JButton("+");
        AddButton.addActionListener(this);
        SubtractButton = new JButton("-");
        SubtractButton.addActionListener(this);
        MultiplyButton = new JButton("x");
        MultiplyButton.addActionListener(this);
        DivideButton = new JButton("/");
        DivideButton.addActionListener(this);
        ModuloButton = new JButton("%");
        ModuloButton.addActionListener(this);
        EqualsButton = new JButton("=");
        EqualsButton.addActionListener(this);
        
        TF1 = new JTextField("0",15);
        TF1.selectAll();
        TF1.requestFocus();
        
        Panel1.setBackground(Color.YELLOW);
        Panel2.setBackground(Color.GREEN);
        Panel3.setBackground(Color.GREEN);
        Panel4.setBackground(Color.YELLOW);
        
        Panel1.add(Label1);
        Panel2.add(Label2);
        Panel3.add(TF1);
        
        Panel5.add(Panel1);
        Panel5.add(Panel2);
        Panel5.add(Panel3);
        Panel5.add(Panel4);
        
        Panel4.add(AddButton);
        Panel4.add(SubtractButton);
        Panel4.add(MultiplyButton);
        Panel4.add(DivideButton);
        Panel4.add(ModuloButton);
        Panel4.add(EqualsButton);
        
        Panel5.setLayout(new GridLayout(4,1);
        
        MainFrame.setContentPane(Panel5);
        MainFrame.pack();
        MainFrame.show();
        MainFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    }
    
    public void actionPerformed(ActionEvent e){
        {
            UserInput = TF1.getText();
            double D2 = Double.parseDouble(UserInput);
            
            {
                if(OpDone =='a')
                D1 = D1 + D2;
                
                if(OpDone =='s')
                D1 = D1 - D2;
                
                if(OpDone =='m')
                D1 = D1 * D2;
                
                if(OpDone =='d')
                D1 = D1 / D2;
                
                if(OpDone =='r')
                D1 = D1 % D2;
                
                if(OpDone =='e')
                D1 = D2;
            }
            
            if(e.getActionCommand().equals("+"))
            OpDone = 'a';
            if(e.getActionCommand().equals("-"))
            OpDone = 's';
            if(e.getActionCommand().equals("x"))
            OpDone = 'm';
            if(e.getActionCommand().equals("/"))
            OpDone = 'd';
            if(e.getActionCommand().equals("%"))
            OpDone = 'r';
            if(e.getActionCommand().equals("="))
            OpDone = 'e';
            
        }
        UserInput = Double.toString(D1);
        TF1.setText(UserInput);
        TF1.selectAll();
        TF1.requestFocus();
    }
    }
    ex-x10er... ^^

  2. #2
    xmakina's Avatar
    xmakina is offline x10 Lieutenant xmakina is an unknown quantity at this point
    Join Date
    May 2008
    Location
    England
    Posts
    265

    Re: java help with codes (please)..

    In the nicest possible way, do your own damn homework.

    And next time you have some Real Java code that doesn't compile, tell us the compile error since we don't want to have to read your whole script when it's probably just a semicolon that anyone who can read debug messages will know in a second where to look.
    IF($this->$post.content() == "SEE SIG"){
    w3Schools and Google
    }

  3. #3
    natsuki's Avatar
    natsuki is offline x10 Sophmore natsuki is an unknown quantity at this point
    Join Date
    Sep 2008
    Posts
    112

    Re: java help with codes (please)..

    woah that IS Java and it's waay different from javascript(ECMAScript). Dunno much who knows any java here... that's not even a script it's a complete oo code for an app..
    Last edited by natsuki; 10-18-2008 at 11:29 AM.

  4. #4
    leafypiggy's Avatar
    leafypiggy is offline Community Advocate leafypiggy is on a distinguished road
    Join Date
    Aug 2007
    Location
    Massachusetts
    Posts
    2,228

    Re: java help with codes (please)..

    ever heard of

    Code:
    System.exit( 0 );
    lol
    Neil Hanlon | x10Hosting Support Representative
    Neil[at]x10hosting.com
    █ I'm always happy to help. Just ask a question in Free Hosting
    Terms of Service IRC

  5. #5
    ldtwo is offline x10Hosting Member ldtwo is an unknown quantity at this point
    Join Date
    Mar 2008
    Posts
    6

    Re: java help with codes (please)..

    First, I recommend netbeans if you aren't using it. Second, you will get much better elp in a java forum. Third, you should state what error you are getting and what line. Use the console, output feedback to discover errors and catch errors you expect to happen and then output more data to help you track the origin of the errors.

  6. #6
    Harry is offline x10Hosting Member Harry is an unknown quantity at this point
    Join Date
    Sep 2007
    Posts
    3

    Re: java help with codes (please)..

    Error 1 : missing paranthesis
    Panel5.setLayout(new GridLayout(4,1));

    Error 2 : wrong constructor syntax (without paranthesis)
    public Project2()

    Complete code
    Code:
    import java.awt.*;
    import javax.swing.*;
    import java.awt.event.*;
    
    public class Project2 implements ActionListener{
        private JFrame MainFrame;
        private JTextField TF1;
        private JLabel Label1, Label2;
        private JPanel Panel1, Panel2, Panel3, Panel4, Panel5;
        private JButton AddButton, SubtractButton, MultiplyButton, DivideButton, ModuloButton,EqualsButton;
        private double D1 = 0, D2;
        private char OpDone = 'e';
        private String UserInput;
    
    public static void main(String[] args)
    { new Project2();
    }
    
    public Project2(){
        MainFrame = new JFrame("Kevin Mabul's Calculator");
        
        Panel1 = new JPanel();
        Panel2 = new JPanel();
        Panel3 = new JPanel();
        Panel4 = new JPanel();
        Panel5 = new JPanel();
        
        Label1 = new JLabel("Patience is a virtue");
        Label2 = new JLabel("Java is a versatile language");
        
        AddButton = new JButton("+");
        AddButton.addActionListener(this);
        SubtractButton = new JButton("-");
        SubtractButton.addActionListener(this);
        MultiplyButton = new JButton("x");
        MultiplyButton.addActionListener(this);
        DivideButton = new JButton("/");
        DivideButton.addActionListener(this);
        ModuloButton = new JButton("%");
        ModuloButton.addActionListener(this);
        EqualsButton = new JButton("=");
        EqualsButton.addActionListener(this);
        
        TF1 = new JTextField("0",15);
        TF1.selectAll();
        TF1.requestFocus();
        
        Panel1.setBackground(Color.YELLOW);
        Panel2.setBackground(Color.GREEN);
        Panel3.setBackground(Color.GREEN);
        Panel4.setBackground(Color.YELLOW);
        
        Panel1.add(Label1);
        Panel2.add(Label2);
        Panel3.add(TF1);
        
        Panel5.add(Panel1);
        Panel5.add(Panel2);
        Panel5.add(Panel3);
        Panel5.add(Panel4);
        
        Panel4.add(AddButton);
        Panel4.add(SubtractButton);
        Panel4.add(MultiplyButton);
        Panel4.add(DivideButton);
        Panel4.add(ModuloButton);
        Panel4.add(EqualsButton);
        
        Panel5.setLayout(new GridLayout(4,1));
        
        MainFrame.setContentPane(Panel5);
        MainFrame.pack();
        MainFrame.show();
        MainFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    }
    
    public void actionPerformed(ActionEvent e){
        {
            UserInput = TF1.getText();
            double D2 = Double.parseDouble(UserInput);
            
            {
                if(OpDone =='a')
                D1 = D1 + D2;
                
                if(OpDone =='s')
                D1 = D1 - D2;
                
                if(OpDone =='m')
                D1 = D1 * D2;
                
                if(OpDone =='d')
                D1 = D1 / D2;
                
                if(OpDone =='r')
                D1 = D1 % D2;
                
                if(OpDone =='e')
                D1 = D2;
            }
            
            if(e.getActionCommand().equals("+"))
            OpDone = 'a';
            if(e.getActionCommand().equals("-"))
            OpDone = 's';
            if(e.getActionCommand().equals("x"))
            OpDone = 'm';
            if(e.getActionCommand().equals("/"))
            OpDone = 'd';
            if(e.getActionCommand().equals("%"))
            OpDone = 'r';
            if(e.getActionCommand().equals("="))
            OpDone = 'e';
            
        }
        UserInput = Double.toString(D1);
        TF1.setText(UserInput);
        TF1.selectAll();
        TF1.requestFocus();
    }
    }

  7. #7
    anirtak143 is offline x10 Sophmore anirtak143 is an unknown quantity at this point
    Join Date
    Mar 2008
    Location
    Philippines
    Posts
    213

    Re: java help with codes (please)..

    woah.. thanks harry... and to everyone, sorry i wasnt able to update this with the compile time error thing.. i was about to do it but this answer came.. thanks..

    Error 1 : missing paranthesis
    Panel5.setLayout(new GridLayout(4,1));

    Error 2 : wrong constructor syntax (without paranthesis)
    public Project2()
    i never knew it was this simple.. anyways, sorry for my stupidity..
    ex-x10er... ^^

+ Reply to Thread

Similar Threads

  1. Java
    By Rhianna in forum Scripts & 3rd Party Apps
    Replies: 4
    Last Post: 03-07-2009, 06:22 PM
  2. Anfy Java Applet Online problems
    By Tharu in forum Scripts & 3rd Party Apps
    Replies: 2
    Last Post: 08-02-2008, 09:05 PM
  3. Mobile phone Codes
    By greeting in forum Computers & Technology
    Replies: 10
    Last Post: 03-28-2008, 07:08 AM
  4. creating a starfield with a java
    By intertec in forum Tutorials
    Replies: 0
    Last Post: 02-08-2008, 01:08 AM
  5. Java Tutorial for Beginners.
    By satheesh in forum Tutorials
    Replies: 0
    Last Post: 10-27-2007, 06:40 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
x10hosting free hosting for the masses
dedicated servers