Results 1 to 10 of 10
  1. #1
    claudius753 is offline Member
    Join Date
    Mar 2010
    Posts
    8
    Rep Power
    0

    Default Stand Alone Compiler?

    Hey all,

    I've had to make a few changes to a java app for school. I'm not on my home computer and the one I'm on doesn't have Java. I don't have admin rights, so no way to install the compiler.

    Is there a stand alone compiler that I can just run from a folder or something so I can do a quick check on my program?

    Thanks.

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

  3. #3
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,371
    Blog Entries
    1
    Rep Power
    20

    Default

    JXXX is one of them. I've use it several times, seems okay for simple applications. Could be fine with complex applications as well, but I've never tried it.

    I think best way is to contact your responsible person in your school laboratory and ask him/her to install a compiler there. What's the usage without having those things of a laboratory. :)

  4. #4
    claudius753 is offline Member
    Join Date
    Mar 2010
    Posts
    8
    Rep Power
    0

    Default

    Quote Originally Posted by Eranga View Post
    JXXX is one of them. I've use it several times, seems okay for simple applications. Could be fine with complex applications as well, but I've never tried it.

    I think best way is to contact your responsible person in your school laboratory and ask him/her to install a compiler there. What's the usage without having those things of a laboratory. :)
    I take classes online from my school, which is actually about a 2 hour drive from me.

    I tried the JXXX compiler, and it comes back with no errors, but I can't get it to run when I download the class file it gives me. I'm not used to Windows, I normally use a Mac.

    This is the error I get. I don't know if it is a problem with the computer I'm on now or with my code.

    Java Code:
    Exception in thread "main" java.lang.NoClassDefFoundError: C:\Exercise15_4
    Caused by: java.lang.ClassNotFoundException: C:\Exercise15_4
            at java.net.URLClassLoader$1.run(Unknown Source)
            at java.security.AccessController.doPrivileged(Native Method)
            at java.net.URLClassLoader.findClass(Unknown Source)
            at java.lang.ClassLoader.loadClass(Unknown Source)
            at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
            at java.lang.ClassLoader.loadClass(Unknown Source)
            at java.lang.ClassLoader.loadClassInternal(Unknown Source)
    Could not find the main class: C:\Exercise15_4.  Program will exit.

  5. #5
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,371
    Blog Entries
    1
    Rep Power
    20

    Default

    Can you post your code here if it's not too long? Are you sure that your class name and physical file name is exactly the same and the main method contains in that class?

  6. #6
    claudius753 is offline Member
    Join Date
    Mar 2010
    Posts
    8
    Rep Power
    0

    Default

    Java Code:
    // Exercise15_4.java: Perform add, subtract, multiply, and divide on
    // double values
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    
    public class Exercise15_4 extends JFrame implements ActionListener {
      // Text fields for Number 1, Number 2, and Result
      private JTextField jtfNum1, jtfNum2, jtfResult;
    
      // Buttons "Add", "Subtract", "Multiply" and "Divide"
      private JButton jbtAdd, jbtSub, jbtMul, jbtDiv, jbtMod, jbtPow, jbtSqu, jbtInv;
    
      // Main Method
      public static void main(String[] args) {
        Exercise15_4 frame = new Exercise15_4();
        frame.pack();
        frame.setTitle("Exercise15_4");
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.setVisible(true);
      }
    
      // Default Constructor
      public Exercise15_4() {
        // Panel p1 to hold text fields and labels
        JPanel p1 = new JPanel();
        p1.setLayout(new FlowLayout());
        p1.add(new JLabel("Number 1"));
        p1.add(jtfNum1 = new JTextField(3));
        p1.add(new JLabel("Number 2"));
        p1.add(jtfNum2 = new JTextField(3));
        p1.add(new JLabel("Result"));
        p1.add(jtfResult = new JTextField(8));
        jtfResult.setEditable(false);
        jtfResult.setHorizontalAlignment(SwingConstants.RIGHT);
    
        // Panel p2 - Add, Subtract, Multiply, Devide
        JPanel p2 = new JPanel();
        p2.setLayout(new FlowLayout());
        p2.add(jbtAdd = new JButton("Add"));
        p2.add(jbtSub = new JButton("Subtract"));
        p2.add(jbtMul = new JButton("Multiply"));
        p2.add(jbtDiv = new JButton("Divide"));
    
        // Panel p# - Modulo, Power, Square, Inverse
        JPanel p3 = new JPanel();
        p3.setLayout(new FlowLayout());
        p3.add(jbtMod = new JButton("Modulo"));
        p3.add(jbtPow = new JButton("Power"));
        p3.add(jbtSqu = new JButton("Square"));
        p3.add(jbtInv = new JButton("Inverse"));
        // Set mnemonic keys
        jbtAdd.setMnemonic('A');
        jbtSub.setMnemonic('S');
        jbtMul.setMnemonic('M');
        jbtDiv.setMnemonic('D');
        jbtMod.setMnemonic('O');
        jbtPow.setMnemonic('P');
        jbtSqu.setMnemonic('Q');
        jbtInv.setMnemonic('I');
    
        // Add panels to the frame
        getContentPane().setLayout(new BorderLayout());
        getContentPane().add(p1, BorderLayout.CENTER);
        getContentPane().add(p2, BorderLayout.SOUTH);
        getContentPane().add(p3, BorderLayout.SOUTH);
        // Register listeners
        jbtAdd.addActionListener(this);
        jbtSub.addActionListener(this);
        jbtMul.addActionListener(this);
        jbtDiv.addActionListener(this);
        jbtMod.addActionListener(this);
        jbtPow.addActionListener(this);
        jbtSqu.addActionListener(this);
        jbtInv.addActionListener(this);
      }
    
      // Handle ActionEvent from buttons and menu items
      public void actionPerformed(ActionEvent e) {
        String actionCommand = e.getActionCommand();
    
        // Handle button events
        if (e.getSource() instanceof JButton) {
          if ("Add".equals(actionCommand))
            calculate('+');
          else if ("Subtract".equals(actionCommand))
            calculate('-');
          else if ("Multiply".equals(actionCommand))
            calculate('*');
          else if ("Divide".equals(actionCommand))
            calculate('/');
          else if ("Modulo".equals(actionCommand))
            calculate('%');
          else if ("Power".equals(actionCommand))
            calculate('P');
          else if ("Square".equals(actionCommand))
            calculate('S');
          else if ("Inverse".equals(actionCommand))
            calculate('I');
        }
      }
    
      // Calculate and show the result in jtfResult
      private void calculate(char operator) {
        // Obtain Number 1 and Number 2
        double num1 = new Double(jtfNum1.getText().trim()).doubleValue();
        double num2 = new Double(jtfNum2.getText().trim()).doubleValue();
        double result = 0;
    
        // Perform selected operation
        switch (operator) {
          case '+': result = num1 + num2;
                    break;
          case '-': result = num1 - num2;
                    break;
          case '*': result = num1 * num2;
                    break;
          case '/': result = num1 / num2;
                    break;
          case '%': result = num1 % num2;
                    break;
          case 'P': result = Math.pow(num1, num2);
                    break;
          case 'S': result = num1 * num1;
                    break;
          case 'I': result = 1.0 / num1;
        }
    
        // Set result in jtfResult
        jtfResult.setText(String.valueOf(result));
      }
    }

  7. #7
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,371
    Blog Entries
    1
    Rep Power
    20

  8. #8
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,371
    Blog Entries
    1
    Rep Power
    20

  9. #9
    claudius753 is offline Member
    Join Date
    Mar 2010
    Posts
    8
    Rep Power
    0

    Default

    I think the problem must be with the JVM on the machine I am using then. I can compile and create the class file with no errors on JXXX, but I can't run it on my JVM locally.

    I'll have to try when I get access to my personal laptop.

  10. #10
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,371
    Blog Entries
    1
    Rep Power
    20

Similar Threads

  1. Stand alone applications? HELP!!!
    By Atriamax in forum Eclipse
    Replies: 6
    Last Post: 09-11-2009, 02:56 AM
  2. What does String args[] stand for?
    By Addez in forum New To Java
    Replies: 7
    Last Post: 08-19-2009, 11:24 AM
  3. compiler,JIT compiler & interpreter
    By gamilah in forum New To Java
    Replies: 4
    Last Post: 11-04-2008, 01:32 AM
  4. Stand Alone Applications?
    By djpg2000 in forum New To Java
    Replies: 5
    Last Post: 09-05-2008, 08:23 PM
  5. Could some plz tell me how to write a stand alone
    By quickfingers in forum New To Java
    Replies: 25
    Last Post: 06-28-2008, 05:22 AM

Posting Permissions

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