How can I have a jar file on my gui?
Basically, on my GUI, I want to have a jar file also, so it'll look like this: http://i47.tinypic.com/pqh3k.jpg
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.
Re: How can I have a jar file on my gui?
If i understand correctly, you want to run an app inside your app?
Re: How can I have a jar file on my gui?
Quote:
Originally Posted by
cristian_ny95
If i understand correctly, you want to run an app inside your app?
Correct, how would this be done? (Code example wise).
Re: How can I have a jar file on my gui?
Code :
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.
Re: How can I have a jar file on my gui?
Quote:
Originally Posted by
cristian_ny95
Code :
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.
That's only starting it...
I can do that with getruntime, I want to load it on my JFrame, not as a regular executable.
Re: How can I have a jar file on my gui?
Ok so the one you want to load has a graphical interface or it just outputs to the console?
Re: How can I have a jar file on my gui?
Quote:
Originally Posted by
cristian_ny95
Ok so the one you want to load has a graphical interface or it just outputs to the console?
Basically I want the applet to load on my graphical user interface like this.
JFrame myFrame = new JFrame("test");
myFrame.setSize(850,700);
myFrame.setDefaultCloseOperation(WindowConstants.E XIT_ON_CLOSE);
myFrame.setVisible(true);
//Load jar on GUI here.
Re: How can I have a jar file on my gui?
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?
Re: How can I have a jar file on my gui?
Quote:
Originally Posted by
cristian_ny95
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?
I suppose, I'm trying to load a .jar on my GUI (JFrame), in other terms a GUI in side a GUI I guess.
Re: How can I have a jar file on my 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?
Re: How can I have a jar file on my gui?
Quote:
Originally Posted by
cristian_ny95
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?
To make a macro, for a game.
Re: How can I have a jar file on my gui?
Re: How can I have a jar file on my gui?
Yes i know im still researching
1 Attachment(s)
Re: How can I have a jar file on my gui?
Ok Java is bundled with a utility called AppletViewer
Code :
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);
}
}
HTML Code:
<HTML>
<BODY>
<applet code="Myapplet",height="200" width="200">
</applet>
</BODY>
</HTML>
C:\javac> javac Myapplet.java
C:\javac>appletviewer Myapplet.html
and the output is
Attachment 1303
Re: How can I have a jar file on my gui?
Quote:
Originally Posted by
cristian_ny95
Ok Java is bundled with a utility called AppletViewer
Code :
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);
}
}
HTML Code:
<HTML>
<BODY>
<applet code="Myapplet",height="200" width="200">
</applet>
<br /><div style="z-index:3" class="shade" align="center"></div>
<script type="text/javascript"><!--
var _gaq = _gaq || [];
_gaq.push(
['_setAccount', 'UA-5573417-2'],
['_trackPageview']
);
(function() {
var ga = document.createElement('script');
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
ga.setAttribute('async', 'true');
document.documentElement.firstChild.appendChild(ga);
})();
//-->
</script>
</BODY>
</HTML>
C:\javac> javac Myapplet.java
C:\javac>appletviewer Myapplet.html
and the output is
Attachment 1303
That's not what I want lol, I basically want another java applet running on that gui where it says 'this is my first java applet', get it? :/
Re: How can I have a jar file on my gui?
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.
Re: How can I have a jar file on my gui?
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.
Re: How can I have a jar file on my gui?
Quote:
Originally Posted by
Norm
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.
Could you please give me an example?
Re: How can I have a jar file on my gui?
The code could be something like this:
Code :
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