Results 1 to 16 of 16

Thread: Applications...

  1. #1

    Thread Starter
    Addicted Member Virtual24's Avatar
    Join Date
    May 2001
    Posts
    228

    Question Applications...

    I have a question on how to make a windows application in java. I know how to use applets and all, but I am confuse on how to make it an independant application (.exe). I know it has to do with extending the Frame class, but I can't seem to figure out how to use it. Can anyone show me some simple code of a program that would make your basic HelloWorld application?
    To protect time is to protect everything...

  2. #2
    Addicted Member HairyDave's Avatar
    Join Date
    Aug 2002
    Location
    Er...I can't remember.
    Posts
    196
    I may be well off the mark (wouldn't be a surprise), but I didn't think you could make exe's in Java..? I thought the idea was that you compiled the java into java byte code. As such it is platform independant but still has to be interpreted/run.

    J++ has the option (I think) to compile to exe, but I didn't think java does as standard. May be wrong.

    You can do the Windows stuff using the swing classes. These allow the dialog stuff to be possible.

    Hope this helps (hope I'm right )

    HD

  3. #3
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    Quite right. The Sun javac can't compile to native code, but, as you said, the J++ compiler could, as does gcc. But if you do that I don't see why you should use Java in the first place. The nice thing about it is it's portability WITHOUT having to recompile. If you compile to native you might just as well (or even better) use C++ and the wxWindows library.

    Frame is an awt class, it has been superseded by the swing class, which all begin with J (e.g. JFrame). Supreseded is to be taken literally, JFrame is derived from Frame, and all swing classes mainly provide premade solutions using the awt.

    On a related thing, is it possible to create Java bytecode files that are automatically executed when double-clicked without having to link the .class extension with the java VM? The Sun VM doesn't automatically do it like it would make sense... (probably because you don't start class files but rather classes).
    Or do I have to write an exe or script that does this?
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  4. #4
    Hyperactive Member marnitzg's Avatar
    Join Date
    Oct 2000
    Location
    South Africa
    Posts
    372
    You do get compilers that compile to machine code. I think they're called JIT (just-in-time) compilers but don't quote me on that.

  5. #5

    Thread Starter
    Addicted Member Virtual24's Avatar
    Join Date
    May 2001
    Posts
    228
    Originally posted by CornedBee
    On a related thing, is it possible to create Java bytecode files that are automatically executed when double-clicked without having to link the .class extension with the java VM? The Sun VM doesn't automatically do it like it would make sense... (probably because you don't start class files but rather classes).
    Or do I have to write an exe or script that does this?
    That is more what I meant. I am using java because it is so much easier to use. C++ is so gay when it come to trying to cast anything into anything else, you get all these unacceptable conversion errors, and I got fed up w/ C++. So i switched to using java. Like CornedBee said, is there a way to make a self executable file for java programs ( esentually a .exe file )
    To protect time is to protect everything...

  6. #6

    Thread Starter
    Addicted Member Virtual24's Avatar
    Join Date
    May 2001
    Posts
    228
    I also wanted to know how to make a java application without using an applet. Swing was mentioned and I know you use that to make the actual window part, but what class would my class extend in order to make a standalone application?
    To protect time is to protect everything...

  7. #7
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    Java doesn't even have most of those conversions (except automatic string conversions, which aren't hard to do in C++).

    But we don't want to start arguing over that now.

    You don't NEED to extend any class in order to make a stand-alone. You need one class that has a
    public static void main(string[] args)
    method. Then you compile your app, open a prompt and write
    java MyClassName
    and provided that MyClassName contains the main method and is in a file named MyClassName.class and the VM can actually find the file the app will start.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  8. #8
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    Code:
    import java.awt.*;
    import java.awt.event.*;
    
    class MyWindowedApp
    {
    	public Frame MainFrame;
    	
    
    	public static void main(String[] args) 
    	{
    		MyWindowedApp app = new MyWindowedApp();
    		app.Go();
    	}
    
    	private class MyEventHandler extends WindowAdapter
    	{
    		public void windowClosing(WindowEvent e)
    		{
    			System.exit(0);
    		}
    	}
    
    	private void Go()
    	{
    		MainFrame = new Frame("My First Windowed Java App!");
    		MainFrame.addWindowListener(new MyEventHandler());
    		MainFrame.show();
    	}
    }
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  9. #9
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    That's awt, not swing btw. I only wanted to show a window quickly.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  10. #10

    Thread Starter
    Addicted Member Virtual24's Avatar
    Join Date
    May 2001
    Posts
    228
    Thanx, thats exactly what I wanted... I had that, but was missing the critical MyWindowedApp.show(); part of it, which is probably why I thought it wasn't working .

    Now I know you said you don't want to get in to it, but I have lost my faith in C++ for several reasons, one of them being there is no really good String type that can be converted easily from const char* to char* to int to double and so on. In java, there is ( whaddya know! ). So... If it is easy, can you explain how. I might try to write a class for my own use that could do that. I would also need help on how to overload operators.

    While on the subject of operators, whats up with the new operator in C++??? What is the point of it. It certainly doesn't work like it does in Java, and whenever I try to use it, I get errors??
    To protect time is to protect everything...

  11. #11

    Thread Starter
    Addicted Member Virtual24's Avatar
    Join Date
    May 2001
    Posts
    228
    Oops, this is a JAVA forum, now someone is probably going to bite my head off for even mentioning C++ in it...
    To protect time is to protect everything...

  12. #12
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    But in the C++ forum our heads might get bitten off for mentioning Java, so it's a lose/lose scenario.

    So you want easy conversion and go for a language where Integer can't be auto-converted to int?

    The good string class is std::string from <string>.
    Operator overloading (especially cast operators), stringstreams (those are wonderful).
    Because where's the big difference?
    Code:
    // Java:
    String str = "12";
    int i = new Integer(str).intVal();
    String str2 = "34.12";
    double d = new Decimal(str2).doubleVal();
    
    // C++:
    string str = "12";
    istringstream is(str);
    int i;
    is >> i;
    double d;
    string str2 = "34.12";
    is.str(str2);
    is >> d;
    
    // so far Java is slightly superior. But what with this?
    // C++:
    string str = "12 43.12 2e10";
    istringstream is(str);
    int i;
    double d1, d2;
    is >> i >> d1 >> d2;
    
    // Java:
    // I admit I don't know, I don't know much about Java
    // But I guess it's something with StringTokenizer
    The advantage Java has here is that everything derives from Object. I could easily write Integer and Decimal classes for a library that would provide similar behavior like the Java classes only they don't need to be manually converted to int/double.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  13. #13

    Thread Starter
    Addicted Member Virtual24's Avatar
    Join Date
    May 2001
    Posts
    228
    I'll try to use the string and stringstreams to see if i can get 'em to work. I am starting to get really fed up with all the errors that C++ has to whine about though... It's like the compiler actually doesn't want you to write successful code...
    To protect time is to protect everything...

  14. #14
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    Nah, it's that the compiler wants you to, but you don't
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  15. #15

    Thread Starter
    Addicted Member Virtual24's Avatar
    Join Date
    May 2001
    Posts
    228
    Ahh, probably right. Actually, I want to write successful code, but I am not a professional programmer, and often do not how to do things. So, that's why I get errors a lot... Guess that means I hafta deal with it...
    To protect time is to protect everything...

  16. #16
    Addicted Member HairyDave's Avatar
    Join Date
    Aug 2002
    Location
    Er...I can't remember.
    Posts
    196
    Ahh, we learn from our mistakes.

    Unfortunately I tend to forget them

    HD

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width