[java] I'm a newcomer (5 days)... some pointers?
No, not pointers a la C/C++, some help please.
OK, I got the book Visual J++ 6.0 From the Ground Up, which I am on page 130 or so, and I have still not written any code beyond a little hello world thingy and some test classes to get the idea of how they interact. Never buy that book! It has no examples, and is page after page of theory (which is actually very helpful, but by 1/5 of the way through the book, and who knows how much farther, it doesn''t tell how to get rudimentary input/output working!). Here are my questions:
For console-type app.''s:
1. How do I get a user input via string like C++''s cin?
2. How do I output strings, like C++''s cout?
3. How do I clear the output area?
4. How do I get real-time input, like QBasic''s INKEY$?
For future browser-based Web Game development:
5. Should I use the built-in Java 2d graphics API?
6. If not, what 3rd party graphics API has best speed/features?
7. How do I define a Java program to be an applet? and,
8. How do I run a Java applet on a web page?
9. For web applets, do I upload a .class file, or an .exe, or what?
Thanks a ton!
Ben Dilts
Bean Dog home page
phew, that''s a lot of quesitons.
1. & 2.
3. Have to do a native C call, or print a lot of new lines.
4. Don''t know if you can do it from a console, from a gui app though you would use the event listener model.
5. sure, why not?
6. don''t know if there are any Java 3rd party apis, maybe a 3rd party native API
7. extend java.applet.Applet, use init() destroy() start() stop()
8. use < applet > tags to use the browser''s native jvm, use < embed > tags to use the java Plugin (search java.sun.com for applet tag converter)
9. class file, < applet code="NameofClass" width=xxx height=xxx > (optional archive="Jarfile.jar")
1. & 2.
import java.io.*;
public class Test {
public Test () {
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
try{
System.out.print("Enter your name> "); System.out.flush();
String myInput = in.readLine();
System.out.println("I got ''" + myInput + "''");
} catch(IOException ioe) {}
}
public static void main(String [] args) {
new Test();
}
}
3. Have to do a native C call, or print a lot of new lines.
4. Don''t know if you can do it from a console, from a gui app though you would use the event listener model.
5. sure, why not?
6. don''t know if there are any Java 3rd party apis, maybe a 3rd party native API
7. extend java.applet.Applet, use init() destroy() start() stop()
8. use < applet > tags to use the browser''s native jvm, use < embed > tags to use the java Plugin (search java.sun.com for applet tag converter)
9. class file, < applet code="NameofClass" width=xxx height=xxx > (optional archive="Jarfile.jar")
July 09, 2000 07:31 PM
I''ve done a thing or two in java, although I never got to deep into it, and I''ve always preferred the original JDK over anything Microsoft sent (besides, I hear it has some incompatabilities with other OSes, the MS mongrols shouldn''t have optimized it for WinX). But, I think I can help with a thing or two...
Input:
Well the equivalent to cin (at least two what I''ve seen in my one week experience with a C++ book) would be something like:
public static byte getInput()[] throws Exception {
byte buffer[] = new byte[12];
for (int i=0;i<12;i++) {
buffer = System.in.read();
}
return buffer;
}
Ofcourse this is an extremely coarse aplication but I hope you get the idea. Oh, and this is only an extremely simplified thing, there are far better and correct ways to do it (but I never got into seeing them to well...). Unfortunately I don''t remember so well how realtime input works, I only remember (marginally) the Java3D API way off implementing keyboard input... Altough mouse input is implented through one or two interfaces and a mouselitner method (but this has differed a bit from JDK to JDK and is most probably even more different in J++).
Output strings:
If J++ didn''t alter it, then you simply need to do:
System.out.println("your string here");
or alternatively
String a = "your string here";
System.out.println(a);
Use or not built in Java API?
Well, I think that it cuts down a lot of work and it usually caters for your needs (but then that depends on your needs...). If you check the net you can see a lot of examples which use the standard library(I simply adore pointing to a using Peter Walser stuff, it actually is a good demonstration of what Java can do on the net http://www2.active.ch/~proxima/idx3d/idx3d.html, besides it''s actually quite good 3D engine which he lets you use, non comercially ofcoures ----- just remembered, in his examples, he uses keyboard and mouse input, check it out to see if it''s what you want).
How does a Java App turn into a Java Applet?
Make your implementation class extend (subclass, inherit, whatever...) java.applet.Applet and then you must overide (better check these details thoroughly, for obvious reasons) init, start, paint, update, stop and destroy (actually some of them don''t need to be overriden, but most people recomend it). Don''t forget to check other things like the HTML tag stuff and how to pass parameters and the whole Abstract Window Toolkit, or J++ equivalent...). Another thing to take in mind is that the browser will not loke for any "main" method, instead it will look for and start with init and continue along those methods you have to override. Oh, and it compiles as any normal APP.
As you can see there is nothing transcendental about applets, just don''t forget to subclass Applet and overide the specific methods and destroy any intentions of including "main" (and consult a complete source on how those methods will be used by the browser). Then you just need to add the correct tags to your html (it''s actually fairly easy to implent, check your book to see what they say, hopefully it won''t differ to much from what I''ve been babling about).
What do you upload to your site?
Well, you need your HTML with the tag to your applet and you need all the images and other data your applet uses and, finally, you need your applet class. When you study the previous point, you''ll see that the tag points to a class file and not a exe, so your applet will have to obviously be a class file.
DW-za
Portugal
>>>I''ll make up a totally useless pun to put here when I get the courage to register myself...
Input:
Well the equivalent to cin (at least two what I''ve seen in my one week experience with a C++ book) would be something like:
public static byte getInput()[] throws Exception {
byte buffer[] = new byte[12];
for (int i=0;i<12;i++) {
buffer = System.in.read();
}
return buffer;
}
Ofcourse this is an extremely coarse aplication but I hope you get the idea. Oh, and this is only an extremely simplified thing, there are far better and correct ways to do it (but I never got into seeing them to well...). Unfortunately I don''t remember so well how realtime input works, I only remember (marginally) the Java3D API way off implementing keyboard input... Altough mouse input is implented through one or two interfaces and a mouselitner method (but this has differed a bit from JDK to JDK and is most probably even more different in J++).
Output strings:
If J++ didn''t alter it, then you simply need to do:
System.out.println("your string here");
or alternatively
String a = "your string here";
System.out.println(a);
Use or not built in Java API?
Well, I think that it cuts down a lot of work and it usually caters for your needs (but then that depends on your needs...). If you check the net you can see a lot of examples which use the standard library(I simply adore pointing to a using Peter Walser stuff, it actually is a good demonstration of what Java can do on the net http://www2.active.ch/~proxima/idx3d/idx3d.html, besides it''s actually quite good 3D engine which he lets you use, non comercially ofcoures ----- just remembered, in his examples, he uses keyboard and mouse input, check it out to see if it''s what you want).
How does a Java App turn into a Java Applet?
Make your implementation class extend (subclass, inherit, whatever...) java.applet.Applet and then you must overide (better check these details thoroughly, for obvious reasons) init, start, paint, update, stop and destroy (actually some of them don''t need to be overriden, but most people recomend it). Don''t forget to check other things like the HTML tag stuff and how to pass parameters and the whole Abstract Window Toolkit, or J++ equivalent...). Another thing to take in mind is that the browser will not loke for any "main" method, instead it will look for and start with init and continue along those methods you have to override. Oh, and it compiles as any normal APP.
As you can see there is nothing transcendental about applets, just don''t forget to subclass Applet and overide the specific methods and destroy any intentions of including "main" (and consult a complete source on how those methods will be used by the browser). Then you just need to add the correct tags to your html (it''s actually fairly easy to implent, check your book to see what they say, hopefully it won''t differ to much from what I''ve been babling about).
What do you upload to your site?
Well, you need your HTML with the tag to your applet and you need all the images and other data your applet uses and, finally, you need your applet class. When you study the previous point, you''ll see that the tag points to a class file and not a exe, so your applet will have to obviously be a class file.
DW-za
Portugal
>>>I''ll make up a totally useless pun to put here when I get the courage to register myself...
July 09, 2000 07:37 PM
Sorry about the apparent repetition of Jim_Ross''s post, but I was looking for Peter Walser''s site and lost my time there... Don''t forget to check it out...
DW-za
Portugal
DW-za
Portugal
Jim_Ross nailed most of them. I would like to add a few things on compatibility.
5) Sun''s new 2D API, Java2D, uses Java version 1.2 and higher. The runtime environment used in IE and Netscape only supports 1.1, so you will not be able to use Java2D or any other 1.2 feature (such as Swing) without using the Java2 Plugin. Downloading this plugin may be a pain to your users, or may be fine. Your call.
7) Swing Applets can also be created by extending javax.swing.JApplet. Swing is a new graphics API introduced in 1.2 . Hmm...I''m not sure if you can even use Java2D without using Swing... Same restrictions as above.
If you are doing web based development, be careful on 3rd party API selection. Many of them use JNI, the native interface, to tie to OpenGL, DirectX, or other native code. If you are coding applets, this is not going to work 90% of the time.
Since you bought "Visual J++ 6.0 From the Ground Up", I would assume that you are using Visual J++, 6.0 . IMHO, Microsoft''s Java implementation may cause you some compatibility headache''s, especially if you use their proprietary extensions. IE, to access ActiveX objects, DirectX features, etc...
Good luck, check in if you have more questions.
ManaSink
5) Sun''s new 2D API, Java2D, uses Java version 1.2 and higher. The runtime environment used in IE and Netscape only supports 1.1, so you will not be able to use Java2D or any other 1.2 feature (such as Swing) without using the Java2 Plugin. Downloading this plugin may be a pain to your users, or may be fine. Your call.
7) Swing Applets can also be created by extending javax.swing.JApplet. Swing is a new graphics API introduced in 1.2 . Hmm...I''m not sure if you can even use Java2D without using Swing... Same restrictions as above.
If you are doing web based development, be careful on 3rd party API selection. Many of them use JNI, the native interface, to tie to OpenGL, DirectX, or other native code. If you are coding applets, this is not going to work 90% of the time.
Since you bought "Visual J++ 6.0 From the Ground Up", I would assume that you are using Visual J++, 6.0 . IMHO, Microsoft''s Java implementation may cause you some compatibility headache''s, especially if you use their proprietary extensions. IE, to access ActiveX objects, DirectX features, etc...
Good luck, check in if you have more questions.
ManaSink
Yeah, you *should* stay away from J++, as it causes compatibilty problems. I believe it is because of J++ that Sun sued MS, leading to this crap C# stuff...
Grrrrrrr...
If you code it, they will come...
Commander M
(a.k.a. Crazy Yank)
http://commanderm.8m.com
cmndrm@commanderm.8m.com
Grrrrrrr...
If you code it, they will come...
Commander M
(a.k.a. Crazy Yank)
http://commanderm.8m.com
cmndrm@commanderm.8m.com
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement