Running a Java application from a Swing GUI

Hi,
I was wondering if there is a simple way to run a Java application from a GUI built with Swing. I would presume there would be, because the Swing GUI is a Java application itself, technically.
So, I want a user to click a button on my GUI, and then have another Java application, which is in the same package with the same classpaths and stuff, run.
Is there a simple way to do this? Do any tutorials exist on this? If someone could give me any advice, or even a simple "yes this is possible, and it is simple" or "this is possible, but difficult" or "no this is not possible" answer, I would appreciate it. If anyone needs more information, I'll be happy to provide it.
Thanks,
Dan

I don't know if it is possible to run the main method from another Java app by simply calling it...
But you could just copy and paste the stuff from your main method into a new static method called something like runDBQuery and have all the execution run from there.
How does that sound? Is it possible?
What I'm suggeting is:
Original
public class DBQuery{
public static void methodA(){
public static void doQuery(){
methodA();
public static void main(String[] args){
// Your method calls
//Your initializing
doQuery();
}Revised:
public class DBQuery{
public static void methodA(){
public static void doQuery(){
methodA();
public static void doMyQuery(){
// Your method calls
//Your initializing
doQuery();
// No main needed!!
//public static void main(String[] args){
// Your method calls
//doQuery();
//}

Similar Messages

  • Running a java application from a java application

    hello ,
    please who knows how i can run a java application 'B' from inside another java application 'A' and get the error messages (if any) from the application 'B'

    how are you executing application B from application A? Please explain the java code you are using?

  • Running a Java application from web browser

    Hi,
    I'm not sure if this is the right place to put this, and it probably isn't, but I don't really know what else to do at the moment.
    I have a problem. I've written all these nice and pretty Java applications that do all this complicated junk that makes me proud. However...I have no idea how to actually run those applications.
    I've looked at guides on Java applets, Java Web Start, Java Server Pages, etc, and I still am not sure. JSP looked like the best option, until I figured out I can't use it with my web server. So, I've pretty much hit a wall here.
    If anyone could shed some light on this, I would be very appreciative. All I want is for a certain application to run when a user clicks a button on a simple HTML page. That's all I want...yet it seems so hard.
    Is there a simple way to do this, or do I need to use JWS or something and configure all these JARs and JNLP and classpaths and everything under the sun (no pun intended)?
    Again, I apologize if there is a better forum for this; I am just very confused right now and feel like I've hit a brick wall. If anyone can give me any advice, or point me in a good (easy) direction, I would truly be grateful.

    If anyone could shed some light on this, I would be
    very appreciative. All I want is for a certain
    application to run when a user clicks a button on a
    simple HTML page. That's all I want...yet it seems so
    hard. There's a lot of hidden details that make it so hard. What computer will run the application when the button is clicked? If the application will run on the client computer (within the web browser) there has to be a mechanism for allowing arbitrary code to be downloaded, verified and executed on any number of different target platforms. This is the problem that Java Applets address. Mostly this is a security issue, since a simple HTML page being able to run arbitary code without user interaction or approval is going to cause the world to be overrun by computer virii. There's also the multi-platform issue, but in many cases that can be avoided by requiring the client to use a single platform (the MS approach).
    If the application will run on the server, then the client code is much less difficult, as only a basic web browser is needed, and the server code is complicated, since it needs to keep track of multiple clients at the same time and process data in a request-response fashion.
    From the end-user's point-of-view, it certainly is simple though. Press the button and voila!
    "Any technology which is distinguishable from magic is insufficiently advanced"
    Brian

  • Error when running "Run as" Java application from NWDS

    Dear All,
    I am trying to run the following .java proggie...
    Thanks for that. By the way, I am now trying to compile the following .java program.....
    Created on 01-Oct-2007
    To change the template for this generated file go to
    Window>Preferences>Java>Code Generation>Code and Comments
    @author chris.jackson
    To change the template for this generated type comment go to
    Window>Preferences>Java>Code Generation>Code and Comments
    import com.sap.lcr.api.cimclient.CIMClient;
    import com.sap.lcr.api.cimclient.CIMClientHandle;
    import com.sap.lcr.api.cimclient.CIMOMClient;
    import com.sap.lcr.api.cimclient.ClientFactory;
    import com.sap.lcr.api.sapmodel.SAP_AppServJCODestination;
    import com.sap.lcr.api.sapmodel.SAP_JCODestination;
    import com.sap.lcr.api.sapmodel.SAP_JCODestinationAccessor;
    import com.sap.lcr.api.sapmodel.SAP_MsgServJCODestination;
    import com.sap.mw.jco.JCO;
    import com.tssap.dtr.client.lib.protocol.URL;
    public class sldpoke {
    public void main() {
    ClientFactory factory = ClientFactory.newInstance();
    try {
    final URL url = new URL("http://ex1d002a.eu.unilever.com:58300/sld/cimom");
    String sldUsername = "cjacks01";
    String sldPassword = "password";
    CIMOMClient cimomClient = factory.createClient (url, sldUsername, sldPassword);
    CIMClient cc = new CIMClient(cimomClient);
    CIMClientHandle cch = (CIMClientHandle) cc;
    SAP_JCODestinationAccessor jcoAccessor = new SAP_JCODestinationAccessor(cc);
    SAP_JCODestination[] jcoDestinations = jcoAccessor.enumerateSAP_JCODestinationInstances();
    JCO.Client jcoClient = null;
    String user = null;
    String pwd = null;
    // iterate over all destinations
    for (int i = 0; i < jcoDestinations.length; i++)
    SAP_JCODestination jcoDestination = jcoDestinations;
    user = jcoDestination.getLogonUser();
    pwd = jcoDestination.getLogonPwd();
    if (jcoDestination instanceof SAP_AppServJCODestination)
    SAP_AppServJCODestination jcoDest = (SAP_AppServJCODestination) jcoDestination;
    jcoClient = JCO.createClient(jcoDest.getLogonBCClient(),
    user,
    pwd,
    jcoDest.getLogonLanguage(),
    jcoDest.getAppServHost(),
    jcoDest.getAppServNumber());
    else if (jcoDestination instanceof SAP_MsgServJCODestination)
    SAP_MsgServJCODestination jcoDest = (SAP_MsgServJCODestination) jcoDestination;
    jcoClient = JCO.createClient(jcoDest.getLogonBCClient(),
    user,
    pwd,
    jcoDest.getLogonLanguage(),
    jcoDest.getMsgServHost(),
    jcoDest.getSAPSystemName(),
    jcoDest.getLogonGroup());
    } catch (Exception e) {
    and I am getting the message "The selection does not contain a main type". The class contains a 'main' function so I am at a loss as to what the problem is. Any ideas how I progress?
    Kind Regards
    Chris Jackson.

    Hi! Jakson,
       to run a Stand-alone Java application, we must have one main() method like...
    public static void main(String args[]){ }
    i can't see this main() method on your appliation.
    regards,
    Mithileshwar

  • Running a Java application from a web page?

    Hi
    Could anyone please tell me how do i launch a java application (which is not an applet) by clicking a button on a web page?
    Does the application have to be converted to .exe? And if so how do i do it?
    The application is on my PC not on a server.
    Thanking u in advance for ur help.

    Hi dins19
    Java WebStart is a pretty good technology for that purpose. Installing and launching a Java application on a local machine has always been a burdensome task. JWS really remedies that. The cool thing about JWS is that it works for both web and client applications. The technology introduces a new file format called jnlp which tells a program called "Java Web Start Application Manager" where the resources, typically a single jar file, are located. Check out
    http://java.sun.com/products/javawebstart/
    for a nifty demo.
    Hope this has been of some help.
    Morten Hjerl-Hansen

  • Running a java application from different directory

    I have the file in my
    c:/Folder/Program.java
    I want to compile and run it from D:/ (drive)i.e from different directory.
    Thanks in advance,
    Praveen.

    javac -cp c:\Folder c:\Folder\Program.java
    java -cp c:\Folder Program

  • Calling Java application from servlet

    Hi !
    I'm trying to run a Java application from within a servlet with Tomcat 4. I'm using the Runtime.getRuntime ().exec () method. So the application is run in a different JVM as a subprocess of the servlet. I use ObjectInputStream and ObjectOutputStream and a serializable object to enable communication between the servlet and the application.
    I tested the application and the serializable object with another Java application that works as the caller and it works fine. However, replacing the caller application with the servlet I get a StreamCorruptedException. The structure of the caller application and the servlet is the same.
    My questions are:
    - Is there something I should configure in Tomcat to create a subprocess ?
    - What is the cause of the StreamCorruptedException ? How do I get it with the servlet and not with the application ?
    - Should I use an environment with the call to Runtime.getRuntime ().exec () ? How do I use it ?
    - Is the called application forced to run in my servlet's context ?
    - Is there a better way to do this ?
    Thanks to all

    Here's my code:
    1. The serializable object:
    // Object Obj
    import java.io.*;
    public class Obj implements Serializable
    public int n;
    public Obj ()
    n = 0;
    public Obj (int n)
    this.n = n;
    public String toString ()
    return getClass ().getName () + " -> (n = " + n + ")";
    2. The application Sub (subprogram)
    // Application Sub
    import java.io.*;
    public class Sub
    private static File f;
    private static FileWriter fw;
    public static void main (String [] args)
    throws IOException, InterruptedException, ClassNotFoundException
    ObjectInputStream ois;
    ObjectOutputStream oos;
    Obj obj;
    ois = new ObjectInputStream (System.in);
    obj = (Obj) ois.readObject ();
    f = new File ("Sub.txt");
    fw = new FileWriter (f);
    fw.write (obj.toString ());
    fw.close ();
    oos = new ObjectOutputStream (System.out);
    oos.writeObject (obj);
    ois.close ();
    oos.close ();
    3. The application AMain (caller application)
    // Application AMain
    import java.io.*;
    class AMain
    private static File f;
    private static FileWriter fw;
    public static void main (String [] args)
    throws IOException, ClassNotFoundException
    Runtime r;
    Process p;
    ObjectInputStream ois;
    ObjectOutputStream oos;
    Obj obj, obj2;
    r = Runtime.getRuntime ();
    p = r.exec ("java Sub");
    oos = new ObjectOutputStream (p.getOutputStream ());
    obj = new Obj (5);
    oos.writeObject (obj);
    oos.flush ();
    B.comunica (obj);
    System.out.println ("AMain sends to Sub: " + obj.toString ());
    try
    p.waitFor ();
    catch (InterruptedException e)
    System.out.println ("Subprogram was interrupted");
    System.out.println (e.toString ());
    ois = new ObjectInputStream (p.getInputStream ());
    System.out.print ("Sub sends to AMain: ");
    obj2 = (Obj) ois.readObject ();
    System.out.println (" " + obj2.toString ());
    oos.close ();
    ois.close ();
    p.destroy ();
    4. The servlet SMain (the calling servlet)
    // Servlet SMain
    import javax.servlet.*;
    import javax.servlet.http.*;
    import java.sql.*;
    import java.io.*;
    import java.util.*;
    public class SMain extends HttpServlet
    public void doPost (HttpServletRequest req, HttpServletResponse res)
    throws ServletException, IOException
    Runtime r;
    Process p;
    ObjectInputStream ois;
    ObjectOutputStream oos;
    Obj obj, obj2;
    int state, i;
    res.setContentType ("text/html");
    ServletOutputStream out = res.getOutputStream ();
    out.println ("<html>");
    out.println ("<head><title>Sub</title></head>");
    out.println ("<body>");
    out.println ("Invoking subprogram...");
    out.println ("<br>");
    try
    r = Runtime.getRuntime();
    p = r.exec ("java -cp .;c:\\Programs\\Apache~1.0\\webapps\\SMain\\WEB-INF\\classes Sub");
    out.println ("...invoked<br>");
    oos = new ObjectOutputStream (p.getOutputStream ());
    obj = new Obj (5);
    oos.writeObject (obj);
    oos.flush ();
    out.println ("<br>SMain sends to Sub: " + obj.toString () + "<br>");
    try
    p.waitFor ();
    catch (InterruptedException e)
    out.println ("<br>Subprogram was interrupted<br>");
    out.println ("<br>" + e.toString () + "<br>");
    state = p.exitValue ();
    out.println ("<br>Subprogram state: " + state + "<br>");
    ois = new ObjectInputStream (p.getInputStream ());
    out.print ("<br>Sub sends to SMain: ");
    obj2 = (Obj) ois.readObject ();
    p.destroy ();
    catch (SecurityException e)
    out.println ("<br>SecurityException<br>");
    out.println ("<br>" + e.toString () + "<br>");
    catch (IOException e)
    out.println ("<br>IOException<br>");
    out.println ("<br>" + e.toString () + "<br>");
    catch (Exception e)
    out.println ("<br>Exception<br>");
    out.println ("<br>" + e.toString () + "<br>");
    out.println ("</body>");
    out.println ("</html>");
    So, as you can see, both application AMain and servlet SMain invoke application Sub and pass it the serializable object Obj. Oddly enough, application AMain works fine whereas servlet SMain throws a StreamCorruptedException exception.
    johnpoole said:
    �It's hard to guess what would cause the exception without seeing code, but the interaction between the processes would differ from that between two applications, because the servlet process is started with a different class loader. I'm not sure which one the jvm started by the call would use.�
    How can I enforce that a System classloader be used in the call to Runtime.getRuntime ().exec () ? (I mean by System classloader a classloader equals to the one applications are launched from console).
    johnpoole said
    �Is there a reason why you aren't starting the second process manually and then connecting to it on a port?�
    The idea is providing a Web interface for an application running in the server. The servlet is used to restrict access to this application but once access is granted (passing the servlet) the application should not be constrained.

  • How to call ejb from a Swing gui application client?

    Hi Everyone,
    I am new to EJB and I have question for calling an ejb from a Swing GUI application client. Can anyone give me an example of how my Swing GUI can call an EJB from a SUN ONE Application Server. If anyone can give me some insight, I appreciate it.

    I have looked up various sources and just can't get it to work. I know I have to use the lookup() method, but I have also seen lookups using IIOP://servename......
    Context ctx = getInitialContext();
    DemoHome dhome = (DemoHome)ctx.lookup("demo.DemoHome");
    or
    Context ctx = getInitialContext();
    DemoHome dhome = (DemoHome)ctx.lookup(java:comp/......)
    so can anyone tell what is the difference between using iiop://servername..... as the lookup string and java:comp/......
    and if using java:comp/ what does this mean? Does it mean that lookup() method is looking for the ejb somewhere in this directory. I would really appreciate if someone can give an example of a Swing GUI calling a ejb from an application server and how the code is actually doing the lookup in and what are each steps it goes through.
    Thanks

  • How to run executable Java app from command line: No Main( ) method

    This is the opposite question from what most users ask. I have the Java source code and a running Java executable version of the program in a windows environment. I don't want to run it in the normal way by double-clicking on it or using the executable. I need to be able to run the same application from the command line. If I can do this, I can then compile and run the code on my Mac, too, which is what I am ultimately trying to accomplish.
    Normally, this would be easy. I would look for a Main method, normally public static void main (String[] args ) or some variation. I cannot find a main() anything, anywhere when searching the files. There must be some windows executable that links to the Java classes. It's very clever, no doubt, but that's not helping me.
    I am trying to run what I can determine as the Main class, with a standard command line call, but that is not working either.
    It is a Java graphics program, so mostly Swing container stuff.
    I am not finding a manifest.txt file, telling me where a main method is, nor anything about the Main Class. There is no readme file for the program.
    Any insight that would point me in the right direction? What should I be looking for?
    Thanks in advance, Bloozman

    It's possible there's a clever Windows executable that runs the class. But if it's a plain old Java class then there's a good chance there's a constructor. Look for that; it's possible you may be able to start by writing another Java class that creates an instance of your mystery class.
    When you have that done, try running it. It's possible that just creating an instance might be sufficient to run it. Swing programs are sometimes written like that. If not, then start looking for methods with names like "run" or "go" or "start" that your little controller program can call.

  • Help required - running a Java program from the command line

    Hi,
    I have a small non-graphical Java application, packaged into a Jar file. My program relies on classes in another (external) Jar file.
    When I run the application from the IDE, everything works fine. However, when I try to run the application from the command line, I keep getting a NoClassDefFoundError for classes in the external jar.
    Both the application jar file and the external jar file are in my root directory (C:\).
    My command line call is as follows:
    java -cp c:MyExternalLib.jar -jar MyApp.jar
    Any help greatly appreciated.
    Thanks,
    Walter

    hi,
    set classpath=%classpath%;c:\myjar.jar;
    here i have specified myjar.jar file as an example u give ur location.after setting the classpath run ur java application.
    java mypgm
    this will solve ur problem
    regards,
    Ganesh

  • Running a java application in command prompt

    hi, I'm new to this forum.
    I would like to know what exactly needs to be specified to run a java application in a normal DOS command prompt.
    I know it is something like:
    javaw -classpath .\class GUI.applicationGUI
    where applicationGUI is the main class, right? What else do I need to do, since I have some other non-GUI classes that I need, inside the class folder ?
    Thanks for your time.

    You need to import those classes. And you need to make packages.
    In classes 1, 2 and 3 put:
    package class;
    In class 4 put;
    package class.GUI;
    Then you need to make the connection:
    In classes 1,2 and 3 put:
    import class.GUI.*;
    In class 4 put:
    import class.*;
    Compile each directory separately while in the respective directory. javac *.java
    Then go back to the directory above the directory "class" and run
    java class/GUI/name_of_file_containing_main_method

  • How to call a WD JAVA application from a WD ABAP application

    Hi experts,
    Here I have two applications with me. One has been created through WebDynpro ABAP while the other one has been created through WebDynpro JAVA. Now i have to call upon the JAVA aplication from my ABAp application. In other words in need to integrate both the applications so as to have an easy navigation in between them.
    In the whole process I need to take care that the data is not lost from both ABAP or JAVA side.
    Please help me someone knows the solution.
    Regards,
    Kaustubh Maithani

    Hi,
    Usally to run WebDynpro for Java Application, we get the Application URL.
    If you want to call this WebDynpro Java Application from Webdynpro Abap, then create UI element like Link to Action or LinktoURL and give the url as WebDynpro for Java URL.
    Regards,
    Lakshmi Prasad.

  • Is it possible to run a java application within a web browser?

    Hello everyone here! I have a question about running a java application within a web browser and I would appreciate it very much if anyone here can give me some answers.
    I have a standalone java application written with AWT. Basically this free application lets users to select spectral lines from a big file based on some criteria and plot those selected lines. Yes, it is a very simple application. Now I want to run this application within a web browser so that users don't need to download the application from the ftp site and thus don't need to install in their machine. Is it possible to run this application within browser? If yes, can we get the same plotting function as we run the application separately and where should I start out?
    Thanks in advance!
    kuilian

    Please see the signed applet discussion group for details of how to avoid the applet security restrictions. You can sign the applet, or use the policy file containing {AllPermission} for testing purposes (though not suitable for widespread deployment).
    Regards
    Matthew

  • How do I start and suspend Java Application from say C++ program

    I want to start a Java application via C++ and on some condition i want to suspend the same program not terminate , but suspend

    Have you tried running the virtual machine from your C++ application ? You can start Java applications from your C++ application using JNI after starting the Virtual machine from within your C++ application. According to the Java documentation you can even now stop the virtual machine from within your C++ program.
    I haven't looked at the 'suspend' detail but I suppose it will not be a problem to call a method via JNI to set a flag to suspend a thread etc.
    There is a tutorial: 'Invoking the Java Virtual Machine' at the following URL: http://java.sun.com/docs/books/tutorial/native1.1/invoking/invo.html.
    This example seems to work only for version1.1 of the JDK. For JDK1.3, version 1.2, (I am not so sure whether I fully understand Sun's version numbers for Java yet) there is some updates on the JNI for starting the VM from C++. This article is called 'JNI Enhancements'. The URL for this article is:
    http://java.sun.com/j2se/1.3.0/docs/guide/jni/jni-12.html
    You have to set version to: JNI_VERSION_1_2
    There is only one problem. I get an error when calling JNI_CreateJavaVM from C++. I could not find any documentation that indicates how you can go about diagnosing what is causing the problem. Normally in Visual C++ you can just get the probable cause by inspecting GetLastError() or the function itself can return helpful diagnostic (error) codes.
    If you manage to start the VM correctly from within Visual C++ please let me know. My email address is [email protected]
    good luck
    Henko

  • Call a Java Application from MicroFocus COBOL (in UNIX environment)

    Hello,
    Could you please let me know, how to call a Java application from a MicroFocus COBOL application. If anyone has any code samples, that would be of great help.
    Thanks in advance,
    Tijo.

    You generally can't cause a program to be executed on a different >server. Basic security, you know. Besides this idea of having the Java >application run on a different server wasn't mentioned in your original >post. That leads me to believe we don't have the whole story.So I think you need to step back and find out what are the requirements. For example: Does your program need to start this Java application running, or is it already running and your program needs to connect to it somehow?
    My program has to start a Java class file, meaning that the Micro Focus COBOL module will call the Java class file. Will it be running on the same machine as your program, or on some other machine?
    For both cases, I would like to know the answer.a) Running on the same machine as my program is running.
    b) Running on the different machine.
    And then there are the questions about whether your program needs to have a conversation with the Java application, or whether it just needs to start it and that's all.
    COBOL program has to call a Java class by passing some parameters and Java class in turn process it and return some value back.. Kind of Request and Response model.Plenty of questions to be asked. Go and find out what they are.
    Sorry ... if I am not clear on my questions. Anyhow, thank you very much for providing the information.

Maybe you are looking for

  • Laserjet 200 color mfp change font

    How do I change the fonts?  I need to print labels and need to use a compressed print.  I cannot find the how to's in manual.  Is this done by a menu choice?  Driver?  Many thanks!!!

  • Can't open a tab in the same window

    Hello, tell me, please, why can't I open a new tab in the same window. maybe I did something wrong done in the settings?

  • Photoshop Crashes When Opening Images

    Hi all, I just installed Photoshop CS5. The program loads fine but when I try to open an image to edit it just crashes. I've tried all kinds of image formats and all of them cause Photoshop to crash. I get a message saying "Photoshop CS5 Has Stopped

  • Looking for Directory structure

    Hi i am new bie to Tomcat . i was wondering if some explain me the directory structure for a web Application. like where to put the HTML files and where to put the Java classes and where to keep the JSP and what is the Importance of WEB-INF dir Thank

  • Which Java version is recommended for widest compatibility?

    I started learning and coding with JDK 1.1_Final, but particular code elements do not seem to be working. For example, overriding update() to not clear the screen and instead only call paint() has no effect at all - the screen still gets cleared! I h