Flo Powers

Ranch Hand
+ Follow
since May 12, 2004
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Flo Powers

Yeah, after looking at Sun's tutorial, I'm starting to get it. It pays off to do things right from the start - kind of like building a house - if the initial design is faulty, you're setting yourself up for trouble later.

May as well go directly to the source to drink, so I'll be hanging out at java.sun.com for a while, instead of trying to tinker with a program based on a flawed design.

Thanks!
13 years ago
Yes, just starting out with GUIs. Am reasonably familiar with OOP and data structures.

Wondering what book to use instead for GUIs. Any ideas? Good online sources?

Am a bit unsure when to use paint and when to use paintComponent.

Thanks!
13 years ago
But wait - if I extend JPanel, put the button, checkboxe and radiobuttons in this class, and then stick an object of this type into a program that extends JFrame, where do I put the listener objects? In the main class that contains this extended panel object, or in the class that extends JPanel?

Thanks!
13 years ago
Yes, I have been reading a bit online about it, and was starting to get the idea I may be using the wrong book... I'm using Deitel and Deitel, 3rd ed. (1999), and the examples on drawing are consistently using the paint method directly on the JFrame object (or rather the class extends JFrame, and paints on itself).

I'll try extending JPanel instead, and then insert an object of that type into my JFrame.

Thanks!
13 years ago
Hi, I've got a simple app that allows the user to drag up rectangles and ovals with the mouse. It works, except that the button and checkboxes don't show until I move the mouse over them. Guessing it has to do with the paint method. Any hints?

Thanks!

13 years ago
Hi, this may not be the right section for this post - may be an issue more suited under the swing section, for example - not sure...

I'm making a simple application that draws shapes on a JFrame (not with applet, but with a class that extends JFrame and has a main method). The paint method runs an endless while loop in which I invoke Thread.sleep(3000) in a try-catch block.

The try block also creates a Polygon with 3 - 8 points (all within the bounds of the window), and paints it with reference to the Graphics object. I then try to invoke repaint for each loop. I have experienced before that I've got that to work with applets, but not with an "application" (by which I mean it has a main method, and doesn't require an appletviewer or a web page in which to run).

It also doesn't unload the process from RAM when I click the close button on the window, even though in the main method I've added a WindowListener. Could that be because of the while loop with the Thread? I.e. it's not listening when I click, because the Thread is sleeping...?

I don't know what's wrong, other than (probably) my overall approach... Any comments? Here's the code so far:



[ March 27, 2006: Message edited by: Flo Powers ]
[ March 27, 2006: Message edited by: Flo Powers ]
Hi, I've been working on a few applets on my machine. They compile fine, and I can load them in the Appletviewer. However, when I tried to open them in IE (or Firefox, for that matter), one of them would freeze up, while the others would run. After a while, none of them would load. I suspect a Java thread was still running (I checked the task manager, and had to terminate the process a few times - could also be working hard running Nortan virus scan and Eclipse at once, with 512MB RAM?).

Anyway, they worked fine in the Appletviewer, and when I tried uploading to my website, it was no problem opening them - they ran like a dream.

Any ideas? It's not a huge hassle - it seems I can trust what I see in the Appletviewer, and the plan is to upload them eventually, so it doesn't really matter so much if I can't view them locally. It's just annoying, and I'm wondering what could be wrong.

Here's what the console has to say:

Java Plug-in 1.5.0_06
Using JRE version 1.5.0_06 Java HotSpot(TM) Client VM
User home directory = C:\Documents and Settings\My name


----------------------------------------------------
c: clear console window
f: finalize objects on finalization queue
g: garbage collect
h: display this help message
l: dump classloader list
m: print memory usage
o: trigger logging
p: reload proxy configuration
q: hide console
r: reload policy configuration
s: dump system and deployment properties
t: dump thread list
v: dump thread stack
x: clear classloader cache
0-5: set trace level to <n>
----------------------------------------------------

Exception in thread "Thread-2" java.lang.IllegalArgumentException
at sun.net.www.ParseUtil.decode(Unknown Source)
at sun.net.www.protocol.file.Handler.openConnection(Unknown Source)
at sun.net.www.protocol.file.Handler.openConnection(Unknown Source)
at java.net.URL.openConnection(Unknown Source)
at sun.applet.AppletPanel.getAccessControlContext(Unknown Source)
at sun.applet.AppletPanel.getClassLoader(Unknown Source)
at sun.applet.AppletPanel.createAppletThread(Unknown Source)
at sun.applet.AppletPanel.init(Unknown Source)
at sun.plugin.AppletViewer.createClassLoader(Unknown Source)
at sun.plugin.AppletViewer.appletInit(Unknown Source)
at sun.plugin.viewer.LifeCycleManager.initAppletPanel(Unknown Source)
at sun.plugin.viewer.IExplorerPluginObject$Initer.run(Unknown Source)
[ March 10, 2006: Message edited by: Flo Powers ]
13 years ago
Well, potentially, this could grow to be a very large number of rooms - in the online games, we're talking thousands of rooms. Even if I only have say 50 rooms, it seems awkward to use individual room object references. As far as I can tell, there should be some data structure for storing them.

