aspose file tools*
The moose likes Beginning Java and the fly likes Several Questions... Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Several Questions..." Watch "Several Questions..." New topic
Author

Several Questions...

Paul Alexandroff
Greenhorn

Joined: Aug 26, 2002
Posts: 4
Greetings All,
I recently started a project to create a 'battle calculator' for a PBeM I play and while it is progressing well I've run into several problems I'm hoping someone here can help me with.
I have searched through the forums and found answers to some questions but not these (or the answers I found I couldnt follow). I'm using JDK 1.3.1_02 & am currently downloading the Docs for it so feel free to tell me RTFM if its in there. Also I'm not sure if these are all beginner questions but I am definitely a beginner who has bitten off a little more than he can chew it seems...
Part of the reason for this project is to get my brain back up to speed for my second java subject which I start in a week (Uni's back WooHoo)...
OK to start with I'm using BreezySwing & javax.swing to do the GUI.
ie:

Now onto the problems :
1. I'm running some menus across the top using the BreezySwing JMenuItem command
ie

My problem here is I want to add submenus & cant figure out how to do it or even if its possible this way. If it isnt doable just let me know & I'll do it the long way by creating a MenuGroup etc...
2. Next up I've noticed weird stuff when doing some maths calculations.
ie (generic example)

Outputs the right numbers until i = 15 at which point it doesnt give 0.225 but 0.224999999 type answers. I've found posts here that indicate bigDecimal may be the way to get around this but thats something I have no idea about. Any pointers appreciated.
3. Rounding. Since I'm mimicing the PBeM engine code to do the calculations I need to round doubles to 2 or 3 decimal places at points. It seems (from posts here) that the only way around is to do something along the lines of multiplying it by 10 or 100, rounding that as an integer and then dividing by the original multiplyer. Is this correct? Is there any other way?
4. Running the code on other machines. I want to be able to distribute my program to others in my Game Clan to use. I have (again from a suggestion on this board) downloaded Excelsior JET to convert it to native code but this isnt working. What do I need to do to get the class to run on anyone elses machine? Assuming that dont have JDK etc installed of course
5. GUI. What is the best way to do a GUI? I'm just coding it into GBFrame and its OK but (due to my limited knowledge) its a bit rough. A pointer to a good tutorial would be most helpful here. I want to avoid a WYSIWYG program and do it by hand so I understand whats going on.
Well thats the major problems at the moment.
Thanks in advance for any help.


Wish I could think of something clever to say in my signature
Marilyn de Queiroz
Sheriff

Joined: Jul 22, 2000
Posts: 9043
    
  10
[I]2. Next up I've noticed weird stuff when doing some maths calculations.
ie (generic example)

Outputs the right numbers until i = 15 at which point it doesnt give 0.225 but 0.224999999 type answers. I've found posts here that indicate bigDecimal may be the way to get around this but thats something I have no idea about. Any pointers appreciated. [/I]

Double has problems with precision. How precise do you need to be?

Three options.
1) Multiply by 1000 (or whatever), do all the math in integer arithmetic and divide by 1000 (or whatever) at the end.

2) Use Math.round() (May be combined with option 1)

3) BigDecimal (may be somewhat slower)

4. What do I need to do to get the class to run on anyone elses machine? Assuming that don't have JDK etc installed of course

They can install just the JRE. They don't need the whole JDK.


JavaBeginnersFaq
"Yesterday is history, tomorrow is a mystery, and today is a gift; that's why they call it the present." Eleanor Roosevelt
Paul Alexandroff
Greenhorn

Joined: Aug 26, 2002
Posts: 4
Thankyou Marilyn - Since most of the figures start out as 3 decimal places your first suggestion will do it perfectly
With the question about making it usable on other computers I meant how do I work out which files I need to include and how do I package them? As a .jar file? Again if someone can point me towards a tutorial on this it'd be much appreciated
Marilyn de Queiroz
Sheriff

Joined: Jul 22, 2000
Posts: 9043
    
  10
jar file tutorial

My guess would be that you want to include all your *.class files, html files (if any), image files (gif/jpeg) and the manifest.mf file.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Several Questions...
 
Similar Threads
Beginners Java Game Book
Swing repaint() not working / might be a case of RFM / tried a few things but can't get it to work
Replacing GUI with new GUI
Eclipse debugging & 3rd party src code
How NOT to convert dollar to cents