Basically, on my GUI, I want to have a jar file also, so it'll look like this:
How would I do that?
Please keep in mind, I'm new to Jframe & GUI making, I normally use console, but this is a must to do this.
Welcome to the Java Programming Forums
The professional, friendly Java community. 21,500 members and growing!
The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.
>> REGISTER NOW TO START POSTING
Members have full access to the forums. Advertisements are removed for registered users.
Basically, on my GUI, I want to have a jar file also, so it'll look like this:
How would I do that?
Please keep in mind, I'm new to Jframe & GUI making, I normally use console, but this is a must to do this.
If i understand correctly, you want to run an app inside your app?
package yourpackage; import java.io.IOException; import java.io.InputStream; import java.util.logging.Level; import java.util.logging.Logger; public class YourClass { public static void main(String[] args) { try { Process jarProcess = Runtime.getRuntime().exec(new String[]{"java", "-jar", "Path To Your .jar File"}); jarProcess.waitFor(); InputStream inputStream = jarProcess.getInputStream(); byte[] inputByte = new byte[inputStream.available()]; inputStream.read(inputByte, 0, inputByte.length); System.out.println(new String(inputByte)); } catch (InterruptedException ex) { Logger.getLogger(YourClass.class.getName()).log(Level.SEVERE, null, ex); } catch (IOException ex) { Logger.getLogger(YourClass.class.getName()).log(Level.SEVERE, null, ex); } } }
You can try this, new String(inputByte) is the console output text of the selected .jar.
Ok so the one you want to load has a graphical interface or it just outputs to the console?
Last edited by testingjava; June 29th, 2012 at 03:35 PM.
Yes i understand that but are you trying to load another gui inside a gui or are you trying to load the output/console of the jar inside a gui?
Im not sure if you can do this in Java, Im going to do some research on this, just out of curiosity why would you want to do this?
Still need help:/
Yes i know im still researching
Ok Java is bundled with a utility called AppletViewer
import java.applet.*; import java.awt.*; public class Myapplet extends Applet{ String str; public void init(){ str = "This is my first applet"; } public void paint(Graphics g){ g.drawString(str, 50,50); } }
C:\javac> javac Myapplet.javaHTML Code:<HTML> <BODY> <applet code="Myapplet",height="200" width="200"> </applet> </BODY> </HTML>
C:\javac>appletviewer Myapplet.html
and the output is
applet.gif
The applet class extends the Panel class and an instance of the applet class could be added to any container.
Create an instance of a JFrame, create an instance of the applet and add it to the JFrame. Call the appropriate applet methods like a browser would and you should be able to "execute" an applet in the GUI provided by a JFrame.
If you don't understand my answer, don't ignore it, ask a question.
Are you asking how to use the Swing components of one jar in a JFrame you have created? You need access to the API of the jar, to add the jar to your classpath, and then construct the appropriate components based upon the API and add them to your JFrame as you would any other component. If all you have is a jar with no documentation, you do not know the class file structure, and thus cannot construct the appropriate objects to add to your user interface.
The code could be something like this:
Applet anApplt = new Applet(); // Create an instance of the applet JFrame jf = new JFrame(); // create frame to show applet in jf.add(anApplt); // add instance to jframe anApplt.init(); // call applet's init
If you don't understand my answer, don't ignore it, ask a question.