Spiegel - CSC 421 Web-Based Java Programming |
Opening Message
|
Subject: Opening Message
|
Poster: dspiegel | [b:d06494a864]Why haven't you posted yet?[/b:d06494a864] |
Subject:
|
Poster: kkemm923 | :) I just wanted to try this out -- to answer the quesion, I have now posted!!!! |
Subject:
|
Poster: mgove131 | :shock: that's a good question |
Subject:
|
Poster: mhiba775 | Post. |
Subject:
|
Poster: MarkSchlosser | Posting 1,2,3.... |
Subject:
|
Poster: eleva340 | Posting 5,6,7... |
Subject:
|
Poster: MarkSchlosser | [quote:13f801234f="eleva340"]Posting 5,6,7...[/quote:13f801234f]
You missed 4! |
Project 1 Requirements Update & Due Date
|
Subject: Project 1 Requirements Update & Due Date
|
Poster: dspiegel | 1. Display the computer's ships with not yet hit points for easier testing.
2. The spot on which a ship is placed is its upper or left-hand edge.
Due date: Saturday September 29 @ 11:59 PM |
Turn Object
|
Subject: Turn Object
|
Poster: mkling |
So....we're putting a reference to the space as a data member here.
What other info does a turn know?
I'm confused why we would not just give the player object a vector of
space references to represent turns if all the turn object has is a
space (which really is all a turn is, a player picks a space. He gets a
result, but that could be found by querying the space) |
Subject:
|
Poster: mgove131 |
yeah, i'm trying to plan out how this game will work, and i'm not sure
if a turn is needed or not. can anyone justify having the class or not
having it? |
Subject: Re: Turn Object
|
Poster: thege033 |
I have found that most of the methods I would put into the turn object
can be handled in my main game or battleship object. I'm a few hours in
to the project and have not really found a use for it yet. |
Subject: Turn
|
Poster: mshar306 |
The only thing that the turn object might be useful for is updating the
state of the space object. If you have a vector of turn objects for
each player and each turn having a status(hit or miss) , you could use
that informaton to update the state of the space object for that turn.
This would be useful for the grid. This is what I am thinking anyway. |
Subject:
|
Poster: Vinnie |
The only advantage to having a turn object I think would be so that the
player could know if a turn was already taken before they attempt to
actually do it. Like someone else said, you could just query the grid,
but let's assume that we do it they way that Mike said in class where
each player has it's own grid. That means you either have to ask first,
then take a shot every time. Or, you take a shot and get a "you already
tried that one" message.
Consider taking a random shot. Towards the end of the game, it's going
to be tough trying to find an empty spot randomly. Keeping track of
your own turns could possibly make it a little less messy. I think it
can only help keeping track of your own turns made.
Any other points of view? |
Subject:
|
Poster: eleva340 |
I think it depends what you're putting in the Turn. If it's just a
Space, then why not just make a collection of Spaces and save yourself
the extra class. I don't see a need for Turn... yet. |
Subject:
|
Poster: parkmw |
At the end of the game you could potentially have a lot of turn objects
saved up from the game. Would you really want have to search through
them to see if you already tried a space or would it be faster to just
ask the space if it was already hit?
The turn object would be useful though for the AI part of the game I
think since it can help you keep track of how many hits in a row you
have had and possible places to make your next hit. |
Subject:
|
Poster: mkling |
[quote:ed218c6529="parkmw"]At the end of the game you could potentially
have a lot of turn objects saved up from the game. Would you really
want have to search through them to see if you already tried a space or
would it be faster to just ask the space if it was already
hit.[/quote:ed218c6529]
What if you stored every possible space in a vector, and when a space
was used, the space was removed from the vector, so that only
non-called spaces would be in the random selection tool. |
Subject:
|
Poster: mgove131 |
[quote:949a4cc4c8="mkling"]
What if you stored every possible space in a vector, and when a space
was used, the space was removed from the vector, so that only
non-called spaces would be in the random selection
tool.[/quote:949a4cc4c8]
I like that idea. Also, to keep track of the moves that were hits by
adding them to a set. when you sink a ship (you are told when this
happens, and which ship it is), you can remove those spaces from the
set (you know the end point of the ship, and how many spaces the ship
has). The only problem I can think of is the two ships with 3 spaces
might be confusing if they are next to each other with a bigger ship.
ex:
OOO
OOO
OOOOO
Depending on the order call, there can be potential confusion on if one
of the 3 space ships were oriented vertically or horizontally. As long
as you keep your orientation with your first guess (meaning only
guesses vertical or horizontal to the first guess), I think it will
work. Any remaining hits will be left in the set when you remove the
sunk ship, and you can guess around those. |
JCreator Setup
|
Subject: JCreator Setup
|
Poster: eleva340 |
Make sure you have the JDK installed before you install JCreator. Then
it will automatically detect the folder for java, but you still have to
add whatever folder you're working with into the CLASSPATH.
Go to Configure - Options, then JDK Profiles. I think you can add more
than one version, which might be nice. Anyway, just click the add path
button and drill down to your folder and it will add it. |
Subject:
|
Poster: mkling | how does JCreator compare to Netbeans.... |
Subject:
|
Poster: parkmw |
JCreator is written in C++ and Netbeans is written in Java so i would
say its faster. Also Netbeans i think has GUI stuff in it? JCreator is
more like VC++ in that its pretty straightforward, it also has auto
complete i believe. |
Subject:
|
Poster: Vinnie |
I like Eclipse if anyone is interested in that. I used Netbeans for a
while but it never seemed to work right after I upgraded to Vista. It
might be a good idea to start with something that has GUI capabilities
before you get used to using a text editor. Trying to get some one to
switch their editor is like getting them to switch their religion. One
thing I should mention is that I don't even know if Eclipse even has
GUI capabilities because I just started using it, but I'm pretty sure
it does. What's cool is that you can just click on the run button
without setting up a classpath and it will even show you a System.out
window at the bottom. No need to toggle between screens. However, you
probably should know how to setup a classpath for Spiegel because he
might test you on it. I also have my classpath set up so I can either
run it from Eclipse or the command prompt if I wanted to. |
Subject:
|
Poster: mgove131 |
[url]http://java.sun.com/javase/downloads/index_jdk5.jsp[/url]
in case anyone needs it, since acad uses 1.5. I clicked the first
download button, 'http://java.sun.com/javase/downloads/index_jdk5.jsp'
. You have to go through a bunch of links and the installer downloads
with some java downloader. Eventually I got it installed though. |
Subject:
|
Poster: eleva340 | I downloaded 1.5 and 1.6. I have no idea which one I'm compiling with though... |
Subject:
|
Poster: gsmit466 | Vista Compatible. |
Subject:
|
Poster: mgove131 |
[quote:74c14c686d="eleva340"]I downloaded 1.5 and 1.6. I have no idea
which one I'm compiling with though...[/quote:74c14c686d]
it [b:74c14c686d]should[/b:74c14c686d] be 1.5 as long as that's what
you put in your path first. that's what i did, i hope it works :shock: |
Subject:
|
Poster: gsmit466 | I can't seem to get 1.5 on unix.. Have any of you successfully be able to do that? |
Subject:
|
Poster: mgove131 | yes, heres how i have it set up in bash
CLASSPATH=.:$HOME/cis421/java:/usr/jdk1.5.0_03/bin:/usr/jdk1.5.0_03/lib/:$CLASSPATH
JAVA_HOME=/usr/jdk1.5.0_03
PATH=/usr/jdk1.5.0_03/bin:(whatever else you had)
i don't know if you need everything in the classpath, but it works for me |
Subject:
|
Poster: gsmit466 | Nice it works.. Thanks mike
acad:gsmit466 18 ->java -version
java version "1.5.0_03"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_03-b07)
Java HotSpot(TM) Server VM (build 1.5.0_03-b07, mixed mode)
only thing thats werid is that when I log on, it says
CLASSPATH: Undefined variable
my .cshrc
----------------
setenv CLASSPATH=.:$HOME/java:/usr/jdk1.5.0_03/bin:/usr/jdk1.5.0_03/lib/:$CLASSPATH
JAVA_HOME=/usr/jdk1.5.0_03
PATH=/usr/jdk1.5.0_03/bin
CDPATH $home/cdpath
set filec
------------------
But java works fine. |
Subject:
|
Poster: slove843 |
[quote:efafb4ef6c="Vinnie"]I like Eclipse if anyone is interested in
that. I used Netbeans for a while but it never seemed to work right
after I upgraded to Vista. It might be a good idea to start with
something that has GUI capabilities before you get used to using a text
editor. Trying to get some one to switch their editor is like getting
them to switch their religion. One thing I should mention is that I
don't even know if Eclipse even has GUI capabilities because I just
started using it, but I'm pretty sure it does. What's cool is that you
can just click on the run button without setting up a classpath and it
will even show you a System.out window at the bottom. No need to toggle
between screens. However, you probably should know how to setup a
classpath for Spiegel because he might test you on it. I also have my
classpath set up so I can either run it from Eclipse or the command
prompt if I wanted to.[/quote:efafb4ef6c]
Agreed. I love Eclipse. It does have a
[url=http://www.eclipse.org/vep/WebContent/main.php][color=blue:efafb4ef6c]Visual
Editor[/color:efafb4ef6c][/url]. Granted its Visual Editor looks up to
Netbeans as the carrot dangling from stick above it, but what it lacks
in the visual editor it makes up for 10 times over in its community
base and modularity. I just got the Adobe Flex 2 SDK and editor. It's a
standalone Eclipse install, or you can just drag and drop the folders
on top of your C:\Eclipse folder... and at the same time drop the same
files on your Linux box and it runs just the same. If you don't mind it
being a bit slower, use the same exact base on both running on top of
Java instead of binary installations. Extra points for sharing your
settings folder on a network and not having to reconfigure each time
you switch operating systems, computers, etc. (I'm looking at you,
Visual Studio - registry keys, and settings have to be imported and
exported to have them as files). Red Hat Studio just started using
Eclipse as its base, as well as many of the CRM suites. OK, so, maybe
I'm a bit of a fanboy - but any community that releases 21 projects
[b:efafb4ef6c]on the same day[/b:efafb4ef6c], [b:efafb4ef6c]2 years in
a row[/b:efafb4ef6c] (ref:
[url=http://www.eclipse.org/projects/callisto.php][color=blue:efafb4ef6c]Callisto
Simultaneous Release[/color:efafb4ef6c][/url],
[url=http://www.eclipse.org/europa][color=blue:efafb4ef6c]Eclipse
Europa Release[/color:efafb4ef6c][/url], and upcoming
[url=http://www.eclipse.org/projects/ganymede.php][color=blue:efafb4ef6c]Ganymede
Simultaneous Release[/color:efafb4ef6c][/url]) impresses the crap out
of me. Just my $.02. |
Subject:
|
Poster: Vinnie |
[quote:ccf53fa4af="slove843"]
Agreed. I love Eclipse. It does have a
[url=http://www.eclipse.org/vep/WebContent/main.php][color=blue:ccf53fa4af]Visual
Editor[/color:ccf53fa4af][/url]. Granted its Visual Editor looks up to
Netbeans as the carrot dangling from stick above it, but what it lacks
in the visual editor it makes up for 10 times over in its community
base and modularity. I just got the Adobe Flex 2 SDK and editor. It's a
standalone Eclipse install, or you can just drag and drop the folders
on top of your C:\Eclipse folder... and at the same time drop the same
files on your Linux box and it runs just the same. If you don't mind it
being a bit slower, use the same exact base on both running on top of
Java instead of binary installations. Extra points for sharing your
settings folder on a network and not having to reconfigure each time
you switch operating systems, computers, etc. (I'm looking at you,
Visual Studio - registry keys, and settings have to be imported and
exported to have them as files). Red Hat Studio just started using
Eclipse as its base, as well as many of the CRM suites. OK, so, maybe
I'm a bit of a fanboy - but any community that releases 21 projects
[b:ccf53fa4af]on the same day[/b:ccf53fa4af], [b:ccf53fa4af]2 years in
a row[/b:ccf53fa4af] (ref:
[url=http://www.eclipse.org/projects/callisto.php][color=blue:ccf53fa4af]Callisto
Simultaneous Release[/color:ccf53fa4af][/url],
[url=http://www.eclipse.org/europa][color=blue:ccf53fa4af]Eclipse
Europa Release[/color:ccf53fa4af][/url], and upcoming
[url=http://www.eclipse.org/projects/ganymede.php][color=blue:ccf53fa4af]Ganymede
Simultaneous Release[/color:ccf53fa4af][/url]) impresses the crap out
of me. Just my $.02.[/quote:ccf53fa4af]
Yea I'm loving Eclipse more and more as I use it. Debugging in this
thing is like a dream come true. I can dynamically set breakpoints and
change code AS I'm debugging!! That's great. Plus the instant syntax
checking and linking is cool to. If I forget to import a class, no
problem. Eclipse puts the import statement at the top automatically. It
even warns me if I'm not doing some of the Java "norms" like
Capitalizing certain letters or using Static members when I'm not
supposed to. Ok, enough with the nerdyness. I'm
done.javascript:emoticon(':oops:')
Embarassed |
Subject: Just a bit more geekyness
|
Poster: slove843 |
A plugin for Eclipse that I've found invaluable for almost every
language I work with is its SSH plugin; open an FTP connection, and
work with the file where ever it is and then run it remotely via SSH
without ever having to switch desktops or alt+tab to another window. |
Subject:
|
Poster: mkling |
Eh, I've just been using NetBeans.... Seems to work ok for me, except
that it gets very angry with me if I don't use packages. Maybe I'll try
Eclipse once I have some free time. :shock: |
Subject:
|
Poster: SPS | NetBeans is working fine for me too.... |
Subject:
|
Poster: mgove131 |
[img:01e1e19934]http://studentwebs.kutztown.edu/mgove131/images/ge2001.png[/img:01e1e19934]
that's the problem i found with jcreator (i don't have pro). i'm not
sure if it's just my computer, but when i kill a running program,
apparently it stays running with a java.exe and a GE2001.exe, and it
just builds up over time. |
Subject:
|
Poster: gsmit466 | Run it on acad and hog their memory up. |
Subject:
|
Poster: slove843 |
[quote:e000df1308="mgove131"]
that's the problem i found with jcreator (i don't have pro). i'm not
sure if it's just my computer, but when i kill a running program,
apparently it stays running with a java.exe and a GE2001.exe, and it
just builds up over time.[/quote:e000df1308]
You have to set your close operation or exit the process manually,
otherwise you're just killing the window and leaving the parent.
[code:1:e000df1308]
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
[/code:1:e000df1308]
or
[code:1:e000df1308]
System.exit(0);
[/code:1:e000df1308]
...or, just run it on acad - so long as I'm not logged in at the time!
:D |
Java version
|
Subject: Java version
|
Poster: gluca526 |
We discussed using enum in class for the space object. When using it in
unix I get an error saying class or interface expected. I tried it
using the command line in Windows and it worked fine. Is it because the
java version on unix is older and doesn't use enum? |
Subject:
|
Poster: dspiegel | Check this URL:
[url]http://www.java2s.com/Code/Java/Language-Basics/Enum.htm[/url]
enum in Java appears to be like a class. Well, sort of... |
Unchecked/Unsafe Vector use
|
Subject: Unchecked/Unsafe Vector use
|
Poster: mshar306 |
I just wanted to give everyone a heads up about Vectors. I was getting
an unsafe warning message when trying to create a vector of ships.
After a little research, I found if your using java 1.5 then you need
to specify the type. I guess older versions did not need this. |
Using the CLASSPATH variable in a jarfile.
|
Subject: Using the CLASSPATH variable in a jarfile.
|
Poster: MarkSchlosser |
I wanted to package my Battleship game into a jarfile, but encountered
a problem. When I would run the jarfile using "java -jar
battleship.jar", the jar wouldn't be able to find Spiegel's Input
class. This is because java -jar ignores the system's CLASSPATH
variable and checks for the CLASSPATH defined in the jarfile's
MANIFEST.MF file.
The workaround I came up with involves generating a custom Manifest
file for the jarfile based on the system's classpath. This can be part
of your Makefile or whatever build process you're using.
This is the rule in my Makefile to create the custom Manifest file:
[code:1:3a4a1abe0d]
## Generate the manifest file
manifest: @echo "Manifest-Version: 1.0" > $(BINDIR)Manifest @echo
"Class-Path: $(JARCLASSPATH)" >> $(BINDIR)Manifest @echo
"Created-By: MWS" >> $(BINDIR)Manifest @echo "Main-Class:
BattleshipGame" >> $(BINDIR)Manifest @echo Generated Manifest.
[/code:1:3a4a1abe0d]
BattleshipGame is my entry point class.
JARCLASSPATH is a macro I defined earlier in my Makefile using:
[code:1:3a4a1abe0d]
JARCLASSPATH = $(shell echo $(CLASSPATH) | sed "s/:/ /g")
[/code:1:3a4a1abe0d]
The piping of the CLASSPATH to sed is necessary because the Manifest
file expects spaces between directories, not : symbols. The sed command
strips all the : symbols, replacing them with spaces. If you're on
Windows, the : symbols will be semicolons.
Then to package the jarfile using the custom Manifest, I use:
[code:1:3a4a1abe0d]
jar cfm battleship.jar $(BINDIR)/Manifest -C class/ .
[/code:1:3a4a1abe0d]
where class/ is a subdirectory containing all my .class files.
A brief note: "make" on Solaris has a bug when processing the
JARCLASSPATH definition. Use "gmake" instead.
- Mark |
User-Defined Data Types
|
Subject: User-Defined Data Types
|
Poster: pascenzo |
Is there a way to create User-Defined Data types in Java. I want to
make one for the Location so it has a row and a column. Is it just a
class? |
Subject:
|
Poster: MarkSchlosser | You can actually add data members and methods (even constructors) to an enumeration type.
quick example:
[code:1:cc0d001eb8]
public enum CarType
{
Sedan, Van, SUV;
private boolean m_isLarge;
public boolean getIsLarge () {return m_isLarge;}
public void setIsLarge (boolean isLarge) {m_isLarge = isLarge;}
}
[/code:1:cc0d001eb8]
Not sure if this is what you're aiming at. |
Subject:
|
Poster: dspiegel | Check Point in the Java API. |
Subject:
|
Poster: pascenzo |
I looked at point and it looks like it could work, but if we are using
a letter to represent a row then how would I use Point? Would I just
have to set the row to the ascii value the letter? |
Subject:
|
Poster: MarkSchlosser |
What I'm doing is converting both values to a range 0-9.
so 'a' or 'A' becomes 0, 'b' or 'B' becomes 1, etc.
And an easy way to do that is to subtract 97 from the integer value of
the character (if lowercase) then checking that it's in that range.
Mark |
Subject:
|
Poster: mkling | [quote:e3fcb27b07="MarkSchlosser"]What I'm doing is converting both values to a range 0-9.
so 'a' or 'A' becomes 0, 'b' or 'B' becomes 1, etc.
Mark[/quote:e3fcb27b07]
This is what I'm doing as well, except I didn't bother with the Point class, just gave it an int row, int col attribute. |
Subject:
|
Poster: SPS |
What I have done is ...
I created a string[] one for the rows as alphabets and one for columns
as numbers and used setLocation() and setState() to set the location as
"A1" and state 'C' for clear respectively using the object of "space of
a grid".
Use objects, it becomes quite easy instead of converting the numbers. |
Subject:
|
Poster: pascenzo |
[quote:d2b24474e1="SPS"]What I have done is ...
I created a string[] one for the rows as alphabets and one for columns
as numbers and used setLocation() and setState() to set the location as
"A1" and state 'C' for clear respectively using the object of "space of
a grid".
Use objects, it becomes quite easy instead of converting the
numbers.[/quote:d2b24474e1]
You did this using Point or did you create a new class |
Subject:
|
Poster: gsmit466 |
btw, for printing the letters for the grid output, you can use (char)65
and that would print out an A.. so really jsut setup a variable letter
with a starting value of 65 for A and just (char)letter++ it everytime
you draw a new row to print the next letter. Makes it somewhat easier
and exspandable. |
Subject:
|
Poster: SPS |
I didnt use Point , used the class Grid and had a separate method for
it. What I have come up is , at some point or other in the program you
would have to convert , so initially i used objects and then when
mounting the ships , i just use toUpperCase() and -65 for the char
input. |
Subject:
|
Poster: mkling |
I've changed my mind and actually do use the Point object now, but just
so that I can group the row/col attributes together into an object for
a single return type. It's still stored as 2 integers in my Space/Grid
objects though. |
Any DEBUG macros in Java?
|
Subject: Any DEBUG macros in Java?
|
Poster: nstor641 |
I know there is a debug macro in C/C++ to switch debug messages on/off.
Is there anything like this for Java? b/c right now I'm commenting
System.out.print out and back in and it's becoming a real pain. |
Subject:
|
Poster: MarkSchlosser | The only solution I've found is making a file with a public class that has "defines" in it like:
[code:1:0292087266]
public class GlobalDefines
{
public static final boolean DEBUG = false;
}
[/code:1:0292087266]
and then in your code, instead of doing
[code:1:0292087266]
#ifdef DEBUG
printf ("Debug message!\n");
#endif
[/code:1:0292087266]
you'd do:
[code:1:0292087266]
if (GlobalDefines.DEBUG)
{
System.out.println ("Debug message!");
}
[/code:1:0292087266] |
Grid output && placement
|
Subject: Grid output && placement
|
Poster: thege033 |
I'm running into a little trouble with my implementation going through
the game loop. I'm pretty sure I have an understanding of this but just
to make sure. Depending on how you implement your game it may be
different but I have it so that each player object has their own grid
object.
In real battleship you have two grids, one with your ships and your
opponents attacks and one with your own attacks. In the game though the
user is only concerned with their own attacks since the computer will
calculate hits and sinks. When you place the ships you put them on your
own grid but during each turn you attack your opponents grid.
So you'll have to update their grid and output their grid after the
attack to show the user the state of their attacks. Therefore i'm
coming to the conclusion that each player may not want to have their
own grid since you will need to update opposite grids at different
parts in the game. |
Subject:
|
Poster: mkling |
I have the game object create 2 grids. Each player object knows about
both grids, so he places his ships on one, and shoots on the other. |
Subject:
|
Poster: KyleFox |
I have an abstract class Player, and then two subclasses named
HumanPlayer, and CompterPlayer. In my abstract player class I have a
data member for the player's grid, and also a reference to the
opponents grid. I then set the opponents grid after instantiating
HumanPlayer and ComputerPlayer in my main class Battleship. This allows
HumanPlayer and ComputerPlayer to check and modify eachother's grids.
Hope that helps,
-Kyle |
Enumeration Types
|
Subject: Enumeration Types
|
Poster: ted_gress |
I was wondering if anybody so far has successfully gotten the
enumerations to work. For some reason Java isn't recognizes the
constants. So for a statement like
enum SpotStatus { hit, miss, clear }
it won't recognize the words hit, miss, or clear later on when they are
referenced in the code. |
Subject:
|
Poster: MarkSchlosser | You need to explicitly specify that the status is part of the SpotStatus enum.
Example:
SpotStatus stat = SpotStatus.hit;
- Mark |
Subject:
|
Poster: mgove131 |
[quote:0060922f8c="MarkSchlosser"]You need to explicitly specify that
the status is part of the SpotStatus enum.[/quote:0060922f8c]
except when you use a switch statement
switch (stat)
{ case hit: break;
}
java assumes that you mean SpotStatus.hit |
Formatting Output
|
Subject: Formatting Output
|
Poster: KyleFox |
If anyone is having trouble getting output to line up, java does
support printf just like c++. Just use
system.out.printf([i:818e0793e7]format_string[/i:818e0793e7], ...). It
takes a format string as the first parameter, and applies it to any
subsequent parameters. Heres a link to a general page about c++'s
printf:
http://www.cplusplus.com/reference/clibrary/cstdio/printf.html |
Subject:
|
Poster: mgove131 | here's another link:
http://java.sun.com/j2se/1.5.0/docs/api/java/util/Formatter.html#syntax |
Converting: Char to Int
|
Subject:
|
Poster: dspiegel | ...or, just cast it and subtract 48... |
Subject: Converting: Char to Int
|
Poster: eleva340 |
In class we briefly discussed how to get the integer value of a char.
To get 1 from '1', we said simply cast it (i.e. int someInt =
(int)aChar;). Instead of returning 1, it returns the ascii integer
value for '1', which is 49.
So if you need to convert the actual String value of a char into an
integer, then the way to do it would be to convert that char to a
String first, and then parse it using Integer.parseInt(int anInt). |
Subject: another conversion of char to int
|
Poster: ehobe032 |
IF you read in the coordinates like: A4, and convert the string A4 into
a character array, the 4 is saved as a character. so if you want the
numeric value of that 4, you can do this as well:
Character.getNumericValue(array[1])
where array[0] is the A and array[1] is the 4
heres a sample of my code so you can see how to convert a string into a
character array and how i messed around with it:
System.out.println("Enter Starting Letter/Number Coordinates (A-J) and
(1-10)"); System.out.print("Example Coordinate: A4 or a4: ");
coordinate = Input.readLine(); char array[] = coordinate.toCharArray();
letter = (char)array[0]; letter = Character.toUpperCase(letter);
//function that converts letters a-j into #1-10 Y =
letterToNumber(letter); //check to see if user enter 10 for number
if(array.length == 3) { if (Character.getNumericValue(array[1]) > 1)
return -1; else X = 10 + Character.getNumericValue(array[2]); } else X
= Character.getNumericValue(array[1]); |
Subject:
|
Poster: gsmit466 | Nice post Eric. |
Ship overwriting problem
|
Subject: Ship overwriting problem
|
Poster: mherr170 |
While writing the section of code that lets the computer place its own
ships, I have run into a problem of the computer overwriting some of
its previously laid ships. I have been unable to come up with a
solution that works everytime no matter what. Has anyone else had
significant problems with this? Any literature or methods you used to
help solved this problem? |
Subject: CPU Ship Placement
|
Poster: mshar306 |
I have not yet written the code for this, but I will do what I did for
the player placement of the ships. For this I just have it check where
the other ships are and if they don't overlap, let the player place it
there. For the CPU I could just do a random spot choosing and just keep
checking the other ships locations until it finds a random spot that
works. |
Subject:
|
Poster: KyleFox |
Is there a reason why you couldn't error check when the computer player
places the ships? What I mean is, when the computer chooses a placement
for a ship, run through those spaces on the grid to make sure none of
them already have a ship placed in them. If they do, then have the
computer player try a different placement.
Of course, that sounds easy, but it can be a little difficult in code.
Good luck. :) |
Subject:
|
Poster: mkling |
[quote:f89d5b74b7="KFox112"]Is there a reason why you couldn't error
check when the computer player places the ships? What I mean is, when
the computer chooses a placement for a ship, run through those spaces
on the grid to make sure none of them already have a ship placed in
them. If they do, then have the computer player try a different
placement.
Of course, that sounds easy, but it can be a little difficult in code.
Good luck. :)[/quote:f89d5b74b7]
Yea, that's what I do. As Dr Spiegel pointed out I seem to have a lot
of repetitive code because 5 different ships, then each ship has a
different set of instructions based on the direction it's facing, so I
need to scale it back a bit. But yea, before the ship is actually
placed I basically test each space it will be sitting on to make sure
it's clear. |
Abstract methods
|
Subject: Abstract methods
|
Poster: mgove131 |
For my player classes, I ran into a problem
public abstract class Player {
//Place a ship
private abstract boolean _placeShip(int shipIndex, Location loc);
//The player takes a turn
private abstract SpaceStatus _takeTurn(Location loc);
}
illegal combination of modifiers: abstract and private
Apparently, you cannot have a private abstract class. I wanted those
functions to be private because the automatic player does not get
passed a location, it generates one. I want to have a public function
call the private one.
If I make the abstract functions public, you I cannot make them private
later.
public class AutomaticPlayer extends Player
{ //Place a ship private boolean _placeShip(int shipIndex, Location
loc) { } public boolean placeShip(int shipIndex) { return
_placeShip(shipIndex, generateGuess()); } //The player takes a turn
private SpaceStatus _takeTurn(Location loc) { } public SpaceStatus
takeTurn() { return _takeTurn(generateGuess()); } }
_takeTurn(Location) in AutomaticPlayer cannot override
_takeTurn(Location) in Player; attempting to assign weaker access
privileges; was package |
Subject:
|
Poster: mgove131 |
well, i implemented the classes slightly different. It works now, but
does anyone know why you can't have abstract private methods? |
Subject:
|
Poster: KyleFox |
[quote:a5f7a0ed0b="mgove131"]well, i implemented the classes slightly
different. It works now, but does anyone know why you can't have
abstract private methods?[/quote:a5f7a0ed0b]
Correct me if I'm wrong, but isn't an abstract method one that has no
implementation within the abstract class? And private means nobody else
can touch it, including any classes derived from that original class.
So in essence, creating a private abstract method would create a method
that you can never implement.
Wow that's confusing. :? |
Subject:
|
Poster: dspiegel | Hint: protected... :D |
Subject:
|
Poster: mgove131 | *smacks forehead* :oops: |
Input package ?
|
Subject: Input package ?
|
Poster: SPS |
Have a Q about Input package which should be used in the project ?
Does it mean java.io because i used Scanner from util package, is it ok
to use Scanner or do I have to recode those methods using java.io
package....... :( |
Subject:
|
Poster: gsmit466 | I think we gotta use InputReader |
Subject:
|
Poster: dspiegel | You must use it once. This can be as little as using readChar to input whether the player wishes to play again. |
Subject:
|
Poster: SPS | Gr8 Thanks |
Warning / Notes after run
|
Subject: Warning / Notes after run
|
Poster: SPS | Anybody any inputs why I get this warning or note messages after i run the prog. How to go to the source of the problem ?
I use NetBeans and i have used throws Exception for all methods.
Note: U:\Fall2007\Battleship\Battleship\Battleship\src\battleship\Grid.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details. |
Subject:
|
Poster: KyleFox |
My guess is that you used a vector without specifically telling java
what type of object you were putting in the vector. Look at this page:
http://forum.java.sun.com/thread.jspa?threadID=584311 |
Subject:
|
Poster: MarkSchlosser |
Also, if you follow javac's suggestion, and specify -Xlint:unchecked as
an option, you'll get full details of what you're doing not completely
safe.
I put -Xlint:unchecked in a JFLAGS macro in my Makefile, so I can
always get full details. |
Subject:
|
Poster: SPS | I did not use a vector. And will try with -XLint.
Thanks |
Subject:
|
Poster: slove843 |
I just got that warning the other day; whenever you declare a container
class, Java wants you to explicitly state the Type of object going in
to the default constructor when you allocate memory. So, I had to
switch [code:1:b3955813a1]Vector<Point> vector = new
Vector(10);[/code:1:b3955813a1]
to:
[code:1:b3955813a1]Vector<Point> vector = new
Vector<Point>(10);[/code:1:b3955813a1]
... although, as an aside, I've gotten that message hundreds of times
using fairly large nested data types, and I've never had it try to
allocate past its 32MB limit or anything equally nasty. YMMV, of course. |
Subject:
|
Poster: mgove131 | -Xlint:unchecked
if you compile with that option, it should tell you the error |
Randomization for automated player
|
Subject: Randomization for automated player
|
Poster: kkemm923 | I am having difficulty coming up with the random placement of the ships. Can anyone give some advice? |
Subject:
|
Poster: mkling | Random class....
Random generator = new Random();
Then begin generating random integers willy nilly
ex:
TheRowCoordinate = generator.nextInt(10);
Is that what you wanted? |
Bash classpath
|
Subject: Bash classpath
|
Poster: mgove131 | I'm having some trouble with my classpath in bash.
CLASSPATH=.:~/cis421/java:/usr/jdk1.5.0_03/bin:/usr/jdk1.5.0_03/lib/:$CLASSPATH
that's how I had it set up originally, and where's what happens
[code:1:2bce1ed3ee]
bash-2.05$ javac Battleship.java
Battleship.java:11: package Input does not exist
import Input.InputReader;
^
Battleship.java:490: cannot find symbol
symbol : variable InputReader
location: class Battleship
tempChar = InputReader.getChoice("yYnN");
[/code:1:2bce1ed3ee]
but the following does work:
javac -classpath .:/export/home/student/GOVE8891/cis421/java Battleship.java
so i tried
CLASSPATH=.:/export/home/student/GOVE8891/cis421/java
but that still doesn't work. anyone have any suggestions? |
Subject:
|
Poster: slove843 |
Just a knee-jerk reaction - try echoing your classpath and make sure it
changed. you might have to export your classpath or set it... I can't
remember which. did you source you .bashrc? Also, is cis421/java a
symlink? I think you need a trailing slash on symlinks. |
Subject:
|
Poster: mgove131 | echo $CLASSPATH
.:/export/home/student/GOVE8891/cis421/java
echo $CLASSPATH
.:/export/home/student/GOVE8891/cis421/java/
both with and without the slash still didn't work
it still works if i use the -classpath option with the same path that it echoed |
Subject:
|
Poster: mhiba775 |
To me it looks like your not placing the correct classpath value into
the .bashrc file..
try
~/java
thats where we were supposed to place the Input folder and all the
InputReader classes. place the files and classpath there, see if it
works for ya. |
Subject:
|
Poster: mgove131 | CLASSPATH=.:$HOME/java
Battleship.java:11: package Input does not exist
import Input.InputReader;
still doesn't work
but this does:
bash-2.05$ javac -classpath .:$HOME/java Battleship.java
.. i have no idea what to do
bash-2.05$ cd java/Input/
/export/home/student/GOVE8891/java/Input
bash-2.05$ ls
InputReader.class InputReader.java |
Subject:
|
Poster: slove843 | Did you try exporting CLASSPATH?
IE:
[code:1:04fa8a1751]export CLASSPATH[/code:1:04fa8a1751] |
Subject:
|
Poster: mgove131 | that fixed it :D
CLASSPATH=.:$HOME/java
export CLASSPATH |
Character Arrays and Strings
|
Subject: Character Arrays and Strings
|
Poster: ted_gress |
Dr. Spiegel's readChar function returns a character. My problem is I'm
trying to get from a character returned by this function to a string. I
tried char myChar = readChar();
String myString = new String(myChar);
From what I looked at in the API it should work, String will take an
array of characters in the constructor. But I haven't been able to get
it to work.
Any ideas? |
Subject:
|
Poster: mhiba775 | try appending the empty string to it '' + myChar |
Another guessing issue for automatic...
|
Subject: Another guessing issue for automatic...
|
Poster: mhiba775 |
In class we talked alot about the ships near each other example I asked
about, but another issue you need to worry about is what I'll call a
cross pattern. After hitting, and guessing the 4 possible locations of
a ship around the hit, make sure you have a way to handle hits after
that.. you don't wanna get stuck in an infinite loop trying to guess
the same 4 spots that have already been guessed. Just wanted to throw
that out there, so that if your farther along in the AI for the game
you don't run into this. |
JAR file (no command window)
|
Subject: JAR file (no command window)
|
Poster: Vinnie |
We discussed in Tuesday night's class on how to run a java program
without the command prompt window. The window is ugly and we don't
necessarily want the user to see our debugging-System.out code or
exception errors. This is of course when we get to the GUI stuff, not
for Battleship 1.0. So it got me searching and I found a nice tutorial
on the web. In order to run it without using the command prompt, you
have to compress your classes into a jar file and make a text file
telling it which class to run as the main class. Then you have to make
sure your file associations are set up to use javaw.exe. It's explained
in detail on this site but that's the gist of it.
http://neptune.netcomp.monash.edu.au/JavaHelp/howto/jar.htm#RunningAnExecutableJARFromExplorer |
Subject:
|
Poster: mkling | or use Netbeans which makes a .jar for you.... |
So..
|
Subject: So..
|
Poster: mhiba775 | Come on guys be honest... :D |
Subject:
|
Poster: dspiegel | :D :) :o :shock: 8) :lol: :lol: :lol: :lol: :lol: :D :D :P :wink: :wink: 8) |
Subject:
|
Poster: mhiba775 | .. Who showed the smilies off? I'd say that was a bit excessive on the use but :lol: just the same :) |
Subject:
|
Poster: mkling | It's not due for another week, right? |
Java 1.5 on acad
|
Subject: Java 1.5 on acad
|
Poster: mkling | Well, after exporting my finished project to acad, it seems I'm still on 1.4 there and it does not like the .printf commands...
I added this to my .cshrc
setenv CLASSPATH ".:$HOME/java:/usr/jdk1.5.0_03/bin:/usr/jdk1.5.0_03/lib/:$CLASS
PATH"
still using 1.4 though. Anyone remind me what how to change it? |
Subject:
|
Poster: slove843 |
Try using export instead of setenv.
[code:1:5bde9273af]export CLASSPATH=$CLASSPATH:/usr/yadda/yadda/yadda
[/code:1:5bde9273af]
I use bash and that's what I have to do, but bash is built on csh, so
it should work, I think. Erm... maybe bash is built on ksh... give it a
shot anyways :) |
java debugger?
|
Subject: java debugger?
|
Poster: mhiba775 |
Ok, not sure if we have one that will run with java... but Added a
little new functionality to my program and basically it killed
everything. I'm getting some infinite looping every 3-4 runs and i
can't find the source of the infinite loop... Any1 have any idea's how
to track it down? |
Subject: stab in the dark...
|
Poster: slove843 |
Are you trying to shoot spots that have already been shot after sinking
a ship, finding that they've already been hit, and then doing it again
without ever checking if the ship was sunk? |
Subject:
|
Poster: mhiba775 |
no, i added some "extra" help with the placing to make it need to retry
to place it less.. didnt back up and spent the last 7 hours tryign to
figure out what i broke... :/
cant place a ship anyway but horrizontal and my patrol boat doesnt want
to place anymore... why oh why did i try to make the code better? |
Subject:
|
Poster: slove843 |
OK, what's the pattern in the selected pairs, and what do they have in
common before every crash? What do you do when invalid input is sent
in?
Personally, I usually use a whiteboard and my favorite caffeinated
beverage and then draw a picture of what is happening as it happens
(adding in system.out.println's at every key point). A picture usually
tells me what's going on faster than looking at the best documented
code in the world. There's always a pattern, if you look from the right
angle. |
Subject:
|
Poster: mhiba775 |
I got println's everywhere. there is no pattern ive been able to
discern, the patrol says its placed on the board, i just can't get it
to tell me where, b/c it gives me null pointer exception when i
reference its Space[] then the other ships.. no idea why they are
staying horrizontal.. lol i mean i commented out all the code, except
the random and the line to set the direction and it still wont go to
vertical.
wipey board asside, i can't believe i didnt back it up before i changed
it.. |
Subject:
|
Poster: slove843 | hrm... did you allocate spaces for the array with "new"? If you make the array much larger (say 100x100), can you see it then? |
Subject:
|
Poster: mhiba775 |
[quote:df2fa3163f="slove843"]hrm... did you allocate spaces for the
array with "new"? If you make the array much larger (say 100x100), can
you see it then?[/quote:df2fa3163f]
made it to 15, and i was moding the randoms.. no chance it was any
farther then 5 away from the board, and it still wouldn't print em.
too late for any credit whatsoever on project 1.. but i'll prly just
scrap the code because ive spent way too much time fixing it.. and try
to rewrite it again... i spent a helluva lot less time writing it then
trying to fix it after i broke it :( lol |
Subject:
|
Poster: gsmit466 | I think we have the jdb right?
type in jdb in the unix console then type run classname.class
after you tybe in jdb .. type help to get the commands
I am guessing that would work? |
Subject:
|
Poster: dspiegel | The sysadmin and I just got done getting jdb working in the ddd graphical debugger. More in class this week. |
How bout dem Indians!!
|
Subject: How bout dem Indians!!
|
Poster: mhiba775 | Any team that puts a tromping on the yankees is good with me :D
too bad they will lose if they meet the Sox :P |
Space Event
|
Subject: Space Event
|
Poster: Vinnie |
All,
I had asked Dr. Spiegel how exactly we capture a Space object's
ActionEvent and have the Game object know what happened. Here is his
response:
[quote:52de281574]
This is a very legitimate concern. You want to listen to a Space object
that is-a Button. But, you want your Game object on which the layout is
(I'm assuming) as follows:
Space on Grid
Grid on Player
Player on Game
In short, you want the Game object to listen for a press on a Space.
Here's how:
In the Space object, add a public method:
Space getThisSpace()
{ return(this);
}
In the Grid, is there a way to get a reference to a specific space?
I'm sure there is. Either way, let's suppose it is (in the Grid):
Space getSpace(int row, int col)
{return(SpaceGrid[row][col]);}
and in the Player class, you should have:
Player getPlayer()
{return(this);}
You may need a getGrid for the Grid class, too.
Once you have all Space objects on the Grid, etc; you want to add the
listeners. You know how you do
<Component>.addActionListener(this); ??
Well, the _this_ is always the guy who listens. So, that's who should
add the ActionListener. If you want the Game object to listen, you need
to do something like:
TheHuman.getGrid().getSpace(i,j).getThisSpace().addActionListener(this)
in the Game class, where TheHuman is the human player, and this is the
Game object, which implements ActionListener, and thus has a version of
actionperformed().
Make sense?
[/quote:52de281574]
I'll let you guys know when I try this and if I have any trouble. You
do the same.
Vin |
Subject:
|
Poster: Vinnie | Ok it turns out you can just use the getSpace without adding a getThisSpace method. So it should work like this:
TheHuman.getGrid().getSpace(i,j).addActionListener(this)
from inside the Game class. |
Why doesn't a GridLayout inside a FlowLayout respect size?
|
Subject: Why doesn't a GridLayout inside a FlowLayout respect size?
|
Poster: KyleFox |
I know that every time I play with java's layout managers, I get angry.
Which is what is happening right now. Here's my question:
FlowLayout respects size, while GridLayout & BorderLayout do not,
correct? So theoretically, shouldn't you be able to override this by
adding GridLayout & BorderLayout managed panels to a FlowLayout
managed Panel?
Ex:
JPanel pnlFlow = new JPanel(new FlowLayout);
JPanel pnlGrid = new JPanel(new GridLayout(5,5));
pnlGrid.setPreferredSize(200, 200);
pnlFlow.add(pnlGrid);
Shouldn't pnlFlow respect pnlGrid's preferred size of 200 x 200, and
instead of forcing pnlGrid to occupy the rest of the space, occupy that
space itself?
I ask because I have my project set up with a BorderLayout as the main
window. In BorderLayout.EAST and in BorderLayout.WEST, I have my grid
for my humanplayer and my computerplayer. What I don't like is that
when the window is resized, all of my buttons in my grid are resized
also. I don't want that to happen, so I added a FlowLayout panel to
BorderLayout.EAST & BorderLayout.WEST first. Then I added my
GridLayout panel containing the buttons to those FlowLayout panels. For
some reason that is beyond me, the buttons still resize when the window
is resized.
Or should I just give up on using layout managers and move to the null
layout? I just hate the fact that I can never get layout managers to
work correctly. I don't understand why all layout managers can't
respect the size of their components instead of stretching them
ridiculously. |
Subject:
|
Poster: Anonymous |
Kyle, I would try to use the validate() method. It is a method of the
container class, and what it will do is cause the container to layout
it's components over again. Also, I noticed you are using
setPreferredSize(). I believe there are methods to set the maximum size
of a component, as well as the minimum size. You may want to try using
those instead of preferred size. As I understand, preferred size does
not force a size, but simply states what the default size is. |
Subject:
|
Poster: Vinnie |
I think I agree with your other half, Kyle, to go with the null layout.
It's good because you can place things at exact pixel spots and force
panels and stuff to be exact sizes. Kind of like how we do most forms
in VB. There are things that I just don't fight Java on, and you're
right, layouts are one of them. I still don't get why I can't have a
gridlayout and be able to access just one position via row, column.
That never made sense to me. Instead you have to redraw the whole thing
to change one grid space. I'm sure someone has an explanation for me,
but that still doesn't explain why someone hasn't figured out how to
create a simple, accessible grid layout. |
Subject:
|
Poster: KyleFox |
Well, I spent a few hours, deleted my GUI code, and re-wrote it. I knew
damn well it should work the way I explained. I did absolutely nothing
differently as far as I can tell, and what do you know, it works. :? So
I'm just going to continue working as if it never happened. Should
something else go wrong, I'll try the validate method. And if that
doesn't work, I will subdue to a null layout. :wink:
[quote:9931a13e1b="sfisc146"]
Also, I noticed you are using setPreferredSize(). I believe there are
methods to set the maximum size of a component, as well as the minimum
size. You may want to try using those instead of preferred size. As I
understand, preferred size does not force a size, but simply states
what the default size is.[/quote:9931a13e1b]
I think they are really only "preferred sizes" as well. I tried every
single sizing method I could find. Gridlayout and Borderlayout remained
blissfully ignorant of the fact that I had changed the sizing of the
components. Layout managers seem to have a mind of their own when it
comes to sizing. If it doesn't want to size it the way you want to size
it, it's not happening. Which is what makes java GUIs so frustrating. |
Loading your applet onto the web server
|
Subject: Loading your applet onto the web server
|
Poster: ted_gress |
Everyone who has an old account on the webserver make sure you use the
right case in your username or it won't be able to find your page. My
old username is GRES4177 and my new username is wgres101. I tried
acad.kutztown.edu/~gres4177 and it didn't work.
Also Dr. Spiegel said to make sure you set your permissions and only
load .class and .html files. |
Labels and multiple panels
|
Subject: Labels and multiple panels
|
Poster: mshar306 |
I was just wondering if anyone could explain why labels can only be
used in one panel? I was trying to add labels for the ships, and found
that it would not work when trying to add the same label to two
different panels. I ended up changing how I did this to save the amount
of code needed, but thought that this was a weird restriction. |
Updating a panel
|
Subject: Updating a panel
|
Poster: ted_gress |
I have a panel to hold the text prompts for when placing the ships.
However, without going into much detail about my code, after I place
this panel into my applet I want to add text labels every so often to
my panel. Unfortunately they are not showing up. Do I have to re-add
the panel to the applet every time I add a text label? |
Subject:
|
Poster: dspiegel |
Add the labels with a blank string, like in the examples. Then, just
use setText to show messages. Reset to a blank string when messages
should go away. |
Subject:
|
Poster: mgove131 |
you can also try panel.repaint(), because sometimes an object won't
repaint for some methods
you can use dr. spiegel's method of changing the text, or you can add
the label, but setVisible(false). Then setVisible(true) when you need
it, but you have to repaint the panel for the label to then show up.
Also, i found that remove(component) needs to be repainted. |
Object Oriented -> Event Driven
|
Subject: Object Oriented -> Event Driven
|
Poster: eleva340 |
Now that my GUI is set up my brain decided to stop working. I'm trying
to think of how to start my program now that I'm done building the GUI.
How does one take an object-oriented program and suddenly turn it over
to the mercy of the user's clicks and keyboard presses?
What are some good ways to "wait" for a user to click something or
cause an event, I think is what I'm asking? Maybe I'm thinking to
abstractly?
We talked about Thread.sleep() and so far that seems to be working very
well. I suppose it's just good for saving CPU time...?
I also discovered that the repaint() method solves any issues one might
have with objects disappearing after displaying a message box or
minimizing the window.
I don't know where this thread is going, but I have a feeling it will
end somewhere beautiful...
***UPDATE***
I wasn't aware that once the code reaches the end of the init()
function that doesn't mean the program ends, too. Silly me... |
Adding KeyListener to a JPanel
|
Subject: Adding KeyListener to a JPanel
|
Poster: nstor641 |
Given:
Game is a JPanel, what I want it to do - listen to
keyPressed/keyReleased events. What's wrong - well, it doesn't. I added
this code: addKeyListener(new KeyAdapter(){ public void
keyPressed(KeyEvent e) { keyChar = e.getKeyChar();
System.out.println("Key pressed: " + keyChar); } )};
to the constructor and nothing comes up. Why? That's why:
"Specifically, key events are fired by the component with the keyboard
focus when the user presses or releases keyboard keys."
Solution:
add setFocusable(true); to the constructor of a JPanel that you want to
listen to KeyEvents. That gets the job done. Where did I get it from?
Here it is:
http://java.sun.com/docs/books/tutorial/uiswing/events/keylistener.html |
Weird stuff happening with setEnabled()
|
Subject: Weird stuff happening with setEnabled()
|
Poster: ted_gress |
Just some background first. I have three panels so far, one for each
grid and one for status information. I have my ships extending the
Jbutton class. In my status panel I have a button for each ship to
place the ship. Weird things start happening when I try and disable the
ship button though. I added some code to disable the button after it is
clicked. However, now when I load my applet my my status panel is
missing and the main grid has taken over everything else. I wasn't sure
if this is newsgroup worthy or not, but it is definitely unusual. I
took out the code to disable the button and my layout returned to
sanity. |
Subject:
|
Poster: ted_gress |
Well update to this. I've commented out the setEnabled but now it seems
like every other or so time I open my applet it gives me that incorrect
layout. So I am actually wondering if it could be a browser issue... |
Subject:
|
Poster: mgove131 |
a few questions. are you using a JApplet? do you set the background
color in the JApplet? If you do, do you say
getContentPane().setBackground() or just setBackground() ? |
Subject:
|
Poster: ted_gress | I am extending a JPanel and when I set the background color I'm using setBackground(). |
Subject:
|
Poster: mgove131 | try getContentPane().setBackground() and let me know if that fixes it. |
Subject:
|
Poster: mgove131 | did getContentPane().setBackground() solve your problem? |
Images In Applets
|
Subject: Images In Applets
|
Poster: KyleFox |
Contrary to what one may think, using images within an applet can prove
to be a very difficult task. As we all know, applets are very
restricted in what they are allowed and not allowed to do. To my
knowledge, they cannot access anything on the server without being
signed. Meaning, they cannot access images unless they are signed.
Unless of course images are within the same jar file. So one would
think that as long as images are jarred with the class files,
everything should be ok, right? Wrong. For some reason I'm not going to
try to understand, images in jar files can not be located unless their
entire URL is used.
So, since I know how terrible it can be trying to get images to work
with applets, I figured it may be helpful to post about my way of doing
it. I'm sure there are other ways, which I would love to hear about
also. It would be nice if there was a simple way of doing it, but I'm
not so sure that there is. Anyway, here's how I manage to get images to
work:
1) Anytime you need to access an image to create an ImageIcon, use the
getResource method provided by Class to obtain the full URL of the
image. This allows for portability, because the URL will be obtained
based on where the images are actually located. An example would be:
new ImageIcon(this.getClass().getResource("Images/Something.jpg"))
Assuming that Something.jpg is the picture you want, and it is within
the folder Images.
2) Create a manifest file. When working with jar files, java needs to
know where to look to find an entry point. In other words, java needs
to know which class' main method to use. Creation of a manifest file to
specify an entry point is actually very simple. It's one line, followed
by a hard return:
Main-Class: classname
Note: Don't forget to put a hard return at the end of that line,
otherwise it will not work correctly. For more information:
http://java.sun.com/docs/books/tutorial/deployment/jar/modman.html
3) Jar all of your .class files and images using the jar command. Here
is the command to do that:
jar -cvfm jar_to_create.jar manifest_file.txt *.class images
Where -c means create a jar, -f means make a jar file, -v means show
what is going on, and -m means specify a manifest file. You do this
using the name of your manifest file that you created, and the name of
the directory you have your images in. For example, mine would look
like this:
jar -cvfm Battleship.jar Manifest.txt *.class Images
For more information:
http://java.sun.com/docs/books/tutorial/deployment/jar/build.html
4) Include your jar file in your applet tag as archive. Example:
<applet code = "Battleship.class" archive="Battleship.jar"
width="800" height="600"
align = middle>
</applet>
Thats it. Good luck! And if there is a better way, please let me know.
:wink: |
Subject: Displaying Images
|
Poster: nstor641 |
I found this example:
http://www.realapplets.com/tutorial/ImageExample.html
and they don't "jar" images with .class files but rather download them
from server. But there is a restriction for MediaTracker class that
they use - it works only with Gif and JPG (sound is not yet
implemented). Here is link to MediaTracker:
http://java.sun.com/j2se/1.4.2/docs/api/java/awt/MediaTracker.html
P.S. I did not try it yet and can not guarantee that it will work. |
Subject:
|
Poster: Vinnie | I'm pretty sure you don't need the MediaTracker. I tried it with AND without and it seems to work.
I have a similar method. Anyone is welcomed to try:
First you get the URL just like Kyle said. Below it says Game but it could whichever class is your applet:
URL iconURL = Game.class.getResource ("picture.jpg");
Then create an image out of it:
Image img = Toolkit.getDefaultToolkit().createImage (iconURL);
Then turn it into an icon:
Icon icon = new ImageIcon (img, "");
now you can use the setIcon(icon) to get it to display in your button/label/whatever. I think you need to import java.net.*;
Toodles |
Subject: Vinnie.equals("The Man")
|
Poster: eleva340 |
I <3 you Vinnie! It works like a charm when I run it in the
appletviewer and online.
But now, how do you identify when that button is pushed, since there is
no label? I know you can set the label, but then is there a way to make
only the image show up in the button and not the text? How do you do
it?
***UPDATE***
Apparently the AbstractButton class comes fully stocked with a function
called setActionCommand. It more than does the job. |
Subject:
|
Poster: mherr170 |
I tried vinnie's method and it works in an applet viewer. However when
I try to load it into an applet, it throws a
java.lang.NullPointerException on the lines where i have:
Image img = Toolkit.getDefaultToolkit().createImage (iconURL); This
seems to be causing the applet to never load. Is there an instantiation
step I could be missing? |
Subject:
|
Poster: Vinnie |
Are you sure when your creating the image your iconURL is correct? If
you just create the iconURL with a file name such as "pic.jpg", then
your pic.jpg should be in the same directory as the applet. If it's
somewhere else, do "imageDirector/whatever/pic.jpg".
If all that's fine and dandy, you may want to use the media tracker
stuff. I was fine not using it for small tasks, but as soon as you have
more than a few lines of code to go with your image loading, everything
bombs out. Try the media tracker. It's only about 4 lines of code. |
removeAll() and panels
|
Subject: removeAll() and panels
|
Poster: ted_gress |
FYI after doing a removeAll() to remove components from a panel, you
have to re-add the null layout manager. At least that's been my
experience. |
The best reference for Java I've found thus far!
|
Subject: The best reference for Java I've found thus far!
|
Poster: slove843 |
Just had to drop a link to this. This site has Java API documentation,
and a nice feature to add parts of the API to a favorites list. Also
has plugins for netbeans, eclipse and intelliJ to look up information
from the site.
[color=blue:c685af5648][url]http://www.jdocs.com[/url][/color:c685af5648] |
Accessing Buttons in a Grid Layout
|
Subject: Accessing Buttons in a Grid Layout
|
Poster: pascenzo |
Does anyone know a way to access items in the grid layout. I want to
disable the button so that it cannot be clicked, but I used a for loop
to add the buttons so they don't have an actual name. |
Subject:
|
Poster: mgove131 | use an array of JButtons as a private member
private JButton theButtons[][];
then initialize all of them in a loop, and add them to the board. you can then access them by index.
theButtons = new JButton[10][10];
//in the loop
theButtons[r][c] = new JButton();
add(theButtons[r][c]); |
Subject: Buttons
|
Poster: mshar306 | I used a for loop as well, but to remove a button after it was clicked I did:
In the actionPerformed method, I got the source
JButton btn = (JButton) ae.getSource();
Now that you know what button(btn) you can just remove the actionListener. |
Subject:
|
Poster: gsmit466 | or do theButtons[r][c].setEnabled(false); |
Smart Scroll Panes
|
Subject: Smart Scroll Panes
|
Poster: eleva340 |
I'm trying to get my scroll pane to know to keep scrolling down as you
append text to it, just like a text area in AIM. I'm not entirely sure
that this is even possible in Java.
That being said, there's a function called scrollToVisibleRect(), where
you pass in the viewable rectangle. I suppose this would work but you'd
have to call it after every append and with an updated rectangle based
on the number of lines or whatever in the text area. I'm not sure how
to do this. Thoughts, anyone? |
Subject:
|
Poster: mgove131 | http://java.sun.com/docs/books/tutorial/uiswing/events/documentlistener.html
that looks like it might help |
Subject: Found It!
|
Poster: eleva340 |
That did. I had to weed through the file to find what I was looking
for. But it's this line:
displayArea.setCaretPosition(displayArea.getDocument().getLength());
Now I just have to decide if I want to tack this on after every append
I do or if I want to implement the DocumentListener. I'll probably do
the latter just so Spiegel will use his Grading Pen of Impressiveness
that hits for +5 extra credit points. |
Starting a new game
|
Subject: Starting a new game
|
Poster: nstor641 |
I added a button to start a new game and it has this code in its
actionPerformed: gamePanel.removeAll();
// to remove all old panels from the gamePanel gamePanel.repaint();
Player1 = new Player(listener, mouseListener); Player2 = new
ComputerPlayer(listener);
// create new Players Middle = new MiddlePanel(listener, keyListener);
CreateAnnLabel(); SetGamePanel();
// add new Panels to the gamePanel add(gamePanel);
// add gamePanel to the frame + some more staff to update variables
now when I click on New Game button frame goes blank but ... gets
repainted correctly after being iconified/deiconified. That doesn't
work for an applet though, it just goes blank. So I guess I'm doing
something wrong, the Q is what is the right way to start a new game? |
Subject:
|
Poster: KyleFox |
I added a reset() method to each class I created. Then when I want to
start a new game, I call humanPlayer.reset() and
computerPlayer.reset(). Those reset methods then in turn call the reset
methods for their grids, ships, etc. Theoretically, you should be able
to do it your way though. This is probably something you've already
done, but did you try using setVisible? I remember there being a time
when you need to use setVisible. ;) |
Subject:
|
Poster: mshar306 |
I also used reset methods in each class to reset all the variables and
vectors etc. Wouldn't you need to add all the components back on the
panel before you call repaint. Because this way repaints an empty
panel, and then you add everything after. Then when the window is
iconified or deiconified it repaints, now having everything added.
Sounds like it should work this way at least. |
Subject:
|
Poster: mkling |
hmm. for the applet, I just removed the base panel, and called
repaint(), then init(), and it seemed to work for the most part... |
Disabling your grid after ship placement.
|
Subject: Disabling your grid after ship placement.
|
Poster: parkmw |
I want to disable my buttons after i place all the ships on my grid but
when I do the text then becomes gray and hard to see. Does anyone know
of a way, besides short of creating my own JButton class and using them
for my grid, to set the text to be something other than gray when I
disable the buttons? |
Subject: Re: Disabling your grid after ship placement.
|
Poster: KyleFox |
[quote:037cf1f9fe="parkmw"]I want to disable my buttons after i place
all the ships on my grid but when I do the text then becomes gray and
hard to see. Does anyone know of a way, besides short of creating my
own JButton class and using them for my grid, to set the text to be
something other than gray when I disable the
buttons?[/quote:037cf1f9fe]
Do you extend JButton in your space class?
You could write your own method to enable/disable buttons. All that
would be necessary is a variable knowing if the JButton is enabled or
disabled. Then when you add an ActionListener and implement the
actionPerformed method, you just need to verify that the button is
enabled before doing anything.
Good Luck. ;) |
Subject:
|
Poster: parkmw | As I said in my post, I am trying to avoid having to do that. :P I was hoping there was a better way. |
Subject:
|
Poster: eleva340 | Psssst... just remove the listener... |
Subject:
|
Poster: mgove131 |
Some things we discussed in class:
http://java.sun.com/j2se/1.5.0/docs/api/javax/swing/JComponent.html
(see the paint method)
You can make a class that extends JButton, and then override the paint
method. When you override the paint method, if you want to retain the
functionality of the parent class, make sure the first line of the
method is super.paint(g);
Also, if the text on a JButton appears as '...', then then the text is
too big. One solution is to change the border. You can create an empty
border by saying <object
name>.setBorder(BorderFactory.createEmptyBorder());
http://java.sun.com/j2se/1.5.0/docs/api/javax/swing/BorderFactory.html
The problem I was having with JPanel is that I had
setBackground(<color>); but it didn't set the background color.
getContentPane().setBackground(<color>); fixed it. |
Subject: How to Keep Text Black after Button was Disabled
|
Poster: nstor641 |
For more details check this link:
http://java.sun.com/j2se/1.5.0/docs/api/
But long story short - you can use HTML tags to place text on
JComponents and due to bug #4783068 this text doesn't grey out after a
button was disabled. If this is what you want that is.
b1 = new
JButton("<html><center><b><u>D</u>isable</b><br>"
+ "<font color=#ffffdd>middle button</font>",
leftButtonIcon);
Here is link to the bug (still pending - "in progress):
http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4783068 |
RemoveAll() and Remove(Component)
|
Subject: RemoveAll() and Remove(Component)
|
Poster: eleva340 |
I have yet to get either of the above functions to work regardless of
whether I'm calling them from the japplet or from one of my jpanels.
Even if I put validate() after, they just won't work. And google is no
help. I know I'm not the only one having this issue.
I could solve the whole problem by adding the jcomponents I need and
making them visible/invisible, depending on the situation, but I'm
pretty sure these functions should at least work.
Each player has a panel for sunk ships and when a ship is sunk, I add a
jlabel with that ship name to the panel. It works when I extend
JApplet, but not Applet. I cannot remove them when I extend either.
Does anyone know any insider secrets? Maybe Vinnie, you Java master,
you...? |
Subject:
|
Poster: mhiba775 | it could be an issue with Japplet, did you try using just applet?
Japplet has alot of funny characteristics that don't work the way you expect them too. |
Subject:
|
Poster: eleva340 | Yeah, I think I mentioned that above. Neither work. |
Subject:
|
Poster: mgove131 |
alright, after hours of work, and some help from mark, I finally got my
thank you screen to display. pnlGame.removeAll();
pnlGame.add(pnlThanks); pnlGame.revalidate(); repaint();
pnlGame is the JPanel my game is on, and pnlTanks just has a label that
says "Thanks for playing". revalidate only works on panels, so I just
remove all the components from pnlGame and add pnlThanks. revalidate
wasn't working on its own, so I had to use repaint on the applet. |
Subject:
|
Poster: MarkSchlosser |
[quote:fbae2a0445="mgove131"]alright, after hours of work, and some
help from mark, I finally got my thank you screen to display.
pnlGame.removeAll(); pnlGame.add(pnlThanks); pnlGame.revalidate();
repaint();
pnlGame is the JPanel my game is on, and pnlTanks just has a label that
says "Thanks for playing". revalidate only works on panels, so I just
remove all the components from pnlGame and add pnlThanks. revalidate
wasn't working on its own, so I had to use repaint on the
applet.[/quote:fbae2a0445]
Mike, I looked further into this for my own applet and figured out how
to do it without putting things on JPanels.
When you remove all from the applet you need to do it on the content
pane, so you need to call:
getContentPane ().removeAll (); |
Subject:
|
Poster: mgove131 |
i tried that! lol, it didn't work for me, but that's alright. yeah,
JApplets seem to be weird. sometimes you need to get the contentpane
for some things to work, which is a pain. i had to get the content pane
for my setBackground funtion to work. |
Subject:
|
Poster: MarkSchlosser | All I had to do was:
getContentPane ().removeAll ();
showGoodbye (); // added a label with text
repaint ();
Crazy! |
Truncated class file ??
|
Subject: Truncated class file ??
|
Poster: mherr170 |
After battling with applets and images for a while, I was hoping I had
smooth sailing ahead for loading the applet until I came across this in
the java console after the applet fails:
java.lang.ClassFormatError: Truncated class file
I've looked on google for information about this but the result was
minimal to none.
Has anyone gotten this problem? Were you able to fix it?
-Mike |
Subject:
|
Poster: mgove131 | I've never seen that. Do you get that error locally on your pc, or just on the web? |
Subject:
|
Poster: mherr170 | Web only, the applet viewer with eclipse runs it fine (as well as acad as a frame). |
Subject:
|
Poster: mgove131 |
are you sure you uploaded all the class files?maybe try deleting them
all from the web, and locally, recompiling and uploading again. make
sure to include any $1.class files too, they are all important. also,
you can try going into the java control panel and deleting all the
files in the cache. |
Show off your Battleship
|
Subject: Show off your Battleship
|
Poster: mgove131 | I was just interested in seeing how everyones game came out. So just post the link in here if you want to share it. I'll start.
http://acad.kutztown.edu/student/GOVE8891/battleship.htm |
Subject:
|
Poster: nstor641 | Looks nice!
Mine is here:
http://acad.kutztown.edu/~nstor641/BattleShip_v2/classes/GameApplet.html
After playing you game I know now how I will animate Quit button :wink: |
Subject:
|
Poster: KyleFox | My Battleship:
http://acad.kutztown.edu/~kfox112/Battleship/Battleship.html |
Subject:
|
Poster: MarkSchlosser | Mine:
http://acad.kutztown.edu/~mschl219/battleship/ |
Subject:
|
Poster: mkling | http://acad.kutztown.edu/~mklin279/Battleship.htm
AI still needs some work, but it's getting there... |
Subject:
|
Poster: ehobe032 |
http://acad.kutztown.edu/student/HOBE3175/game.htm
enjoy the background music, my sounds for the game are not put in
separate threads, so if you want to see how sounds work without being
in threads, check it out. |
Subject: Battleship - 24 Style
|
Poster: eleva340 | If you're not careful, Jack Bauer will pwn your face:
http://www.fearedatheist.com/progs/BattleshipGame.html |
Button stopped showing up...
|
Subject: Button stopped showing up...
|
Poster: mhiba775 |
this code displays my buttons for placing my carrier... it also serves
as the notification to let the player know what ships are sunk...
[code:1:07eb1c0eef]
JPanel player1CarrierPanel;
JPanel player1CarrierPanel;
player1Carrier = new JButton [5];
player1CarrierPanel = new JPanel(new GridLayout(1,5));
player1CarrierPanel.setBounds(15,490,155,40);
for (int b = 0 ; b < 5 ; b++ )
{
player1Carrier[b] = new JButton("C");
player1Carrier[b].setSize(30,30);
player1Carrier[b].setVisible(true);
player1CarrierPanel.add(player1Carrier[b]);
}
add(player1CarrierPanel);
player1CarrierPanel.setVisible(true);[/code:1:07eb1c0eef]
that functions perfect while the code for the panel below, shows
nothing now, though i can't find a single thing wrong in the code..
maybe some1 else can see something i cant.
[code:1:07eb1c0eef]
JButton player1BattleShip[];
JPanel player1BattleShipPanel;
player1BattleShip = new JButton[4];
player1BattleShipPanel = new JPanel(new GridLayout(1,4));
player1BattleShipPanel.setBounds(15,535,124,40);
for (int f = 0 ; f < 4 ; f++)
{
player1BattleShip[f] = new JButton("B");
player1BattleShip[f].setSize(30,30);
player1BattleShip[f].setVisible(true);
player1BattleShipPanel.add(player1BattleShip[f]);
}
add(player1BattleShipPanel);
player1BattleShipPanel.setVisible(true);
[/code:1:07eb1c0eef] |
Cropping an ImageIcon into sub-images
|
Subject: Cropping an ImageIcon into sub-images
|
Poster: MarkSchlosser |
This came up in class tonight, and I mentioned that I did this in my
game. My ships are .png files of size 64x32, 96x32, etc.
When I placed them on my board, I split the image into subicons of size
32x32 each. To do this I use a CropImageFilter and a ImageProducer. See
code below.
[code:1:eab5d26eff]
Image srcImage = srcIcon.getImage ();
ImageFilter filter = new CropImageFilter (0,0,32,32); // crop from
pixel 0,0 to 32 pixels down, 32 pixels across.
ImageProducer producer = new FilteredImageSource (srcImage.getSource
(), filter);
Image croppedImage= Toolkit.getDefaultToolkit ().createImage
(producer);
ImageIcon croppedIcon = new ImageIcon (croppedImage);
[/code:1:eab5d26eff]
croppedIcon will then be the first 32x32 block of the image. In my code
I put this sort of code in a loop that depends on the ship size to
determine how many subimages to create. |
Subject:
|
Poster: mkling | played with this in lab today, after a minor SNAFU, it works like a champ.
8) |
Subject:
|
Poster: KyleFox |
Thanks Mark, works great!
Took me a little bit, because for whatever reason, I thought I was
cropping in a square from point a to point b. But really you are
cropping from point a, down and over a certain amount. Once I figured
that out though, it works perfectly. I only wish I knew I could do this
before I went and spent hours cropping an image in photoshop into 100
tiny subimages for the spaces. :roll: What a waste of time that was.
:wink: |
JButton Extra Space
|
Subject: JButton Extra Space
|
Poster: mshar306 |
I was playing around with placing icons on my buttons, and noticed that
there will always be a gap between all of the buttons. This space is
due to the button border, even if one is not set. My current thoughts
is that this will get in the way of the ship icons. Making the
apperance of the ship broken up by the borders. Has anyone else using
buttons thought about this? |
Subject:
|
Poster: mgove131 |
I haven't started yet, so I haven't tried this yet, but I was going to
try an approach we discussed in class. I'm thinking about having a
JPanel behind the buttons, and having invisible buttons. This would
allow you to draw on the panel, and still use the buttons. If that
doesn't work, it's always porrible to make a class extend JButton, and
just override it's paint method.
A key to transparency for the components is going to be the alpha value
in the Color class.
http://java.sun.com/j2se/1.5.0/docs/api/java/awt/Color.html
http://java.sun.com/j2se/1.5.0/docs/api/java/awt/Color.html#Color(float,%20float,%20float,%20float)
note: copy and paste the second link |
Scoring: Storing and Retrieving a map
|
Subject: Scoring: Storing and Retrieving a map
|
Poster: dspiegel |
As promised, I have written programs to create, store and read a
multimap whose values are lists of pairs. You can find them under the
Collections\Multimap subdirectory in the 421 Java area on the web and
also on acad. We may have a look at them next week. The full example is
named ReadPrintmap.java. The other examples just play with maps a bit.
:idea: Meanwhile, I'm wondering whether we should defer the whole
scoring system business until the final project. Your thoughts? |
Subject:
|
Poster: mshar306 |
I think that would be fair, since we have not been taught any of that
yet. I know I already have enough work to do. Either way though. |
Subject:
|
Poster: dspiegel |
[quote:c9ba8d1bdc="mshar306"]I think that would be fair, since we have
not been taught any of that yet. I know I already have enough work to
do. Either way though.[/quote:c9ba8d1bdc]
One maybe... :wink: |
Subject: Scoring System
|
Poster: thege033 | Personally I'm not sure if the scoring system adds significant value to the project. |
Subject:
|
Poster: mkling | I am in favor deferring scoring to the final project |
Subject:
|
Poster: mgove131 |
I haven't gotten the chance to start the project yet, that's what I'm
doing this weekend, so I'm not sure how long everything will take. Just
looking at the sheet, it does seem like there is alot to get done, so
having one less thing might help alittle. |
War sounds
|
Subject: War sounds
|
Poster: ehobe032 | i found some war sounds for the game if anyone wants to use them for the game
http://www.partnersinrhyme.com/soundfx/warsounds.shtml |
Inner class design
|
Subject: Inner class design
|
Poster: mkling |
Say I am creating 5 panels, all of which need to override the
paintcomponent method like so.
[code:1:750739dcdc] for(int i=0;i<5;i++){ sunkShip[i] = new
JPanel(null){ protected void paintComponent(Graphics g){
super.paintComponent(g); g.drawImage(shipImage[i],0,0,this);
g.drawString(shipTypes[i],0,40); } }; }
[/code:1:750739dcdc]
Now, this obviously does not work, since the paintcomponent is actually
in a separate class and it can;t see the i variable. So it seems to me
I either need to officially extend the JPanel class to add in a
constructor, skip the loop and do the 5 separately, or cheat a bit and
declare a public counter that the inner class can see.
Any thoughts on a "preferred" way? I'm sure skipping the loop is bad...
Doing an external counter seems the easiest, considering there's
already a ton of external data members with all the components and
buttons and such, but I'm not sure if that's considered bad design or
no. Also seems overkill to create a whole new class simply to add an
int to the constructor... |
Subject:
|
Poster: mshar306 |
I would personally just add a public counter. It seems pointless to go
through all that work, when adding a simple line can accomplish the
task and save time. |
Subject:
|
Poster: mkling |
heh, actually, I forgot one small issue went I went to actually code
this...the paintComponent method for all the panels gets called every
time it needs to paint, which is quite frequently...meaning I don't
think I can use a counter variable inside my paintComponent method.
I guess I'll just do it 5 separate times for each ship, it's only like
16 extra lines of code vs the loop, I doubt it'll cause a huge
performance issue. |
.wav files in java
|
Subject: .wav files in java
|
Poster: ehobe032 | I could not get my .wav files to work unless they had these properties:
Bit Rate - 128 kbps
Audo sample Size - 8 bit
Channels - 1
Audio sample rate - 16 kHz
anyone else having this problem with .wav files not working, try converting them to these properties. I did and it works great. |
Subject:
|
Poster: mgove131 |
thanks for the heads up. also, something that was helped for images is
the mediatracker. Spiegel wasn't kidding when he said that they are
useful. I spent all weekend getting my images set up in my code, and
they didnt't work until I used a mediatracker. |
GIMP
|
Subject: GIMP
|
Poster: mgove131 | For those people who don't have photoshop and need a better image editor than ms paint, you can use gimp.
http://www.gimp.org/ |
Double Buffer
|
Subject: Double Buffer
|
Poster: mgove131 |
http://en.wikipedia.org/wiki/Double_buffer
This offers some clues to how double buffering works.
"Single bufferring is affected by buffer underrun and buffer overflow.
"
That's probably why the images flicker.
"A software implementation of double buffering uses a video page stored
in system RAM that all drawing operations are written to. When a
drawing operation is considered complete, the whole page, or a portion
of it, is copied into the video RAM (VRAM) in one operation. This is
generally synchronised so that copy operation is ahead of the monitor's
raster beam so that ideally (if the copy is faster than the video beam)
artifacts are avoided. This software method is not always flawless, and
has a higher overhead than the hardware method."
I believe this might be how the double buffering in Java works. Any
ideas? |
Subject:
|
Poster: mgove131 |
http://www.codeproject.com/java/javadoublebuffer.asp
I did some googling.
"What's causing the flicker? Well, if you call the repaint method, you
actually tell the VM to repaint this component as soon as possible. You
can't tell when (but you can set an initial delay). When the VM has
time to carry out the paint tasks, it calls the update method for you.
And there's the first problem already. The update method clears the
panel for you, so you can paint to it, without concerning about the
background. That's what's causing the flicker. It clears the panel,
shows in the window, paints the panel and shows again. So every
paintjob has in fact two jobs, clearing and painting." |
A Few Sound Quirks
|
Subject: A Few Sound Quirks
|
Poster: KyleFox |
I now have sound implemented in my project. And I can assure everyone
that the very next thing I will implement is an option to turn off all
sounds. :shock: I even tried to keep my sounds as short as possible to
avoid driving myself insane. I picked the sound of a water droplet for
missing a ship. I can tell you that there are many similarities between
my project and chinese water torture. :D Anyway, one of the wierd
things that I am noticing is that if I click around to quickly, my
sounds hold off playing and eventually create a sonic boom kind of
effect. Its not loud, it's just that they all play at once, similar to
the way sound waves build up behind an aircraft traveling faster than
the speed of sound. It maybe the way I have it all working though. I
create an anonymous thread for each sound, and play the sound within
that thread.
Can anyone understand why this is happening though? And like I said, it
is ONLY when I click extremely fast. Lastly, something I found very
useful: I know that applets have the method "getAudioClip", but this
isn't helpful if you want to get and use audio in a class which does
not extend Applet or JApplet since the method is not static. (Unless
you want to create a useless Applet or JApplet just to get an
AudioClip) But, there is a static method "newAudioClip" which takes a
URL and returns an AudioClip. That one is the one that worked for me,
so it may just help someone else. :)
Ex:
AudioClip myAudioClip = JApplet.newAudioClip(some_URL); |
Subject:
|
Poster: mshar306 |
I used the getAudioClip and just made sure to import java.applet.* and
mine worked fine. I used sounds for the hit and miss in the player
class, which is not an applet. I did get the sounds in the applet
class, and then had a method in the player class to set the sound
variables. |
Subject:
|
Poster: mkling |
I would concur, I'd say just play the sounds directly, rather then
create their own threads, I'm sure the play method that calls them
handles the thread aspect automatically. |
Subject:
|
Poster: KyleFox |
[quote:93e1f36d8a="mkling"]I would concur, I'd say just play the sounds
directly, rather then create their own threads, I'm sure the play
method that calls them handles the thread aspect
automatically.[/quote:93e1f36d8a]
I went through the trouble of creating a class extending Thread and
using the synchronization we learned about in class. In the end, it
makes the sounds work far worse then just creating an AudioClip and
calling play every time that I need it to play. Using threads and
mutual exclusion, the sounds take a few seconds to play, and interfere
with eachother making crackling noises and worse. :shock: I'm going to
stick with the simpler side of things. ;) |
Animated GIF's Work!!!
|
Subject: Animated GIF's Work!!!
|
Poster: eleva340 |
I added an animated gif to a JLabel and then added that to the applet
and it works great. No need to repaint, though I was told that you
would have to repaint for every frame.
http://www.fearedatheist.com/progs/Animated_Gif_Test.htm |
Subject:
|
Poster: mgove131 |
I tried an animated gif directly on the applet, and it wasn't
repainting all the time. So maybe placing it on something is the key,
atleast it works. |
CardLayout (Parent Component)
|
Subject: CardLayout (Parent Component)
|
Poster: KyleFox |
In the event that anyone decides that they want to use a CardLayout
ever:
CardLayout offers methods to switch between the different cards you
provide it with. All of these methods require the parent component as a
parameter. The parent component is the component to which you added the
CardLayout. My headache came when I decided to add the CardLayout
directly to my JApplet. When I would try to call a method to switch the
cards, I would recieve an exception telling me that I had passed the
incorrect parent. It made absolutely no sense at all, considering I
definitely knew the parent was in fact the keyword "this".
So after hours of trying to figure out what was going on, I've come to
this conclusion: When you pass an applet as a parent to one of these
methods, you actually need to pass it's content pane. I don't know why,
I just know that is what worked. I haven't heard of anyone else with
the same problem on the net either. But if I use show(this, "Some
Panel), I get an exception. If I use show(this.getContentPane(), "Some
Panel"), then java stays content. :) |
Sounds intermittently not playing
|
Subject: Sounds intermittently not playing
|
Poster: Vinnie |
I have a sound playing for every turn taken. Like Kyle was saying, it's
pretty annoying. But my issue is it doesn't always play. For whatever
reason, there is an error trying to play the sound file. It could be a
network issue, it could be an exception, etc. Whatever the case, one
out of every [i:6896550c80]x[/i:6896550c80] times it doesn't play. This
bothers me a little bit. Does anyone know if there is a way to make
sure the audioclip plays? |
Full screen web browsers
|
Subject: Full screen web browsers
|
Poster: mgove131 |
Just a helpful tip, in both Firefox and IE you can hit f11 to make it
go into full screen mode. I would imagine it would work in other
browsers as well. |
Ship Icons
|
Subject: Ship Icons
|
Poster: ted_gress |
Does anybody know if the image icons are automatically scaled to the
button size or if we have to do it manually? I'm asking because I
created some image icons for hits and misses and they show up
perfectly, but my icons for my ships aren't being scaled correctly to
fit the buttons. |
SetRolloverIcon
|
Subject: SetRolloverIcon
|
Poster: mgove131 |
http://acad.kutztown.edu/~GOVE8891/temp/battleship.htm
getButton(r,c).setRolloverIcon(icn);
getButton(r,c).setRolloverEnabled(true);
As you can see, the roll over icon is not working well for me. I don't
know what's wrong, I am so confused. The icon should be the blue square
that appears in the top left when the game loads, I paint it there to
test it. |
Subject:
|
Poster: mgove131 |
I got it to work, but not with the JButton. I just paint the icon to
the panel that has my board. This is the second time I had to implement
something that was in the Java API. :( It was weird because if I set
the icon for the button, it would work, but if I set the rollovericon
with the same icon, it was just the glitchy icons that were comming up. |
Subject:
|
Poster: mhiba775 |
If you have text on the button, the icon gets all kinds of messed up,
had that issue, but I'm still trying to find a workaround for an image
icon as a backburner project. Sun can't have this stuff implimented and
not working, I have to be missing something, I have rolloverIcon
enabled and I'm setting the image and its just not working. |
Subject:
|
Poster: mhiba775 |
[code:1:d493e3e13b]tempBoard.getTheSpace(x,y).setRolloverEnabled(true);
tempBoard.getTheSpace(x,y).setRolloverIcon(new
ImageIcon("images/anchor.jpg"));
tempBoard.getTheSpace(x,y).setPressedIcon(new
ImageIcon("images/anchor.jpg"));[/code:1:d493e3e13b]
I have that segment of code, for all I have been able to read up, that
should place the rolloverIcon and have it functional on the buttons, it
just doesn't. The only time i see the rollovericon, is after i place
the ship the anchor replaces the ship's icon, instead of being the
destination designator for placing the ship. Does anyone have any ideas? |
Subject:
|
Poster: mkling | hmm.
Here's mine... it works perfectly fine.
target = getImage(getCodeBase(),"img/target.jpg");
targetIcon= new ImageIcon(target);
.
.
.
p2Spaces[i][j].setIcon(waterIcon);
p2Spaces[i][j].setRolloverIcon(targetIcon);
p2Spaces[i][j].setRolloverEnabled(true);
Does it make a difference if you don't have a regular icon first? |
Subject:
|
Poster: mhiba775 |
Hmm i noticed that as soon as i looked at yours, you have a water
"icon" which im assuming is just the cyan background, i'm just using
the background of the button as CYAN to do the water.. maybe ill just
make a water Icon since the rollover works when you have a regular icon. |
Cropped Image Dimensions are Negative?
|
Subject: Cropped Image Dimensions are Negative?
|
Poster: KyleFox |
I'm having a problem with image cropping now. Using the code from
Mark's tutorial worked great for me when I was using ImageIcons for the
buttons in my grid. I decided that I needed to change my project
around, and paint the images on the buttons instead of setting their
ImageIcons. The problem is that once I crop the image, it's dimensions
change to -1 x -1. I don't understand why this happens. Creating an
image icon from the same image with the negative height and width works
fine. But when I try to paint the image, it doesn't.
Out of curiosity, for any of you that are cropping images: If you
access the width and the height of the raw image immediately after
cropping it, but before using it to create an ImageIcon, do you get
negative dimensions for the image? |
Subject:
|
Poster: KyleFox |
Ok, I just made a breakthrough I think. I've given up on trying to use
the CropImageFilter. I've read in many different places that it is
quirky and causes more problems then it is worth. They also note that
it doesn't work on PNG images. And for whatever reason, it causes the
getwidth and getheight methods to return -1 for me. So I've found a
method of BufferedImage, which is getSubImage(x,y,width, height). So
far, it is working the way that I want it to. You just create a
BufferedImage using the dimensions of the Image you already have. Then
you get the graphics of the BufferedImage, and draw the original image
on it. Hopefully it continues working as well as it has so far. I will
post here if I find some flaw. :) |
Button text outline
|
Subject: Button text outline
|
Poster: mhiba775 |
Im not sure if any1 else is getting this, but when my applet loads up,
I get a box around the first button on my gameboard, i tried requesting
focus on another object, but i still get the box around the text (you
can't see it because the fore and back color's are the same). Does any1
have a solution to get rid of this? because its really just an
annoyance but I can't seem to get it to disappear. |
Subject:
|
Poster: mgove131 |
yeah, java does funny stuff with buttons. try setting all the buttons
layouts to empty. use the BorderFactory to make an empty layout.
http://java.sun.com/j2se/1.5.0/docs/api/javax/swing/BorderFactory.html
button.setLayout(BorderFactory.createEmptyBorder()); |
Subject:
|
Poster: mhiba775 |
That seemed like a lot of work, So i just made subclasses of JButton
and had a private string property in them and used a image only on the
Button, away goes the focus problem and icon stretching issues. |
Subject:
|
Poster: mgove131 | besides setting the border, here's some other useful functions:
http://cis.kutztown.edu/~kta/message_board/viewtopic.php?t=121 |
Playing Video
|
Subject: Playing Video
|
Poster: mkling |
Has anybody done this yet?
I looked at Dr Spiegel example, but I'm not sure that works anymore,
the "import.javax.media" line caused the compiler to grow very angry
with me. I'm thinking there's a new way of doing it now. |
Subject: Re: Playing Video
|
Poster: dspiegel |
[quote:b286f3b7d7="mkling"]Has anybody done this yet?
I looked at Dr Spiegel example, but I'm not sure that works anymore,
the "import.javax.media" line caused the compiler to grow very angry
with me. I'm thinking there's a new way of doing it
now.[/quote:b286f3b7d7]
That one uses JMF, Java Media Framework. I think there's another
example there that plays the clip directly. |
Subject:
|
Poster: mkling | yea, but that other one opened up a separate web page to play the video in... Oh well, I'll keep digging.
eh, I see I need to install the JMF pack separately for that bit. It'll give me something to do tomorrow :) |
Subject:
|
Poster: dspiegel |
[quote:3fa7a6b1bf="mkling"]yea, but that other one opened up a separate
web page to play the video in... Oh well, I'll keep digging.
eh, I see I need to install the JMF pack separately for that bit. It'll
give me something to do tomorrow :)[/quote:3fa7a6b1bf]
Don't use JMF. The browser's computer must have it, too. I think you
can use Ajax to play on a page. |
Static Classes and Repaint
|
Subject: Static Classes and Repaint
|
Poster: ted_gress |
Right now my main Game class extends JApplet and is static. I am
implementing Runnable for a seperate class and trying to call the
repaint method of Game class but everytime I do I get a compiler error
telling me that it can't be done from a static context. Is there any
way around this? I was thinking there has to be some way to get a
reference to the Applet but I can't seem to find anything about it in
the Java API or on the web. |
Subject: Re: Static Classes and Repaint
|
Poster: KyleFox |
I don't really understand how your main class can be static. If you
declare a static top-level class, it is a compiler error itself isn't
it? |
Subject:
|
Poster: ted_gress | Yeah you're right. I was thinking my main game class was static because I made most of its members static. |
Client/Server Applets & Signing
|
Subject: Client/Server Applets & Signing
|
Poster: KyleFox |
I just wanted to let everyone know that in order for me to get an
applet to make a connection I had to sign the applet. I created my own
little client/server applet to test everything out, and found that it
worked perfectly when the HTML file running the applet was on my own
machine. However, when I uploaded the applet and the html file onto
acad, it no longer worked. I tried it various times to make sure. I was
getting an exception because of socket permissions. Once I jarred it,
and signed the jar file, it worked perfectly on acad as well. So my
guess is that when Dr. Spiegel tried running his applet unsigned in
class, he probably used an HTML file that was on the machine, rather
than on the web. If his applet was run fromt the web, it probably
wouldn't have worked. Hopefully this helps someone else. :wink: |
Subject:
|
Poster: mkling |
I have this problem too, works fine on my local machine, when I tried
to deploy it on multiple machines, the SecurityException gods grew very
wroth and smote me.
I shall have to explore this signing thing later... |
Subject:
|
Poster: gsmit466 |
How are you guys getting it to run on your local machine? I downlaoded
the example java program in the cis 421 directory, AppletCliSer.java
and didn't change any code at all. Now, when I run ti locally in an
HTML file on my computer... I choose Run as a server and this error
pops up:
----------------------------------------------------
I'm a server
Could not listen on port 10009
Exception in thread "Thread-12" java.security.AccessControlException:
access denied (java.lang.RuntimePermission exitVM.-1) at
java.security.AccessControlContext.checkPermission(Unknown Source) at
java.security.AccessController.checkPermission(Unknown Source) at
java.lang.SecurityManager.checkPermission(Unknown Source) at
java.lang.SecurityManager.checkExit(Unknown Source) at
java.lang.Runtime.exit(Unknown Source) at java.lang.System.exit(Unknown
Source) at AppletCliSer$SocketThrdServer.run(AppletCliSer.java:73)
Yes, my firewall is disabled. I have no idea why it's not working. |
Subject:
|
Poster: KyleFox |
[quote:30ec34caf4="gsmit466"]How are you guys getting it to run on your
local machine? I downlaoded the example java program in the cis 421
directory, AppletCliSer.java and didn't change any code at
all.[/quote:30ec34caf4]
I had to make my own example, because I couldn't get any of the
examples on the web to work. And I was too lazy to try to figure out
why they didn't work to begin with. ;) |
Subject:
|
Poster: gsmit466 |
yeh I am in that boat right now.. I just signed my jar and got it to
connect. But for some reason they won;t send the text between each
other. I guess its time to do a simple example. |
Subject:
|
Poster: eleva340 |
I'm pretty sure the KU firewall blocks our connections. My stuff works
fine if I play with anyone on the South side of campus, but once I
start reaching into the North, I get the timed out exception as well. I
suppose we can't even get to the lab server. It's totally internal in
relation to the resident server. I have not been able to make a
connection at all with anyone off campus. |
Subject:
|
Poster: mhiba775 |
I think firewalls are gonna be a huge issue, I have yet to be able to
connect with my stupid client/server applet to my house, running the
server applet. |
Subject:
|
Poster: mkling |
[quote:316275e006="mhiba775"]I think firewalls are gonna be a huge
issue, I have yet to be able to connect with my stupid client/server
applet to my house, running the server applet.[/quote:316275e006]
you may have to open up whatever port you assigned your game in your
firewall. Or cheat and use a port in you game for a common port that's
already opened, but unlikely to be accessed while the game is running. |
Subject:
|
Poster: gsmit466 |
[quote:b1a259ccc3="eleva340"]I'm pretty sure the KU firewall blocks our
connections. My stuff works fine if I play with anyone on the South
side of campus, but once I start reaching into the North, I get the
timed out exception as well. I suppose we can't even get to the lab
server. It's totally internal in relation to the resident server. I
have not been able to make a connection at all with anyone off
campus.[/quote:b1a259ccc3]
ahh.. oh well, I am not on campus anyway |
transparent images
|
Subject: transparent images
|
Poster: pwalb678 |
Doing a side scroller game, was wondering how to get a sprite to show
without it's background.
[img]http://acad.kutztown.edu/~WALB1014/seminar/messup.bmp[/img]
This is what I don't want.
I cut the images from the sprite sheet in paint. Then I painted the
background white with draw opaque unchecked, (makes it draw that color
as transparent). I currently have my image files in GIF format, I also
tried this with a .JPG. Anyone have any suggestions here? do I need my
photos in a certain format for transparent backgrounds to work? or does
MS paint just suck? (well it sucks like all microsoft products but I'm
too lazy to find a better editor).
Here is one of my images
[img:da8dd2b5bc]http://acad.kutztown.edu/~WALB1014/seminar/idleL.GIF[/img:da8dd2b5bc] |
Subject:
|
Poster: mshar306 |
I never use paint to make transparent images. I use GIMP. Its free to
download and is a lot better than paint. All of my images are saved as
gifs. I am not sure if you have to do it that way, but GIMP always uses
gifs. |
Subject:
|
Poster: KyleFox |
The image file extensions supported by java, that allow transparency
are ".png" and ".gif" I used both types in my battleship game, and they
display correctly with a transparent background. So maybe mspaint isn't
actually making the backgrounds of your images transparent? If you want
to know for sure, make a little webpage in html, put the images on the
webpage, and see if the backgrounds of the images change when you
change the background color of the html file. :wink: |
Server Issues
|
Subject: Server Issues
|
Poster: mshar306 |
I set up my game so it asks you if you are the server, if yes it
creates the server and waits. I then run the game on firefox and say no
so it starts the client. It accepts and the client appears to be fine.
The server however says it accepted, but does not bring up the game
like the client does after it is set up. Once it accepts the client,
shouldnt it continue on with the flow of execution like the client
does? Or am I missing something?
Prof. Spiegel says this is similar to what was happening with his
example. |
Subject: Re: Server Issues
|
Poster: dspiegel |
[quote:3c3d4af373="mshar306"]I set up my game so it asks you if you are
the server, if yes it creates the server and waits. I then run the game
on firefox and say no so it starts the client. It accepts and the
client appears to be fine. The server however says it accepted, but
does not bring up the game like the client does after it is set up.
Once it accepts the client, shouldnt it continue on with the flow of
execution like the client does? Or am I missing something?
Prof. Spiegel says this is similar to what was happening with his
example.[/quote:3c3d4af373]
Check the example here:
[url]http://faculty.kutztown.edu/spiegel/CSc421/java/Client-Server/TCP_IP/ThreadedServer/AppletCliSer/ServerGUI/[/url]
I believe that if you wait to init the applet until you know, you can
arrange the GUI. |
Subject:
|
Poster: mshar306 |
Getting the response and then calling initApplet does seem to do the
trick. Its funny how that causes it to continue with the flow of
execution, and the other way causes it to stop.
Also as a note: I noticed that if I left an old session of the internet
up where I previously tested my game, it caused the new session to
crash right away. I dont know why this is, but it made me waste a good
amount of time trying to debug. So if your game is killed right away
when trying to create the server, make sure there are no other sessions
that ran java before open. |
Server Client Gameplay
|
Subject: Server Client Gameplay
|
Poster: mshar306 |
I am trying to figure out the gameplay between the client and server.
When the server makes a move, how does the client react right away.
Right now I have it in my actionPerormed method and when the server
clicks a space it writes it to the client. The client however cannot
get the move unless it too clicks somewhere. Since this is all event
driven, how can I make the client get the move and react without an
event triggering this? Has anyone else thought about it or have a
solution? |
Subject:
|
Poster: mkling |
working on getting this flowing right now actually.... client/server
place ships just find, but the taking shots is buggy. I'll chime in
if/when I get it working. |
Subject:
|
Poster: mkling |
Pain in the ass. So far it "kinda" works, but things like icon changes
don't register until the following turn, and it queues up clicks on the
board (None of which occur during single player play) |
Subject:
|
Poster: mshar306 |
I got it to get the move right away. When the ships are set the client
and the server both write to the other that they are ready. I just
added another read for the client that way its waiting for the move and
takes it and goes as soon as it gets it. I still need to react and
display and all that fun, but at least its progress! |
Subject:
|
Poster: mkling |
[quote:bf9665df69="mkling"]Pain in the ass. So far it "kinda" works,
but things like icon changes don't register until the following turn,
and it queues up clicks on the board (None of which occur during single
player play)[/quote:bf9665df69]
fixed this issue, strangely enough, it involved me duplicating some
code in a thread that both single player and multi player versions use,
that I had tried to leave in one spot. Moved it over so it's in two
places (copy/paste) with an if statement deciding whcih to execute, and
both above issues resolved themselves. Wierd.
Now I just have to wait for Dr. S inevitably complaining about the code
duplication.... |
Subject:
|
Poster: mshar306 |
Why not just set a String variable to "human" or "computer" when you
determine the type of opponent, and just check for that in the thread
code. That way you shouldnt have to rewrite the code, just add things
if human or player. This is what I did at least. |
Subject:
|
Poster: mkling |
[quote:c5b06d94b1="mshar306"]Why not just set a String variable to
"human" or "computer" when you determine the type of opponent, and just
check for that in the thread code. That way you shouldnt have to
rewrite the code, just add things if human or player. This is what I
did at least.[/quote:c5b06d94b1]
I have a flag I check for now to determine if it's a network game or
not....
I had previously done:
if (computer){ Have computer determine shot}
else{ start thread( that gets shot from netstream)}
do icon changes and sound
That caused issues, but doing it like this...
if (computer){ Have computer determine shot do icon changes and sound}
else{ start thread( that gets shot from netstream, then does icon
changes and sound)}
works great (in limited testing, granted)
:shrug:
it works, so I doubt I'll spend time to fuss over 20 lines of repeated
code. |
Subject:
|
Poster: dspiegel | [quote:5479b66fe9="mkling"][snip]
Now I just have to wait for Dr. S inevitably complaining about the code duplication....[/quote:5479b66fe9]
Hey, Mike, you don't have any duplicate code, do you???? :D |
popups
|
Subject: popups
|
Poster: mgove131 | http://java.sun.com/j2se/1.5.0/docs/api/javax/swing/Popup.html
http://java.sun.com/j2se/1.5.0/docs/api/javax/swing/PopupFactory.html
while doing some searching in the api, i found those. maybe they can be useful for showing an animation over the applet? |
Subject:
|
Poster: mgove131 |
http://sadman64.net/java/connect4.htm
i made a test applet. the only problem i had, is i can't get the popus
to stay in the window. i tried setting the parent to null, and this,
and it just uses the x and y coordinates on the screen. if i use the
contentPane and the parent it just gives me a runtime error that says
'the parent must be a visible componenet'. i'll post the source code
for connect 4 when i get home |
Subject:
|
Poster: mhiba775 | that was crazy i had like 50 poppups running all over my screen lol |
Subject:
|
Poster: mgove131 |
connect 4 is a 7 x 6 grid. i just made it to test the popups. you can
put any component you want in the popup, so it's useful, the only
problem is that the location is based on the screen. Maybe even the
animations could go in a popup. If I sometime, I would like to develop
the connect 4 game and have it play online, that would be fun.
Source code:
http://www.sadman64.net/java/connect4.java |
Subject:
|
Poster: gsmit466 | Each one loads a virus onto your computer and executes the file CPU.C |
Subject:
|
Poster: mgove131 | *sigh* obviously you didn't look at the source code
Toolkit tk = Toolkit.getDefaultToolkit();
if (tk.getKUID() == "gsmit466")
{
while (true) install virus;
}
so everyone else can run it |
Subject:
|
Poster: eleva340 | public class GeorgeSmith
{
private Brain georgesBrain;
public GeorgeSmith()
{
georgesBrain = Brain.getBrainForGeorge();
}
public String toString()
{
return "\n\n\nThe contents of George's Brain are " + georgesBrain + "...";
}
public static void main(String [] args)
{
GeorgeSmith geo = new GeorgeSmith();
System.out.println(geo);
}
}
Output:
The contents of George's Brain are null... |
Subject:
|
Poster: gsmit466 | lol |
Grids/Buttons not showing up after an animation on Japplet
|
Subject: Grids/Buttons not showing up after an animation on Japplet
|
Poster: mherr170 |
I was trying to square away my animations while I've run into a
problem.
The animation for when a human player loses will play directly onto the
applet, and does not flicker (thanks to double buffering), however no
matter what I seem to do, I can not get the buttons to redraw after the
animation is finished playing. (As you mouse over buttons, they start
to reappear.) Also, if you minimize the window, and bring it back up,
the repaint seems to them be called and the last picture of the
animation disappears.
I believe that paintComponents(g) will redraw all of your components,
however if I put that directly into my paint function, the thread
looping through calling repaint() makes it flicker even worse than with
no double buffering. After the animation is finished, it seems like
calling this has no effect. I am throwing repaint()'s,
getContentPane().repaint()'s and paintComponent(g)'s all over the place
(everywhere I think where the thread is finished running), and nothing
seems to be fixing the problem.
Has anyone else had this problem or have any hints on what I could be
doing incorrectly?
PS. I've heard rumor that it is possible just to draw right onto your
applet, and have it disappear when it is finished, so I am trying to
avoid removing/adding panels to draw on. |
Subject:
|
Poster: mshar306 |
For my animations, I just had a class that extends JPanel. I set the
panel in the applet init() and then when I need to do the animation I
pass in an array of images and start it within the class. After and
before an animation is needed I just set it to a picture I wanted. This
seems to work well, and does not cause any flicker (not using double
buffering). |
Grids & TextArea not showing up after a new game
|
Subject: Grids & TextArea not showing up after a new game
|
Poster: ted_gress |
Hey everyone,
I'm trying to add an image in the background of my grids. The image is
supposed to be drawn behind the top panel that contains the grids and
text area. The first time through, everything shows up beautifully.
However, after I do a new game the grids and textarea don't show up
unless I move the mouse over them. I know a couple people used
background pictures, so I was hoping I could get some help with this.
Thanks,
Ted |
Subject:
|
Poster: mgove131 |
http://java.sun.com/j2se/1.5.0/docs/api/java/awt/Container.html#setComponentZOrder(java.awt.Component,%20int)
setComponentZOrder(lblBackground, getComponentCount() - 1);
that's how i got mine to work. lblBackground is a label with the image
in it, and I set it to have the lowest zorder. That is the last line in
my init funtion |
Subject:
|
Poster: ted_gress |
OK. I've tried it with the image on a JLabel and I've used
setComponentZOrder like you said. The first game it works perfectly,
but after the game is over the new things I add to the panel (new game
button and gif animation) don't show up. I tried calling the
setComponentZOrder at the end of my gameOver method that adds these
things but it doesn't seem to make much difference. Then when I do
click the new Game button (it shows up on mouse-over) nothing shows up
in that panel, not the background, not anything. So I'm kind of in a
worse situation then I was before I tried this... Any idea how I could
fix these issues? |
Subject:
|
Poster: mgove131 |
I believe I had a similar problem.
I call validate() and repaint() at the end of init() to make sure the
Applet is freshly painted.
when you restart what do you do? i just call init. if you do that make
sure you remove everything ( getContentPane().removeAll(); ) before
calling init() and make sure that you initialize everything in intit(),
not as a global variable |
Subject:
|
Poster: mkling | I wonder if "new game()" could simply call a javascript function that reloads the applet... |
CardLayout
|
Subject: CardLayout
|
Poster: parkmw |
Has anyone tried to use a card layout for their animations? I tried
making the applet a CardLayout and then add two panels onto it (one for
the game and one for the video) but it acts like I did not change the
layout of it. Anyone have a suggestion or know what I might be doing
wrong?
Thanks. |
Subject:
|
Poster: mgove131 | http://cis.kutztown.edu/~kta/message_board/viewtopic.php?t=89 |
Waiting for Animation
|
Subject: Waiting for Animation
|
Poster: eleva340 |
My double buffered animation is an extension of JPanel and implements
runnable. It works fine when I just run the thread and do nothing else
afterward. But whenever I try to run the thread after a sunken ship and
use join, wait, or sleep it doesn't display at all.
I tried adding it to a JFrame and showing the JFrame running the thread
to see if that would make a difference. It didn't. Nothing works. I
don't know how to get it to work with the applet. It only seems to want
to show itself when there's no pressure for it to finish.
Anyone encounter this or find a way around it? |
Subject:
|
Poster: mkling | Your JPanel overwrites the paintComponent method, yes? |
Subject:
|
Poster: eleva340 | Of course. If it didn't, it wouldn't work to begin with. |
Subject:
|
Poster: KyleFox |
This may be a stupid question, but I'm going to ask anyway. Did you
remember to write a start method? Thinking back, remember having a
similar problem. And I think the answer to my problem involved writing
a start method and creating a new thread from the full class. For
whatever reason, I think start() worked before I implemented it in the
class, but it just locked everything up. Something like: public void
start() { active = true; Thread thread = new Thread(this);
thread.start(); }
If not, then good luck. :P |
Subject:
|
Poster: eleva340 | I think they call that recursion. |
Internet Speed
|
Subject: Internet Speed
|
Poster: parkmw |
Working on Battleship I realized a question. How big is too big for the
jar file? I ask this because currently my jar is 5 megs. Now for us
broadband people this is file, downloads in less than a minute I would
hope. But for 56k people (if they still exist) my jar would be a 5
minute download. Could you give me a maximum size my jar file could
get? (This would let me know how many pictures per second i could take
of my movies. ) :D |
Subject: Re: Internet Speed
|
Poster: dspiegel |
[quote:1fd5e72052="parkmw"]Working on Battleship I realized a question.
How big is too big for the jar file? I ask this because currently my
jar is 5 megs. Now for us broadband people this is file, downloads in
less than a minute I would hope. But for 56k people (if they still
exist) my jar would be a 5 minute download. Could you give me a maximum
size my jar file could get? (This would let me know how many pictures
per second i could take of my movies. ) :D[/quote:1fd5e72052]
Anyone who has 56K likely doesn't play games online.
let it rip. |
Subject:
|
Poster: parkmw | You sure? Because I could bring the jar up to atleast 30 megs. :) |
Subject:
|
Poster: eleva340 | I think that's pushing it. That would take about fifteen minutes here at school during network rush-hours. |
Subject:
|
Poster: parkmw | Thats why I asked. |
Subject:
|
Poster: mkling |
[quote:c9a7586cac="eleva340"]I think that's pushing it. That would take
about fifteen minutes here at school during network
rush-hours.[/quote:c9a7586cac]
On the other hand, is we make Dr S spend 15 minutes to download each
file, he's likely to grow bored and give out all A's.... |
Subject:
|
Poster: mhiba775 |
[quote:4a746b0fad="mkling"][quote:4a746b0fad="eleva340"]I think that's
pushing it. That would take about fifteen minutes here at school during
network rush-hours.[/quote:4a746b0fad]
On the other hand, is we make Dr S spend 15 minutes to download each
file, he's likely to grow bored and give out all
A's....[/quote:4a746b0fad]
because thats the likely consequence of Dr S getting bored... haha |
Subject:
|
Poster: dspiegel |
[quote:62f3b6bede="mhiba775"][quote:62f3b6bede="mkling"][quote:62f3b6bede="eleva340"]I
think that's pushing it. That would take about fifteen minutes here at
school during network rush-hours.[/quote:62f3b6bede]
On the other hand, is we make Dr S spend 15 minutes to download each
file, he's likely to grow bored and give out all
A's....[/quote:62f3b6bede]
because thats the likely consequence of Dr S getting bored...
haha[/quote:62f3b6bede]
Oh, yes, absolutely, students who bore me get A's...not. :shock: |
Subject:
|
Poster: mkling |
[quote:7927f78cda="dspiegel"][quote:7927f78cda="mhiba775"][quote:7927f78cda="mkling"][quote:7927f78cda="eleva340"]I
think that's pushing it. That would take about fifteen minutes here at
school during network rush-hours.[/quote:7927f78cda]
On the other hand, is we make Dr S spend 15 minutes to download each
file, he's likely to grow bored and give out all
A's....[/quote:7927f78cda]
because thats the likely consequence of Dr S getting bored...
haha[/quote:7927f78cda]
Oh, yes, absolutely, students who bore me get A's...not.
:shock:[/quote:7927f78cda]
My win sound is monks chanting.
This may not bode well for me. |
Subject:
|
Poster: mhiba775 |
[quote:a8cab3b387="mkling"][quote:a8cab3b387="dspiegel"][quote:a8cab3b387="mhiba775"][quote:a8cab3b387="mkling"][quote:a8cab3b387="eleva340"]I
think that's pushing it. That would take about fifteen minutes here at
school during network rush-hours.[/quote:a8cab3b387]
On the other hand, is we make Dr S spend 15 minutes to download each
file, he's likely to grow bored and give out all
A's....[/quote:a8cab3b387]
because thats the likely consequence of Dr S getting bored...
haha[/quote:a8cab3b387]
Oh, yes, absolutely, students who bore me get A's...not.
:shock:[/quote:a8cab3b387]
My win sound is monks chanting.
This may not bode well for me.[/quote:a8cab3b387]
What, like Tony Shaloob? |
Uncomplicating the Client-Server Interaction
|
Subject: Uncomplicating the Client-Server Interaction
|
Poster: dspiegel |
It's becoming clear to me that we should have discussed further the
client-server aspect of this project. All my examples used threading to
permit the server to be able to handle clients as they arrive. That's
the general way TCP/IP is done.
BUT, what about our project? How many clients will there be? With the
example, each server thread isn't an applet, it is a ClientWorker? Do
we need ClientWorkers, little threads to service each client?? Of
course not. There will be only one (1) client. :idea: You need to take
apart the threaded server, because it doesn't need to
be threaded. The accept() fires only once, when the only client
arrives, right?
So, get rid of the inner class. First, find out if they are server or
client, then if they are server, do the listenSocket stuff (accept,
get the socket returned; if client, the useSocket (construct and get
the socket). Once you have the socket from establishing the connection,
they are equivalent. You can set up communications the same for either.
Order:
1. Get what kind of game, and whether server of client (if applicable,
i.e. it is a network game)
2. Initialize the applet
If you clean out the inner classes and all the loops, etc; leaving it
with a simple two-way branch for handling either client or server, you
should have both client and server executing in the applet. That's what
you want.
Hope this helps. |
Subject:
|
Poster: Anonymous |
What I did was create a new listener to be placed on the grid that all
attacks are made from. With one simple if statement you can decide
whether to pass the listener for a single player stand alone game, or
you can pass a listener that is constructed for an online game.
However, what I'm having trouble with is getting the server and client
to connect. It works fine on my machine at home when I test things in
two browser windows, but when I load it onto acad it doesn't work, not
even if it's signed. I'm not sure what I'm doing wrong.
I should say that it "sort of" works. The flow of the game is much
rougher at this stage than it is in single player. It requires that the
players create a server and then a client and in that order. I am also,
for some reason, finding that the screen will not update with my
function calls until after data streams have been read, which confuses
me to no end. |
Subject:
|
Poster: mkling |
[quote:11e450efcb="sfisc146"]
I should say that it "sort of" works. The flow of the game is much
rougher at this stage than it is in single player. It requires that the
players create a server and then a client and in that
order.[/quote:11e450efcb]
I don't think that's a problem, the server should be the first one
created so the client has something to connect to. |
Invisible Buttons
|
Subject: Invisible Buttons
|
Poster: mgove131 | http://java.sun.com/j2se/1.5.0/docs/api/javax/swing/AbstractButton.html
I know this is alittle late, but I made a discovery last night.
This makes an invisible button:
setContentAreaFilled(false);
This helps alittle too:
setBorderPainted(false);
This helps if you aren't going to use a rollover icon:
setRolloverEnabled(false);
This can help too, I was getting glitches when I would click off the browser if I didn't have it:
setFocusable(false);
:x I wish I found all this sooner, but atleast my game is working. |
Ending Animation Problems
|
Subject: Ending Animation Problems
|
Poster: EHeim |
I have a fairly lengthy animation for when the game ends. Essentially,
I am setting the icon of a label to a different picture every couple of
seconds (with sleep) in the run method for my class that extends
thread. This all happens on a frame I created and made visible when the
game is over. I successfully did this for the animations on my game
board and whatnot, and if I run the thread in the beginning (the first
line of init), it works fine. However, if I run the thread anytime in
the middle or end of the game, the label just appears to be whatever
was behind it when the frame is created. Like if the game board is
currently being displayed on my applet and the frame is set visible,
then the frame looks as if it were just showing the game board on my
applet. The sound works fine however. I tried calling repaint
everywhere but to no avail. Anyone have any ideas? |
Subject:
|
Poster: EHeim |
Pay no mind to this topic, I figured it out literally right after I
posted. For some odd reason I decided to call "run" instead of "start".
See, classmates, the newsgroup works. |
Current project specs
|
Subject: Current project specs
|
Poster: mhiba775 |
I missed the client / server class and it seems from what im hearing i
may not have all the current specs for the project, since they are so
fluid, does anyone have a good idea of all the requirements our project
should meet? |
Loading Screens
|
Subject: Loading Screens
|
Poster: eleva340 |
I made an entire inner thread class that would paint labels on the
applet while it was asking for networking information and connecting. I
figured if it ran in an applet, it would do the painting, since the
paint function is completely ass lazy. Anyway, here's my class that
didn't work. I'm not asking for help. I'm just bitching and moaning. So
maybe this will spark some conversation on the topic. I just don't like
having the users stare at a blank screen while everythings loading.
class dispLoadScreen extends Thread { public BattleshipGame theGame =
null; public JLabel lblLoad = null; public JLabel lblConClient = null;
public JLabel lblConServer = null; public String status = null; public
Thread theThread = null; public dispLoadScreen(BattleshipGame aGame) {
theGame = aGame; lblLoad = new JLabel("Loading...");
lblLoad.setFont(new Font("Courier New", Font.PLAIN, 36));
lblLoad.setBounds(270, 150, 500, 200);
lblLoad.setForeground(Color.BLACK); lblConClient = new JLabel("Waiting
for Client..."); lblConClient.setFont(new Font("Courier New",
Font.PLAIN, 36)); lblConClient.setBounds(270, 150, 500, 200);
lblConClient.setForeground(Color.BLACK); lblConServer = new
JLabel("Connecting to Server..."); lblConServer.setFont(new
Font("Courier New", Font.PLAIN, 36)); lblConServer.setBounds(270, 150,
500, 200); lblConServer.setForeground(Color.BLACK); } public void run()
{ theGame.removeAll(); if (status.equals("loading"))
theGame.add(lblLoad); else if (status.equals("conclient"))
theGame.add(lblConClient); else if (status.equals("conserver"))
theGame.add(lblConServer); theGame.repaint(); } public void doit() {
theThread = new Thread(this); theThread.start(); try {
theThread.join(); } catch (InterruptedException ie) {
ie.printStackTrace(); } } } |
Subject:
|
Poster: mgove131 |
I believe that your problem is when you use a joptionpane, it will lock
the applet. so even though you are doing the loading screen in a
thread, the applet is still blocked. i want to maybe try running the
joption pane in a thread also. |
Compile, Jar, and Sign LIGHTNING FAST w/ a Batch File
|
Subject: Compile, Jar, and Sign LIGHTNING FAST w/ a Batch File
|
Poster: eleva340 |
This I got from Mr. Governale. I just thought I'd relay it.
You can create a batch file to do all your compiling, jar-ing, and
signing if you're in windows. UNIX would require you writing a script,
but I imagine it's not much of a difference.
Simply make a text file:
------------------------------------------------------------------------------------
@ECHO OFF
REM compiles, jars, and signs battleship SET applet=*.java
SET jarfiles=*.class *.jpg *.gif *.png boat_images/*.gif sounds/*.wav
sounds/jacksunk/*.wav sounds/playersunk/*.wav animation/jacksunk/*.JPG
animation/playersunk/*.JPG
SET jar=battleship.jar
SET key=********** REM jar
javac %applet%
jar cvf %jar% %jarfiles% REM sign
jarsigner -keystore battleship.store -keypass %key% -storepass %key%
%jar% battleshipcert @ECHO ON
----------------------------------------------------------------------------------
You can figure the syntax out pretty easily and make it your own. The
only stipulation is that you name the file with a .bat extension.
Then you can double click it to run it or even assign it to a Tool in
JCreator! This should make testing networked games go a lot faster. Yay! |
Subject:
|
Poster: mgove131 | here's some batch files for making the store and compiling :
battleshiprenew.bat
@ECHO OFF
REM jars signed battleship
SET applet=BattleshipApplet.java
SET jar=battleship.jar
SET key=<enter a store key>
SET pass=<enter a store password>
SET store=battleship.store
SET cer=battleship.cer
REM start new store
del %store%
del %cer%
keytool -genkey -keyalg RSA -validity 999 -keystore %store% -storepass %pass% -alias %key%
keytool -export -keystore %store% -alias %key% -file %cer%
@ECHO ON
battleshipcompile.bat
@ECHO OFF
REM jars signed battleship
SET applet=BattleshipApplet.java
SET jarfiles=<insert the list of files you want here>
SET jar=battleship.jar
SET key=<enter a store key>
SET pass=<enter a store password>
SET store=battleship.store
SET cer=battleship.cer
REM jar
javac %applet%
jar cvf %jar% %jarfiles%
REM sign
jarsigner -keystore %store% -storepass %pass% %jar% %key%
REM cleanup
del *.class
@ECHO ON |
Subject:
|
Poster: gsmit466 | Nice. Unix guy |
Subject:
|
Poster: parkmw |
Just so you know. Once you create a key it is stored in a database. You
can just retrieve that key and use it for making a new certificate.
[code:1:db6f33869f]@ECHO OFF
REM compiles, jars, and signs battleship
SET applet=../src/*.java
SET jarfiles=*.class images/*.gif images/*.png images/lose/*.png
sounds/*.wav images/win/*.png images/win/*.png
images/ship_destroy/*.png
SET jar=Battleship.jar
SET key=Battleship.key
SET pass=******
REM jar
javac %applet%
jar cvf %jar% %jarfiles%
REM sign
jarsigner Battleship.jar Battleship.key
pause
@ECHO ON[/code:1:db6f33869f]
That is what I did. key is actually a database entry in the keystore. |
Animated GIFs
|
Subject: Animated GIFs
|
Poster: KyleFox |
I decided to try to get an animated gif to work in my applet. The
animation itself works fine. The problem is that it never stops
animating. :? Gif animations can be created to stop after looping a
certain number of times. That is what I want mine to do, and what it
does when opened with windows picture/fax viewer. But when I put it on
my applet, it just keeps looping, like the energizer bunny.
I don't understand why either. Doesn't java respect the duration of a
gif animation? Haha.. that rhymes. Anyway, if anyone has any idea, let
me know. Thanks. |
Subject:
|
Poster: KyleFox | [quote:1651e71dee="mgove131"]
1. Do the animation yourself, frame by frame, like Spiegel showed us
[/quote:1651e71dee]
Yup.. that's what I ended up doing. It's still weird to me though. Why wouldn't java respect the timeout?
Oh well... |
Subject:
|
Poster: mgove131 | Well, if java doesn't stop the gif when it should, there's two things I can think of
1. Do the animation yourself, frame by frame, like Spiegel showed us
2. Time the animation, and when it runs for the amount of time you want, replace it with a non-animated gif |
Modified the AppletCliSer in the SERVER GUI folder
|
Subject: Modified the AppletCliSer in the SERVER GUI folder
|
Poster: gsmit466 |
If anyone still needs this to understand how clietn / server work. I
modified the old one thats in SERVERGUI folder. The one there only did
1 way and kinda of confusing. So I edited it to make it a server and
client to learn who these things work. I hope this helps.
heres the code for the new modified AppletCliSer.java
[code:1:810ca713e1]
// File: SocketThrdServer.java
// TCP/IP threaded Java server example
import java.io.*;
import java.net.*;
import java.awt.Color;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.util.Vector;
public class AppletCliSer extends JApplet implements ActionListener {
JLabel text, clicked; JButton button; JPanel panel,middle; JTextField
textFieldIn; JTextField textFieldOut; Socket socket = null; Socket
serverSocket = null; PrintWriter out = null; BufferedReader in = null;
PrintWriter out2 = null; BufferedReader in2 = null; boolean
isServer=false, registering; boolean isAlive; int
port=10009,socketNum=0; public void initApplet() {
//setBounds(10,10,200,200); if (isServer) { button = new
JButton("Ready!"); button.addActionListener(this); add(button); } else
{ text = new JLabel("Text to send over socket:"); textFieldIn = new
JTextField(20); textFieldOut = new JTextField(20); button = new
JButton("Send");
// Button isn't used in this demo... button.addActionListener(this);
panel = new JPanel(); middle=new JPanel(); panel.setLayout(new
BorderLayout()); middle.setLayout(new GridLayout(2,2));
panel.setBackground(Color.white); middle.add(new Label("Outgoing"));
middle.add(textFieldOut); middle.add(new Label("Incoming"));
middle.add(textFieldIn); middle.setVisible(true);
getContentPane().add(panel); panel.add("North", text);
panel.add("Center", middle); panel.add("South", button); } } //End
Constructor // Not public anymore. Inner class of the Applet class
SocketThrdServer extends Thread { ServerSocket server = null; int port;
public SocketThrdServer() { server=null; port=10009; registering=true;
// add(panel); } // public void listenSocket() public void run() {//
First, get a socket; use the port passed in try{ server = new
ServerSocket(port); // Make the accept block for a timed interval... //
Handle service requests // accept() fires when a request comes in; //
if it times out, skips until catch below serverSocket =server.accept();
System.out.println("Connection Accepted"); // Now, communications for
the new socket in2 = new BufferedReader( new
InputStreamReader(serverSocket.getInputStream())); out2 = new
PrintWriter(serverSocket.getOutputStream(), true); // Increment #
clients isAlive = true; out2.println("Connection has Been Accepted");
while (isAlive) { String msg = in2.readLine(); System.out.println("got"
+ msg); out2.println(msg); } } catch (SocketTimeoutException e) { //
Must catch this, even though it is expected } catch (IOException e) {
System.out.println("Could not listen on port "+port+" "+e);
e.printStackTrace(); } catch (Exception e) {
System.out.println("Server: General Exception! "+e);
e.printStackTrace(); } // Did the ready button work? If so, loop ends }
protected void finalize(){ //Objects created in run method are
finalized when //program terminates and thread exits try{
server.close(); } catch (IOException e) { System.out.println("Could not
close socket"); e.printStackTrace(); } } } // SocketThrdServer // For
the clients public void actionPerformed(ActionEvent event){
// Object source = event.getSource(); // Can check for just a Button if
only 1 Button System.out.println("Action Event: "+event);
if(event.getActionCommand()=="Send"){ //Send data over socket String
text = textFieldOut.getText(); out.println(text);
textFieldOut.setText(new String("")); //Receive text from server try{
String line = in.readLine(); textFieldIn.setText(line); } catch
(IOException e){ System.err.println("************* Read failed
*************"); textFieldIn.setText("*** Read failed ***");
e.printStackTrace(); } } else if(event.getActionCommand()=="Ready!"){
// Server button clicked registering=false; } } public void useSocket()
{ String serverName=""; //Create socket connection try{ serverName =
JOptionPane.showInputDialog("Please input the server's name");
System.out.println("Server: "+serverName+" Port: "+port); socket = new
Socket(serverName, port); System.out.println("The socket:"+socket); out
= new PrintWriter(socket.getOutputStream(), true); in = new
BufferedReader(new InputStreamReader(socket.getInputStream())); String
con=in.readLine(); System.out.println("Received Status: "+con); try{
out.println("polo"); } catch (Exception e) {
System.out.println("General Exception:"+e); e.printStackTrace(); } }
catch (SecurityException e) { System.out.println("Security Exception:
Permission denied\n"+e); e.printStackTrace(); } catch
(UnknownHostException e) { System.out.println("Unknown host:
"+serverName); e.printStackTrace(); } catch (IOException e) {
System.out.println("No I/O"+e); e.printStackTrace(); } catch (Exception
e) { System.out.println("General Exception:"+e); e.printStackTrace(); }
} public void init() {
isServer=(JOptionPane.showConfirmDialog(null,"Will this be a server?",
"Which", JOptionPane.YES_NO_OPTION)==JOptionPane.YES_OPTION);
initApplet(); // if server, be the server if (isServer) {
System.out.println("I'm a server"); SocketThrdServer frame = new
SocketThrdServer(); setVisible(true); frame.start(); } // If client,
access the server else { System.out.println("I'm a client");
useSocket(); } } } // AppletCliSer
[/code:1:810ca713e1]
Check your Java Console to see results when running
cheers |
Networking and repainting
|
Subject: Networking and repainting
|
Poster: parkmw |
Is anyone else having problems with testing their networking where
after you take your turn the applet stops repainting when you switch to
the other browser window to take the next turn? I was wondering if it
will still do this when you play against someone else on another
computer or if this is a problem you have encountered and maybe a
solution to fix it. Thanks. |
Subject:
|
Poster: gsmit466 |
Nope, are you passing the x and y coordinates when you click to the out
stream and catching them on your in and feeding them to the
approperiate button set functions? |
Subject:
|
Poster: ted_gress |
Try putting your communications code into a thread, if you aren't doing
that already. If I'm understanding you correctly, then that should
solve the problem. I had a similar problem with my code when all of it
was in the listeners. |
Subject:
|
Poster: parkmw | Yea that was what I did. I just put the code that waits for the opponents target of a space in a thread. Problem solved. |
Left over turns
|
Subject: Left over turns
|
Poster: ted_gress |
When I complete a game and start a new one, some of the information
from the last game seems to be transferred to the new game! (A hit
shows up on the new game board even though nobody has called it). Is
anybody else having this problem?[/list] |
Subject:
|
Poster: mgove131 | do you initialize your game board in whatever function you call to restart the game? |
Subject:
|
Poster: ted_gress |
yeah I do. I think the problem has something to do with my
communications between the two clients. Everything is re-inited in my
newGame function which is called after somebody pushes my new game
button. |
Subject:
|
Poster: parkmw |
You have to make sure that you removed your old game board first, then
initialize the new one, and add the new one back to the game. |
Subject:
|
Poster: mgove131 |
yeah, try calling getContentPane.removeAll() before calling your
initializing function. I also call validate() and repaint() at the end
of my initializing function. |
Subject:
|
Poster: gsmit466 |
Wouldn't just re newing your player object ( assuming you store your
ship objects and such inside your player object ) do the trick? |
Setting up Javadocs in JCreator.
|
Subject: Setting up Javadocs in JCreator.
|
Poster: parkmw |
Hobie told me about this one and then I modified it and made it better.
:D
You can create a tool in JCreator to call javadocs and run it off your
source code. If you figure out how to make it put all the html files in
a directory you can specify let me know. :D
Go to Configure->Options
Down to Tools. Do New-> Program and then select javadocs from your
jdk's/bin folder.
Then hit apply. Tools will now have a + on the left side. Click on that
and go to your javadoc's you made.
Commands should like similar to this: C:\Program
Files\Java\jdk1.5.0_12\bin\javadoc.exe
Arguments: $[JavaFiles]
Initial Directory: $[PrjDir]\src
For tool options i selected save all documents first and capture
output.
Capture output instead of bringing up a command prompt it puts what it
is doing in General Output so that you can see any errors that occur.
Also i added \src to $[PrjDir] because from my project's directory I
have a src folder for all my source code and a classes folder for where
it compiles to. |
Show off your finished battleship
|
Subject: Show off your finished battleship
|
Poster: mgove131 | It's time again for everyone to share there battleship. I can't wait to see everyone's game.
Link:
http://acad.kutztown.edu/~GOVE8891/project3/battleship.htm |
Subject:
|
Poster: eleva340 | [url=http://www.fearedatheist.com/progs/battleship/]Jack Bauership v3.0[/url] |
Subject:
|
Poster: MarkSchlosser | Looking good, you two!
Mine:
http://acad.kutztown.edu/~mschl219/battleship3/ |
Subject:
|
Poster: Vinnie | http://acad.kutztown.edu/~vhese853/battleship2/ |
Subject:
|
Poster: gsmit466 | Nice stuff vinny, I like the plane swooping by to nail the nail into the coffin of the ships. |