Re: How to make standalone Java applications?

mromarkhan_at_rogers.com
Date: 04/29/04


Date: Thu, 29 Apr 2004 13:04:52 GMT

Peace be unto you.

Here is a cheap hack

// http://www-106.ibm.com/developerworks/java/library/j-jniexe/jniexe.html
#include <windows.h>
#define MAIN_CLASS "Console"
int main(int argc, char** argv)
{
    char * cmdline = (char *) malloc( 1024 ); /* big buffer */
    wsprintf( cmdline, "javaw.exe %s", MAIN_CLASS );
    for(int i = 1;i < argc;i++)
    {
        strcat(cmdline, " ");
        strcat(cmdline, argv[i]);
    }
    system( cmdline );
    return 0;
}

import java.awt.event.*;
import javax.swing.*;
import java.awt.*;
public class Console extends JFrame
{
        private JTextArea textdisplay;
        public Console(String [] args)
        {
                textdisplay = new JTextArea();
                this.getContentPane().add(new JScrollPane(textdisplay),BorderLayout.CENTER);
                this.setSize(512,342);
                this.setVisible(true);
                for(int i = 0;i < args.length;i++)
                {
                    textdisplay.append(i+" "+args[i]+"\n");
                }
        }
        public static void main(String [] args)
        {
                Console console = new Console(args);
                
        }
}

g++ myapp.cpp -o myapp.exe

Good bye.



Relevant Pages

  • Re: a simple question realted to StringBuffer
    ... I think the reason why the same piece of code works for Flo 'Irian' Schaetz and does not work for Shawn. ... One console accepts "zero" char and displays it as 'space', another console might igonore any character following 'zero char'. ...
    (comp.lang.java.programmer)
  • Re: sending strings from C using Engine
    ... char *outputTest; ... allocate new memory to hold the concatenated result and ... you end the MATLAB command ... The console output gets buffered and doesn't print when ...
    (comp.soft-sys.matlab)
  • [resend patch] HVSI early boot console
    ... This patch adds support for the udbg early console interfaces ... +static void udbg_hvsi_putc(unsigned char c) ... send the line "unsubscribe linux-kernel" in ...
    (Linux-Kernel)
  • Re: std::cin and disabling canonical line processing (buffering)
    ... >> Tom, ... >> I prefer your method of opening up the console in binary mode from the get-go. ... >> tried it with those modes enabled and still cannot get an ESC char. ... > Obviously, not all virtual key codes have an obvious char value, so you ...
    (microsoft.public.vc.stl)
  • [patch] HVSI early boot console
    ... this patch adds support for the udbg early console interfaces ... +static void udbg_hvsi_putc(unsigned char c) ... send the line "unsubscribe linux-kernel" in ...
    (Linux-Kernel)