Results 1 to 20 of 20
Thread: Running Interfaces
- 06-20-2011, 10:16 PM #1
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?
- 06-20-2011, 10:21 PM #2
- Join Date
- Jan 2011
- Location
- Richmond, Virginia
- Posts
- 3,069
- Blog Entries
- 3
- Rep Power
- 7
Interface? Do you mean jar? The two things are quite different.
- 06-20-2011, 10:46 PM #3
What is the "it" you click on?When I try and click on it
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.
- 06-20-2011, 10:48 PM #4
No I mean once you create a custom interface how do you run it outside of netbeans?
- 06-20-2011, 10:50 PM #5
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.
- 06-20-2011, 10:52 PM #6
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
- 06-20-2011, 10:53 PM #7
What is the "it" you click on?
- 06-20-2011, 10:55 PM #8
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.
- 06-20-2011, 10:58 PM #9
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
- 06-20-2011, 11:03 PM #10
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
}
- 06-20-2011, 11:07 PM #11
Please explain what your problem is.but that doesn't solve my problem
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?
- 06-20-2011, 11:10 PM #12
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.
- 06-20-2011, 11:12 PM #13
What error messages do you get?
- 06-20-2011, 11:16 PM #14
- 06-20-2011, 11:18 PM #15
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.
- 06-20-2011, 11:22 PM #16
- 06-20-2011, 11:25 PM #17
Generated code can put you way out on a limb. You end up being stuck and can only run the code in the IDE.
- 06-20-2011, 11:29 PM #18
- 06-21-2011, 09:41 AM #19
Moderator
- Join Date
- Apr 2009
- Posts
- 10,448
- Rep Power
- 16
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:
so using it to mean the gui just confuses matters.Java Code:public interface MyInterface { void doSomething(); }
- 07-05-2011, 04:32 AM #20
Similar Threads
-
Interfaces
By dalu in forum New To JavaReplies: 4Last Post: 04-26-2011, 12:22 PM -
Interfaces
By blug in forum New To JavaReplies: 3Last Post: 03-08-2011, 04:01 AM -
Problem in running Java swing wizard in jre 1.6 while it is running in jre 1.4
By Sanjay Dwivedi in forum AWT / SwingReplies: 0Last Post: 08-26-2009, 01:03 PM -
interfaces..
By sireesha in forum New To JavaReplies: 5Last Post: 01-16-2008, 05:52 PM -
Interfaces
By Kavana Krishnappa in forum New To JavaReplies: 7Last Post: 12-11-2007, 04:28 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks