[java] Java questions

Started by
28 comments, last by eedok 20 years, 6 months ago
Buttons in Java are confusing me, all I want to do is set a button to an absolute position, and one is clicked to remove them, or place them offscreen. Does anyone here know how to do this? [edited by - eedok on September 24, 2003 1:23:16 AM]
Advertisement
Do something like "setLayout(null);", then to place your buttons, do something like "jButton1.setBounds(x, y, width, height);", then add it to the panel with the null layout. And to remove them just say "jPanel1.remove(jButton1);" and its gone. I believe that should work.
quote:setLayout(null);
This is exactly what I needed thx
I just got another question, I want to put a timer in my game,to go down 1 once a second, how would I go about doing so?
Im fairly new to java, but I believe I can help...

go here and look at javax.swing and go down to Timer.


int delay = 1000; //millisecondsActionListener taskPerformer = new ActionListener() {      public void actionPerformed(ActionEvent evt) {          //...Perform a task...      }};new Timer(delay, taskPerformer).start();


Seems pretty simple to me...


Later,
Lord Hen
Well if anyone was wondering here's the game I ended up making

http://www.voidofmind.com/eedok/game/msStones.html

it's only 2p mode right now but I'm working on making a 1p version and a bunch of other things..

There's a couple other things I am wondering,
a.) The next game I want to get on to making is a stepping stone game (like pong was to my stones game), I'd like it to be a maze game, that would read the maze from a file(created by a level editor in C or C++ whatever I end up using), how hard would it be for a java applet to read this file if it was in the codebase?

b.) My current games both use awt, instead of Swing, mostly due to the fact that my references are outdated, And it also uses the KeyUp & KeyDown API, which is deprecated. So, b1.)What are some reasons to update the deprecated Api's to newer ones? and how hard would it be to change it? and b2.)Why should I switch from awt to Swing? and also how hard would it be.

c.) Is there a tutorial on using objects in java, and what advantages would be gained with using objects in my games?

d.) Is there an article/tutorial aimed at java on coding habits that should be made, just in case I decide to move away from being an independant game developer?

e.) Here's for the people who have tried my game, is there things that I've done wrong, and should be changed?

Sorry for the onslaught of questions, but I don't expect an answer to each one of these..


[edited by - eedok on September 29, 2003 3:02:58 PM]

[edited by - eedok on September 29, 2003 3:04:12 PM]
a) It wouldn''t be hard at all. But why don''t you just use Java to make your map editor?

b1) Any current code you have may not matter if you don''t plan on doing anything else with it. Any new code you make should avoid deprecated APIs. It''s not difficult to change, just may be time consuming.

b2) You don''t necessarily need to switch. Swing has a richer set of features, including pluggable look and feel. AWT tends to run faster because it uses native GUI widgets to draw the GUI elements, where Swing draws everything in Java.

c) I would first recommend reading "The Java Tutorial". It is free online at http://www.gamedev.net/community/forums/topic.asp?topic_id=181801. You can also download it and do it offline. You can also do a search for "The Black Art of Java Game Programming" If you can find it, it is free online. It is a bit dated for the APIs it uses, but it shows how to lay things out. If you can''t find it, drop me a line and I can get it to you.

d) You can look for a book called "Code Complete". It deals more with procedural style languages, but it is not a bad place to start. Or check the bookstores for something similar in object oriented programming.

e) Looks pretty good.


First make it work,
then make it fast.

--Brian Kernighan

"The problems of this world cannot possibly be solved by skeptics or cynics whose horizons are limited by the obvious realities. We need men and women who can dream of things that never were." - John Fitzgerald Kennedy(35th US President)
"None of us learn in a vacuum; we all stand on the shoulders of giants such as Wirth and Knuth and thousands of others. Lend your shoulders to building the future!" - Michael Abrash[JavaGaming.org][The Java Tutorial][Slick][LWJGL][LWJGL Tutorials for NeHe][LWJGL Wiki][jMonkey Engine]
the answer to c is just a link that goes nowhere, but every other answer is good thank you CaptainJester, but what is the link sposed to be for c?
That is a key advantage to using objects: that you can use Java''s object serialization to create your map editor. Think of this:

You have created a class called Level. A Level is a two-dimensional array of Tiles (and however you want to define the Tiles is up to you). I think the Level class should have both accessor and mutator methods. Anyway, once those classes are created, you can make a Java program (a map editor) that creates and/or manipulates a Level object (through the mutator methods) and saves it to the hard drive (serialization ). Then your game can take that file, open it, and recreate the Level object. Your game won''t modify the Level object, it will only access it. By accessing the Level object, the game can figure out what to draw for each frame.

Look up Java''s serialization features and object streams on Sun''s website and the API. That should help you understand the benefit of using objects to create Java games. Of course, these serialized objects will probably take up a little more space than a crafty text file format but they will probably be more flexible.

Over the centuries, mankind has tried many ways of combating the forces of evil...prayer,
fasting, good works and so on. Up until Doom, no one seemed to have thought about the
double-barrel shotgun. Eat leaden death, demon...
-- Terry Pratchett
Over the centuries, mankind has tried many ways of combating the forces of evil...prayer,fasting, good works and so on. Up until Doom, no one seemed to have thought about thedouble-barrel shotgun. Eat leaden death, demon... -- Terry Pratchett
quote:Original post by eedok
the answer to c is just a link that goes nowhere, but every other answer is good thank you CaptainJester, but what is the link sposed to be for c?


Whoops, that should have been http://java.sun.com/docs/books/tutorial/

I would reccomend doing everything up to the specialized trails before doing anything else. Then you can go on with the specialized trails or do them as needed.


First make it work,
then make it fast.

--Brian Kernighan

"The problems of this world cannot possibly be solved by skeptics or cynics whose horizons are limited by the obvious realities. We need men and women who can dream of things that never were." - John Fitzgerald Kennedy(35th US President)
"None of us learn in a vacuum; we all stand on the shoulders of giants such as Wirth and Knuth and thousands of others. Lend your shoulders to building the future!" - Michael Abrash[JavaGaming.org][The Java Tutorial][Slick][LWJGL][LWJGL Tutorials for NeHe][LWJGL Wiki][jMonkey Engine]

This topic is closed to new replies.

Advertisement