If I make it a very simple and structured world, each room would have max four exits (connections to other rooms), east, west, north and south. And presumably, if from room A we go east, then north and then west, we should be in the room next to where we started (one room north of A). I was wondering if I could use linked structures (LinkNodes with four LinkNode references east, west, north and south), but I could not see a simple way to automate that spatial logic (east, north and west = north). It seemed awkward to have to manually hardcode the links between room objects. An array using just counters would take care of that, but is that the way it should be done or is there a better way?
13 years ago
I am learning Java (well, do you ever finish learning?), and decided to try and make a simple textbased game to set myself an interesting task. I have some idea of what text games are all about (played "The hobbit" a couple of decades ago, and have since tried MUDs for example, but don't know much about their internal design.

I intend to make a single-player game to begin with, and have made a GUI terminal with a textfield for entering commands and a display for the text to display. I can enter commands, and the world object uses multithreading to allow time to pass (one minute itrl = one hour in my game), and the weather to change. When events happen (e.g. the church bell rings every hour), this is described in the scrolling text.

However, I am unsure how best to organize room objects. I imagine having a room object that can contain item objects, non-playable character objects and even other rooms possibly. But how best to arrange this? Is it an idea to put room objects in a 2D (or even 3D) array, or is there a better way? Maybe I'm going about it the wrong way.

I imagine saving all rooms and items, and the stats for the player object to a file (autosave every five minutes), so the player can continue from the same point next time s/he starts the game. I also imagine having a login, so you can have different games underway. Finally, if you log in as admin, you can also edit rooms, add rooms, etc.

The next step I guess is to create the world as a separate program, and then let people connect - I'm thinking perhaps RMI might be a way to let me run the main program as a sort of "server" program and then let more than one player enter the game at once (on a LAN). Of course, this is not as good as having it run on an Internet server and using a proper MUD library, but hey - I'm only just starting out and like the challenge of making it from scratch...

Thanks for any hints!
13 years ago
Thanks, I'll experiment with that. I also decided I probably need to create a console with which to interact with this World object - commands are entered in a JTextField, and when the user presses enter, it commits the command. What I was trying before was a loop that inputs user commands in a program running in the command prompt. I think this made the program wait for user input.

Thanks! Will ask again if (when) I get stuck again (and cannot find answers in the thread you provided a link to).
13 years ago
Hi, I am trying to work out how to work with multithreading. I'm guessing that's what's needed. To experiment, I've set myself a little challenge, but I get the feeling I may be trying to go about it the wrong way.

Here's what I'm trying to make: a game-like environment where there's a world object, with instance variables hour, minute and description. The description is a simple String and changes both with the time (day/night) and randomized weather (every hour or so, it may go cloudy or sunny, and during the night, there may or may not be a moon out). This class extends Thread, and I am using the sleep( ) method with an argument of 3000 milliseconds to make time go by and let the weather change. One minute in the real world is one hour in this world object. When I create a World object, and watch it tick along, I can see that it works. Inside the constructor is a loop that outputs the time and the description.

The problem: I also want to have a player object that can do things. I have created another class that inputs user commands (for now, just "Look", "Time" and "Quit". However, I can't make both things work. When I create a World( ) object it never waits for me to do input. I guess this is because the constructor in the World object loops forever. If I try to put the user input as part of this loop, it interrupts the thread, as it pauses while waiting for user input.

What I would like: a World object where time passes and the weather changes, and at the same time the ability to have user input (when the user wants) of commands and have the world object return Time or description.

If you see a simple logic flaw and could give a pointer in the right direction, I'd be mighty grateful.

Thanks!
13 years ago
Thanks for your answer, but I'm afraid I'm going to need a bit more help.

I've never written a batch file, so... the line of code you wrote goes in the batch file?

Flo

Wow! I tested it - put the line in a text file (with the rigth jar file name), saved it as a .bat file and double-clicked it, and voila! It works!

THANK YOU! )
[ February 21, 2006: Message edited by: Flo Powers ]
13 years ago
Hi, thanks for the replies. I've managed to make the program load the browser, but am unsure about the part that directs the browser to a particular URL. The program inputs from the user a URL as a String. I guess what I'm looking for is the DOS command to load a web browser and direct it to a particular URL...

Thanks!
13 years ago
Sorry, careless wording on my part. What I mean is, I've made two different programs, one that displays a GUI using swing, and one that runs in the command prompt (or perhaps "console" is a better word for it?). I made two different executable JAR files (using Eclipse - really easy). However, when I click on the one that has a GUI, it loads fine. When I click on the one that requires a console in which to run, nothing happens.

Is there a(n easy) way to make this CLI program run when I double-click the JAR file?

Hope that was a bit more precise. Thanks again!
[ February 08, 2006: Message edited by: Flo Powers ]
13 years ago
Hi, I looked at the thread on creating executable jar files at http://www.coderanch.com/t/391746/java/java/Game-Tutorials-Creating-Executable-JAR and this worked fine for an application, but I don't know if it's possible to do the same with a program that runs in the command prompt. Any ideas?

Thanks!

[EDIT by mw: Repaired link.]
[ February 05, 2006: Message edited by: marc weber ]
13 years ago