Results 1 to 20 of 20
  1. #1
    anthropamorphic's Avatar
    anthropamorphic is offline Senior Member
    Join Date
    Jun 2011
    Posts
    136
    Rep Power
    0

    Default Running Interfaces

    Hello, I was wondering if anyone could help me out. I have build a custom interface in netbeans, but I'm not sure how to run it outside of netbeans? When I try and click on it it says:
    The Java class file “Convertergui.class” could not be launched.

    How would I make an interface runnable?

  2. #2
    sunde887's Avatar
    sunde887 is offline Moderator
    Join Date
    Jan 2011
    Location
    Richmond, Virginia
    Posts
    3,069
    Blog Entries
    3
    Rep Power
    8

    Default

    Interface? Do you mean jar? The two things are quite different.

  3. #3
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,886
    Rep Power
    25

    Default

    When I try and click on it
    What is the "it" you click on?
    You have to do some magic to execute .class files via a double click.
    In a command prompt you would enter:
    java Convertergui
    to execute that class.

  4. #4
    anthropamorphic's Avatar
    anthropamorphic is offline Senior Member
    Join Date
    Jun 2011
    Posts
    136
    Rep Power
    0

    Default

    No I mean once you create a custom interface how do you run it outside of netbeans?

  5. #5
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,886
    Rep Power
    25

    Default

    What is a "custom interface"? Can you describe it in turns of the files that it consists of? class, jar or ???

    What is the "it" you click on? A file on a disk. An icon in netbeans. An button in a browser html page.

  6. #6
    anthropamorphic's Avatar
    anthropamorphic is offline Senior Member
    Join Date
    Jun 2011
    Posts
    136
    Rep Power
    0

    Default

    I can run class files on my mac just by double clicking. I know on windows you can't run class files, but on mac you can. Anyway I tried running it through terminal and it still doesn't work. I can run it in netbeans, but no outside of netbeans

  7. #7
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,886
    Rep Power
    25

    Default

    What is the "it" you click on?

  8. #8
    anthropamorphic's Avatar
    anthropamorphic is offline Senior Member
    Join Date
    Jun 2011
    Posts
    136
    Rep Power
    0

    Default

    I clicked on every single class file that was in the project and none of them worked which is odd since the Convertergui.class works when I run it in netbeans. Oh and it's a java interface if you wanted to know specifically what I meant by custom interface.

  9. #9
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,886
    Rep Power
    25

    Default

    Do you mean by "interface" what the program does? Not what parts it is made of.
    If you want to be able to click on a class file and have it execute on Windows, here's how:

    Make a R-C command for class files with this commandline:

    C:\BatchFiles\ExecClass.bat "%1"

    The ExecClass.bat file:
    REM Execute a java class file - need to strip extension
    echo filename is %~n1
    java %~n1
    MORE

  10. #10
    anthropamorphic's Avatar
    anthropamorphic is offline Senior Member
    Join Date
    Jun 2011
    Posts
    136
    Rep Power
    0

    Default

    OK thanks for the code, but that doesn't solve my problem. I am not sure how to really explain it but heres my code. (It works in netbeans but doesn't work anywhere else I tried running it through console still doesn't work. I normally don't use netbeans so it is probably just me messing something up. The program converts Celsius to Fahrenheit and visa versa.)


    /*
    * To change this template, choose Tools | Templates
    * and open the template in the editor.
    */

    /*
    * Convertergui.java
    *
    * Created on May 25, 2010, 9:33:00 PM
    */
    package converter;

    /**
    *
    * @author alec
    */
    public class Convertergui extends javax.swing.JFrame {

    /** Creates new form Convertergui */
    public Convertergui() {
    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() {

    degreetext = new javax.swing.JTextField();
    celsius = new javax.swing.JLabel();
    convert = new javax.swing.JButton();
    fahrenheit = new javax.swing.JLabel();
    ftext = new javax.swing.JTextField();
    clear = new javax.swing.JButton();
    convert2 = new javax.swing.JButton();

    setDefaultCloseOperation(javax.swing.WindowConstan ts.EXIT_ON_CLOSE);
    setTitle("Celsuis To Fahrenheit");

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

    celsius.setText("Celsius");

    convert.setText("Convert");
    convert.addActionListener(new java.awt.event.ActionListener() {
    public void actionPerformed(java.awt.event.ActionEvent evt) {
    convertActionPerformed(evt);
    }
    });

    fahrenheit.setText("Fahrenheit");

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

    clear.setText("Clear");
    clear.addActionListener(new java.awt.event.ActionListener() {
    public void actionPerformed(java.awt.event.ActionEvent evt) {
    clearActionPerformed(evt);
    }
    });

    convert2.setText("Convert");
    convert2.addActionListener(new java.awt.event.ActionListener() {
    public void actionPerformed(java.awt.event.ActionEvent evt) {
    convert2ActionPerformed(evt);
    }
    });

    org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(getContentPane());
    getContentPane().setLayout(layout);
    layout.setHorizontalGroup(
    layout.createParallelGroup(org.jdesktop.layout.Gro upLayout.LEADING)
    .add(layout.createSequentialGroup()
    .addContainerGap()
    .add(layout.createParallelGroup(org.jdesktop.layou t.GroupLayout.LEADING)
    .add(convert)
    .add(degreetext, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 89, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
    .add(layout.createParallelGroup(org.jdesktop.layou t.GroupLayout.TRAILING)
    .add(layout.createSequentialGroup()
    .add(26, 26, 26)
    .add(clear)
    .addPreferredGap(org.jdesktop.layout.LayoutStyle.R ELATED, 22, Short.MAX_VALUE)
    .add(convert2))
    .add(layout.createSequentialGroup()
    .addPreferredGap(org.jdesktop.layout.LayoutStyle.R ELATED)
    .add(ftext, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 89, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)))
    .addContainerGap())
    .add(layout.createSequentialGroup()
    .add(29, 29, 29)
    .add(fahrenheit)
    .addPreferredGap(org.jdesktop.layout.LayoutStyle.R ELATED, 164, Short.MAX_VALUE)
    .add(celsius)
    .add(45, 45, 45))
    );
    layout.setVerticalGroup(
    layout.createParallelGroup(org.jdesktop.layout.Gro upLayout.LEADING)
    .add(layout.createSequentialGroup()
    .addContainerGap()
    .add(layout.createParallelGroup(org.jdesktop.layou t.GroupLayout.BASELINE)
    .add(fahrenheit)
    .add(celsius))
    .add(18, 18, 18)
    .add(layout.createParallelGroup(org.jdesktop.layou t.GroupLayout.BASELINE)
    .add(ftext, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
    .add(degreetext, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
    .addPreferredGap(org.jdesktop.layout.LayoutStyle.R ELATED, 46, Short.MAX_VALUE)
    .add(layout.createParallelGroup(org.jdesktop.layou t.GroupLayout.BASELINE)
    .add(convert, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 40, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
    .add(convert2, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 40, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
    .add(clear, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 40, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
    .addContainerGap())
    );

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

    private void degreetextActionPerformed(java.awt.event.ActionEve nt evt) {
    // TODO add your handling code here:
    }

    private void convertActionPerformed(java.awt.event.ActionEvent evt) {
    int tempFahr = (int) ((Double.parseDouble((degreetext.getText()))
    -32) * 5/9);
    ftext.setText(tempFahr + "");


    }

    private void ftextActionPerformed(java.awt.event.ActionEvent evt) {
    // TODO add your handling code here:
    }

    private void clearActionPerformed(java.awt.event.ActionEvent evt) {

    ftext.setText("");
    degreetext.setText("");
    }

    private void convert2ActionPerformed(java.awt.event.ActionEvent evt) {
    int tempcel = (int) ((Double.parseDouble((ftext.getText()))
    * 9/5) + 32);
    degreetext.setText(tempcel + "");
    }

    /**
    * @param args the command line arguments
    */
    public static void main(String args[]) {
    java.awt.EventQueue.invokeLater(new Runnable() {

    public void run() {
    new Convertergui().setVisible(true);
    }
    });
    }
    // Variables declaration - do not modify
    private javax.swing.JLabel celsius;
    private javax.swing.JButton clear;
    private javax.swing.JButton convert;
    private javax.swing.JButton convert2;
    private javax.swing.JTextField degreetext;
    private javax.swing.JLabel fahrenheit;
    private javax.swing.JTextField ftext;
    // End of variables declaration
    }

  11. #11
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,886
    Rep Power
    25

    Default

    but that doesn't solve my problem
    Please explain what your problem is.
    Without some trick like the code I gave you, it is difficult to execute .class files on Windows.
    Have you tried the command prompt example I showed you?

  12. #12
    anthropamorphic's Avatar
    anthropamorphic is offline Senior Member
    Join Date
    Jun 2011
    Posts
    136
    Rep Power
    0

    Default

    I'm not on windows I'm on a mac which you can just double click class files and run them. My problem is is that I can run my program in netbeans, but when I go to run it through terminal(mac's console), in a jar, or just by clicking the class file it won't run.

  13. #13
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,886
    Rep Power
    25

    Default

    What error messages do you get?

  14. #14
    anthropamorphic's Avatar
    anthropamorphic is offline Senior Member
    Join Date
    Jun 2011
    Posts
    136
    Rep Power
    0

    Default

    Quote Originally Posted by Norm View Post
    What error messages do you get?
    When I'm not in netbeans I get this error message
    The Java class file “Convertergui.class” could not be launched.

  15. #15
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,886
    Rep Power
    25

    Default

    Sorry, I don't know anything about a mac and what error messages mean there.

    The code you posted uses classes the are not part of standard java. I can't compile it.

  16. #16
    anthropamorphic's Avatar
    anthropamorphic is offline Senior Member
    Join Date
    Jun 2011
    Posts
    136
    Rep Power
    0

    Default

    Quote Originally Posted by Norm View Post
    Sorry, I don't know anything about a mac and what error messages mean there.

    The code you posted uses classes the are not part of standard java. I can't compile it.
    Yah I know it's really odd I couldn't compile it in eclipse either and for the most part the code was generated by netbeans. So I guess I'll just stick to eclipse instead of netbeans for now on.

  17. #17
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,886
    Rep Power
    25

    Default

    Generated code can put you way out on a limb. You end up being stuck and can only run the code in the IDE.

  18. #18
    anthropamorphic's Avatar
    anthropamorphic is offline Senior Member
    Join Date
    Jun 2011
    Posts
    136
    Rep Power
    0

    Default

    Quote Originally Posted by Norm View Post
    Generated code can put you way out on a limb. You end up being stuck and can only run the code in the IDE.
    Oh well thanks for the help.

  19. #19
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,224
    Rep Power
    20

    Default

    I'm guessing a bit here, but I suspect that the launcher the Mac uses to run a .class file will require that class file to have a main() method, since that's the entry point for an application. That class up there does not have a main() method, so it cannot be launched. In Netbeans I would bet the Gui editor has a dummy main() it uses to bootstrap a JFrame.

    Also, when posting code can you please use code tags since unformatted code is very hard to read.

    And a point to note. The term "interface" in Java has a specific meaning to do with the code:
    Java Code:
    public interface MyInterface {
        void doSomething();
    }
    so using it to mean the gui just confuses matters.

  20. #20
    anthropamorphic's Avatar
    anthropamorphic is offline Senior Member
    Join Date
    Jun 2011
    Posts
    136
    Rep Power
    0

    Default

    I figured it out just needed to clean and build it (you didn't need to do that in eclipse)

Similar Threads

  1. Interfaces
    By dalu in forum New To Java
    Replies: 4
    Last Post: 04-26-2011, 01:22 PM
  2. Interfaces
    By blug in forum New To Java
    Replies: 3
    Last Post: 03-08-2011, 05:01 AM
  3. Replies: 0
    Last Post: 08-26-2009, 02:03 PM
  4. interfaces..
    By sireesha in forum New To Java
    Replies: 5
    Last Post: 01-16-2008, 06:52 PM
  5. Interfaces
    By Kavana Krishnappa in forum New To Java
    Replies: 7
    Last Post: 12-11-2007, 05:28 PM

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
  •