> I don't think I need one on running from foxnews ;).
>
> Java is beginning to frustrate me with it's
> unnecessary complexity.
You can quit at anytime. If you don't want to do quit, why don't you ask a specific question about the problem you're having?
I don't want to quit, and I can't, really. I'm just used to basic where you can have a 3D rotating cube on the screen in 4 lines, and here it takes more than that just to set up the simplest possible thing that will compile. I'm needing to eventually get some games up on websites, so I'm wondering how I would do that exactly. I have no idea where to even start, so that's what I'm asking.
> I don't want to quit, and I can't, really. I'm just
> used to basic where you can have a 3D rotating cube
> on the screen in 4 lines, and here it takes more than
> that just to set up the simplest possible thing that
> will compile. I'm needing to eventually get some
> games up on websites, so I'm wondering how I would do
> that exactly. I have no idea where to even start, so
> that's what I'm asking.
I'd like to see a rotating 3D cube with 4 lines of basic code ;-)
Java is a good way to go. Applets are what you want to look at but Java is a super complex language because it is super powerful and can be used to do just about anything.
I'd suggest looking at the AWT/Swing tutorial and Applet tutorial on the Sun web site as a starting point.
But Java it isn't a language many people can just dive right into and start writing games / apps right from the get go.
> Java is beginning to frustrate me with it's
> unnecessary complexity.
How did you find out its complexity is "unnecessary" ?
I personally didn't find anything unnecessary or illogical in Java after a few years of developing. Java is very powerful as it is complex. It's designed "by professional programmers FOR professional programmers", not for kids who want to play with it, or creating a rotating cube in 4 lines.
> I'd like to see a rotating 3D cube with 4 lines of
> basic code ;-)
>
> Java is a good way to go. Applets are what you want
> to look at but Java is a super complex language
> because it is super powerful and can be used to do
> just about anything.
>
> I'd suggest looking at the AWT/Swing tutorial and
> Applet tutorial on the Sun web site as a starting
> point.
>
> But Java it isn't a language many people can just
> dive right into and start writing games / apps right
> from the get go.
Okay, here's the basic code, I'm serious, 4 lines ;).
make object cube 1, 5
DO
yrotate object 1, object angle y( 1 ) + 1
LOOP
Here's even a video of a game I'm making in it, which is currently 6000 lines.
http://www.youtube.com/watch?v=CBmZ7OzFZwE
I don't plan on diving right in, I learned it in school this year (if you could call it that, mostly self-taught, the course sucked), and am trying to learn more this summer. All I want is a simple app up on a website. I'm not trying to get the next World of Warcraft on an applet ;).
> > Java is beginning to frustrate me with it's
> > unnecessary complexity.
>
> How did you find out its complexity is "unnecessary"
> ?
>
> I personally didn't find anything unnecessary or
> illogical in Java after a few years of developing.
> Java is very powerful as it is complex. It's designed
> "by professional programmers FOR professional
> programmers", not for kids who want to play with it,
> or creating a rotating cube in 4 lines.
Because, coming from basic, it has many unnecessary features that should be done for you. I'll make a quick list off the top of my head:
1) Why doesn't it default variables to 0 or null if you don't define them?
2) Why does it matter if a method is static and you reference a non-static method?
3) Why do you have to pass the graphics class into every method you want to use it in? Why can't it just be global?
4) Why doesn't java automatically import all needed classes and API's for you instead of you manually having to do it at the top?
5) Why do you need double equal signs to evaluate equality instead of a single one? Java should have the ability to realize which one you're wanting without problem like in basic.
6) Why do you need all the methods for something you implement such as MouseListener if you're not going to use them?
7) Why does all the input have to be defined to it's respective method? Why can't I say "if( mousePressed == true )" in the main method?
8) Why do you need a specific method to paint?
and that's just off the top of my head.
> That's why I suggested the AWT/Swing and Applet
> tutorials. Perfect place to start gathering
> knowledge about the language with respect to applets
> / web based applications.
I've looked at some of them, but the one's I've found don't actually tell you how to get it on a web page, which is what I need. I already know how to make basic Applets using AWT, just not get them on the web.
> > > Java is beginning to frustrate me with it's
> > > unnecessary complexity.
> >
> > How did you find out its complexity is
> "unnecessary"
> > ?
> >
> > I personally didn't find anything unnecessary or
> > illogical in Java after a few years of developing.
> > Java is very powerful as it is complex. It's
> designed
> > "by professional programmers FOR professional
> > programmers", not for kids who want to play with
> it,
> > or creating a rotating cube in 4 lines.
> Because, coming from basic, it has many unnecessary
> features that should be done for you. I'll make a
> quick list off the top of my head:
> 1) Why doesn't it default variables to 0 or null if
> you don't define them?
> 2) Why does it matter if a method is static and you
> reference a non-static method?
> 3) Why do you have to pass the graphics class into
> every method you want to use it in? Why can't it just
> be global?
> 4) Why doesn't java automatically import all needed
> classes and API's for you instead of you manually
> having to do it at the top?
> 5) Why do you need double equal signs to evaluate
> equality instead of a single one? Java should have
> the ability to realize which one you're wanting
> without problem like in basic.
> 6) Why do you need all the methods for something you
> implement such as MouseListener if you're not going
> to use them?
> 7) Why does all the input have to be defined to it's
> respective method? Why can't I say "if( mousePressed
> == true )" in the main method?
> 8) Why do you need a specific method to paint?
>
> and that's just off the top of my head.
Lol, that's like buying a tank to drive to the grocery store then complaining that all those guns and treads are unneccesary. They are if you're just going to the grocery store. But tanks are designed for much than that. You can program a computer to do almost anything it's capable of in java. Don't you think that requires a lot of complexity?
> Lol, that's like buying a tank to drive to the
> grocery store then complaining that all those guns
> and treads are unneccesary. They are if you're just
> going to the grocery store. But tanks are designed
> for much than that. You can program a computer to do
> almost anything it's capable of in java. Don't
> you think that requires a lot of complexity?
I see what you're trying to say, but I still think that most of those are unnecessary no matter the complexity of the program your creating. I'm not saying I think Java should be simpler, I'm just saying that it doesn't need many of the little things like the 8 I listed above. For example, why doesn't it automatically default variables to null or 0 if undefined? That way you wouldn't have to define every single variable in your program at the top. And why is passing Graphics g to everything you use it in necessary? Why can't they just make it where it's automatically there? Or get rid of it altogether, I don't see the point of even say "g."... Why not just "fillRect( x, y, width, height )"?
> I see what you're trying to say, but I still think
> that most of those are unnecessary no matter the
> complexity of the program your creating. I'm not
> saying I think Java should be simpler, I'm just
> saying that it doesn't need many of the little things
> like the 8 I listed above. For example, why doesn't
> it automatically default variables to null or 0 if
> undefined? That way you wouldn't have to define every
> single variable in your program at the top.
Variables are assigned a default value if they're class members. If not, is it really that hard to add "= 0" to the end of the declaration?
> And why
> is passing Graphics g to everything you use it in
> necessary? Why can't they just make it where it's
> automatically there? Or get rid of it altogether, I
> don't see the point of even say "g."... Why not just
> "fillRect( x, y, width, height )"?
Because there can be many graphics contexts that you can draw on. There are images, the contents of components, etc. If you couldn't specify where to draw, it would severly limit what you could do.
> > I see what you're trying to say, but I still think
> > that most of those are unnecessary no matter the
> > complexity of the program your creating. I'm not
> > saying I think Java should be simpler, I'm just
> > saying that it doesn't need many of the little
> things
> > like the 8 I listed above. For example, why
> doesn't
> > it automatically default variables to null or 0 if
> > undefined? That way you wouldn't have to define
> every
> > single variable in your program at the top.
>
> Variables are assigned a default value if they're
> class members. If not, is it really that hard to add
> "= 0" to the end of the declaration?
Okay, I know it wouldn't be a big deal, but that's just a small example.
> > And why
> > is passing Graphics g to everything you use it in
> > necessary? Why can't they just make it where it's
> > automatically there? Or get rid of it altogether,
> I
> > don't see the point of even say "g."... Why not
> just
> > "fillRect( x, y, width, height )"?
>
> Because there can be many graphics contexts that you
> can draw on. There are images, the contents of
> components, etc. If you couldn't specify where to
> draw, it would severly limit what you could do.
Okay, I understand that, but that still doesn't mean you should have to pass g into everything you need it for. Why can't it just be global?
What about "Why does it matter if a method is static and you reference a non-static method?" and "Why doesn't java automatically import all needed classes and API's for you instead of you manually having to do it at the top?" and "Why do you need all the methods for something you implement such as MouseListener if you're not going to use them?".
> 1) Why doesn't it default variables to 0 or null if you don't define them?
The rationale is that this may be sweeping oversights under the rug -- you
forgot to set foo to 17 as you intended, and silently setting it to 0 is going to
introduce bugs, not help you.
2) Why does it matter if a method is static and you reference a non-static method?
I won't explain that here, but basically you are goofing up and not
understanding the basics or method invocation and object instantiation.
3) Why do you have to pass the graphics class into every method you want to use it in? Why can't it just be global?
In general, introducing global objects should be done very sparingly.
In the case of the graphics objects used for painting, they are disposed
at the end of a call to paint, so you should not maintain a reference to them.
4) Why doesn't java automatically import all needed classes and API's for you instead of you manually having to do it at the top?
The API is too big for that. Many IDEs simplify this, though.
5) Why do you need double equal signs to evaluate equality instead of a single one? Java should have the ability to realize which one you're wanting without problem like in basic.
BASIC gets around this by treating assignment as a statement, not an expression. In Java (and various languages in the C family) you can write:
if ((ch = in.read()) != -1)
which has an assignment inside a larger expression. This is often
useful and I miss it when I write in other languages.
It's not hard to learn to write ==
6) Why do you need all the methods for something you implement such as MouseListener if you're not going to use them?
extends MouseAdapter instead of directly implementing MouseListener.
Problem solved!
7) Why does all the input have to be defined to it's respective method? Why can't I say "if( mousePressed == true )" in the main method?
I don't know what you mean. Are you asking why we need to program in
an event-driven manner?
8) Why do you need a specific method to paint?
One needs specific methods to do specific things. Less magic.
> What about "Why does it matter if a method is static
> and you reference a non-static method?"
Read about class variables, it explains what static means: http://java.sun.com/docs/books/tutorial/java/javaOO/classvars.html
> and "Why
> doesn't java automatically import all needed classes
> and API's for you instead of you manually having to
> do it at the top?"
What if there were two classes call Foo, one in the standard java library, and one that you wrote yourself. What if you referred to it in your code simply as Foo, not by the fully qualified package name? How would the compiler know which one you wanted? You don't have to import anything anyway, you can use the full name for everything in your code. i.e. java.util.List aList = new java.util.ArrayList();
> and "Why do you need all the
> methods for something you implement such as
> MouseListener if you're not going to use them?".
Because the MouseListener interface defines all five of those methods. That interface could be split into 5 different ones each with one method, but then you'd have to implement 5 different interfaces to get all the functionality. An interface defines a contract that your class agrees to when it implements it. Any other code can call any of the methods in that interface, so they have to be implemented, even if it doesn't actually do anything.
> 7) Why does all the input have to be defined to it's
> respective method? Why can't I say "if( mousePressed
> == true )" in the main method?
>
> I don't know what you mean. Are you asking why we
> need to program in
> an event-driven manner?
Kind of. In BASIC, say to move a box across the screen using the arrowkeys, you would do something like:
ink rgb( 200, 0, 0 ), 0 //set box color to red
y1 = 50 //initial y value
DO //start main loop
cls //clear the screen every loop
box x1, y1, x1 + 50, y1 + 50 //draw box
IF mouseclick() = 1 //if you click the left mouse button
x1 = x1 + 1 //move x value over one every loop
ENDIF //end if statement
LOOP //end main loop
So you don't have to have an entire method devoted to doing something if the mouse is clicked. This way you also don't have a hundred boolean statements saying things like:
"if( hasSelectedPlayer == false )" and "hasStartedGame == true", so you would check for the mouseclick in certain locations at certain times.
> 8) Why do you need a specific method to paint?
>
> One needs specific methods to do specific things.
> Less magic.
I don't think you do though. For example, see the code above. There is not "paint method" it's all implemented into one part, where you don't have to have specific method recalled every time something occurs that would change the screen.
> I don't think you do though. For example, see the code above. There is not
> "paint method" it's all implemented into one part, where you don't have to have
> specific method recalled every time something occurs that would change the
> screen.
For painting to occur, there is a paint method somewhere. Perhaps you didn't
write it or you didn't invoke it directly, but it is there.
By the way, I understand that Java isn't BASIC, I just keep comparing them to point out simple things that could be a lot easier and accomplish the same thing, and it's the only other language I know to compare it to. The only reason I'm using Java right now is because BASIC can't be embedded into webpages and Java is faster.
> >For painting to occur, there is a paint method
> somewhere. Perhaps you didn't
> >write it or you didn't invoke it directly, but it is
> there.
>
> But that's the point, why should I need to invoke it
> in the first place? Why can't Java do it
> automatically?
I don't know what you are referring to here. One seldom invokes
Component's paint method directly.
> > >For painting to occur, there is a paint method
> > somewhere. Perhaps you didn't
> > >write it or you didn't invoke it directly, but it
> is
> > there.
> >
> > But that's the point, why should I need to invoke
> it
> > in the first place? Why can't Java do it
> > automatically?
>
> I don't know what you are referring to here. One
> seldom invokes
> Component's paint method directly.
I'm referring to having to call "repaint()" everytime something on the screen changes.
> I'm referring to having to call "repaint()" everytime
> something on the screen changes.
How would the vm know when it needs to repaint? It could just constantly repaint, but that would burn up cpu time unneccesarily if it only changed once every 10 seconds. All calling repaint() does is tell the vm that you want it redraw when you change something.
> Okay, so how would I handle mouse input? What if I at
> the beginning the player had to select the player,
> then afterwards, the mouse wouldn't read that. Would
> the only way to do this is say something like "if(
> hasStarted == false )" in the mousePressed method?
Normally you have separate components' events handled by different code. So the button that selects the player, or whatever, only get's run when the select player button is clicked. After you're done selecting players, don't show that button anymore, and you don't have to worry about that code running anymore.
> Okay, so how would I handle mouse input? What if I at
> the beginning the player had to select the player,
> then afterwards, the mouse wouldn't read that. Would
> the only way to do this is say something like "if(
> hasStarted == false )" in the mousePressed method?
If the behaviour of a mouse listener needs to change, among your options are:
1. defining a property like started, as you write.
2. Have different mouse listeners: say InitialMouseListener and PlayngMouseListener,
and switching them as appropriate.
This is just basic object-oriented design and programming. You would do exactly
the same in VB.NET.
> Impossible. The applet code has to be downloaded and
> executed locally on the persons machine. This is
> what an applet is and how it works.
Then how are any of the games on pages like this done? http://www.addictinggames.com/
And, no, I don't know what the html file needs.
> > Impossible. The applet code has to be downloaded
> and
> > executed locally on the persons machine. This is
> > what an applet is and how it works.
>
> Then how are any of the games on pages like this
> done? http://www.addictinggames.com/
>
> And, no, I don't know what the html file needs.
Ah, well then you're missing a big chunk of the puzzle. When someone browses to your webpage, there's a bit of html that handles loading the applet and running it on the page. I'm not up to date on how to use it, but here are some resources:
http://java.sun.com/docs/books/tutorial/deployment/applet/html.html
http://java.sun.com/docs/books/tutorial/deployment/applet/applettag.html
That is an applet, if you peek into the HTML source code, you'll see this tag:
<applet width=300 height=300 code="Backbuffer1.class">
( <font color="red">You need to enable Java to see this applet.</font> )
</applet>
That tells the browser to download Backbuffer1.class and execute it as an applet in the space provided.
The code is downloaded in order to be executed on your machine.
> Okay, well what about these on this page:
> http://www.dgp.toronto.edu/~mjmcguff/learn/java/07-bac
> kbuffer/
>
> how are they done?
>
> Okay, thanks for those links, I'll check them out.
Look at the source of that page, you'll see the <applet> tag where they're loading it.
Wasn't there a tool that came with the jdk that would generate the html for your applet automatically? I swear I remember using something like that ages ago. I can't remember what it was called.
> That is an applet, if you peek into the HTML source
> code, you'll see this tag:
>
> <applet width=300 height=300
> code="Backbuffer1.class">
> ( <font color="red">You need to enable Java to see
> this applet.</font> )
>
> </applet>
>
> That tells the browser to download Backbuffer1.class
> and execute it as an applet in the space provided.
>
> The code is downloaded in order to be executed on
> your machine.
Oh, well, I don't mind that kind of downloading, I thought you meant an actual downloading of an exe. So if I use that HTML then it should automatically download the class to use on the internet?
> Oh, well, I don't mind that kind of downloading, I
> thought you meant an actual downloading of an exe. So
> if I use that HTML then it should automatically
> download the class to use on the internet?
Yep. Just like the browser automatically downloads images when it hits an <img> tag.
For example, it seems I need it in a .war file, or do I need to compress it to that? is it optional? And whats a .jsp file? It looks like a cross between a .java and .html file. It annoys me that they assume that you know all this and it's hard to find a good tutorial that doesn't assume you already know half the things it discusses and everything else about computers.
> For example, it seems I need it in a .war file, or do
> I need to compress it to that? is it optional? And
> whats a .jsp file? It looks like a cross between a
> .java and .html file. It annoys me that they assume
> that you know all this and it's hard to find a good
> tutorial that doesn't assume you already know half
> the things it discusses and everything else about
> computers.
Running your own webserver is way overkill for this. Just go to a free website like geocities, angelfire, etc. and make a site. I had an angelfire site way back in the day that I had an applet on, it was super easy. the war and jsp stuff is getting in to servlets and web apps, which you don't need to touch to run a simple applet.
> > For example, it seems I need it in a .war file, or
> do
> > I need to compress it to that? is it optional? And
> > whats a .jsp file? It looks like a cross between a
> > .java and .html file. It annoys me that they
> assume
> > that you know all this and it's hard to find a
> good
> > tutorial that doesn't assume you already know half
> > the things it discusses and everything else about
> > computers.
>
> Running your own webserver is way overkill for this.
> Just go to a free website like geocities, angelfire,
> etc. and make a site. I had an angelfire site way
> back in the day that I had an applet on, it was super
> easy. the war and jsp stuff is getting in to servlets
> and web apps, which you don't need to touch to run a
> simple applet.
Okay, so what would I do once I get a site? Where do I upload the files?
> Any decent web host should give you the instructions
> for this themselves - most likely through a
> "webshell" type interface if you're completely new to
> it.
Angelfire had this type of setup, where you'd just click a button to upload a file, and tell it what directory to put it in. Very simple, though it'll probably vary from site to site.
> Okay, I've uploaded the class file and put the HTML
> on the site, but it just shows up as an empty box
> with an x. Any idea what's wrong?
> http://gilgalvanti.angelfire.com/
java.lang.UnsupportedClassVersionError: Bad version number in .class file
You've compile your applet, with I guess 1.6 and your browser plug in is 1.5 or earlier.
I get this when I try to do what it says:
C:\Program Files\Xinox Software\JCreatorV3LE\MyProjects>javac -target 1.5 -bootc
lasspath jdk1.5.0/lib/rt.jar/-extdirs "" Problems.java
An exception has occurred in the compiler (1.6.0_01). Please file a bug at the J
ava Developer Connection (http://java.sun.com/webapps/bugreport) after checking
the Bug Parade for duplicates. Include your program and the following diagnosti
c in your report. Thank you.
java.lang.StringIndexOutOfBoundsException: String index out of range: 0
at java.lang.String.charAt(String.java:687)
at com.sun.tools.javac.main.Main.processArgs(Main.java:180)
at com.sun.tools.javac.main.Main.compile(Main.java:309)
at com.sun.tools.javac.main.Main.compile(Main.java:279)
at com.sun.tools.javac.main.Main.compile(Main.java:270)
at com.sun.tools.javac.Main.compile(Main.java:69)
at com.sun.tools.javac.Main.main(Main.java:54)
C:\Program Files\Xinox Software\JCreatorV3LE\MyProjects>
> Looked through the little documentation it had, and
> didn't see anything. Can't I do it from the command
> console?
Yes you can, in fact, I'd recommend it. Here's a tutorial that shows you how to compile and run your code from the command line:
http://java.sun.com/docs/books/tutorial/getStarted/cupojava/index.html
> > Looked through the little documentation it had,
> and
> > didn't see anything. Can't I do it from the
> command
> > console?
>
> Yes you can, in fact, I'd recommend it. Here's a
> tutorial that shows you how to compile and run your
> code from the command line:
> http://java.sun.com/docs/books/tutorial/getStarted/cup
> ojava/index.html
Thanks, but I already know how to compile them from the command line, but I'm asking how to compile them in 1.5 instead of 1.6 from the command line. The way that I tried already is shown above.
If you have 1.5 jdk installed already, you can either change your path so that it picks up the javac under the 1.5 directory, or call the correct javac version directly:
C:> C:\Program Files\Java\jdk1.5\bin\javac blah blah blah
Basically if you have multiple jdks installed, you have multiple versions of javac, and you just need to tell the system which one to run when you use javac.
> If you have 1.5 jdk installed already, you can either
> change your path so that it picks up the javac under
> the 1.5 directory, or call the correct javac version
> directly:
> C:> C:\Program Files\Java\jdk1.5\bin\javac blah
> blah blah
> Basically if you have multiple jdks installed, you
> have multiple versions of javac, and you just need to
> tell the system which one to run when you use javac.
Yeah but that's what I'm confused on how to do. What co I need to type to get it to compile the old version?