Some background reading available at Ars Technica, see Climate:
http://episteme.arstechnica.com/eve/forums/a/tpc/f/770002407831/m/841006407831
Additional answers to questions can be found here:
http://gristmill.grist.org/skeptics
Some background reading available at Ars Technica, see Climate:
http://episteme.arstechnica.com/eve/forums/a/tpc/f/770002407831/m/841006407831
Additional answers to questions can be found here:
http://gristmill.grist.org/skeptics
Everyone working with Java should take the time to read the Java coding conventions published by Sun: http://java.sun.com/docs/codeconv/html/CodeConvTOC.doc.html
Coding to the common conventions will ensure a consistency that greatly aids both the coder and others reading that code.
Anyone designing programs that involve more than one or two classes could benefit from familiarizing themselves with design patterns. An excellent introduction to this is Head First Design Patterns. Design patterns may or may not be appropriate for a given application, but learning about them and their usage will teach you to look at your program organization in a more critical manner from perspectives that you may not have considered at the outset.
Yes, EatDot() needs to be called before repaint() in your KeyAdapter to evaluate if a dot is eaten.
Also, your collision function in EatDot() needs to check the absolute value of the coordinate differences
if ((Math.abs(xcoords - dot[i].x) <= 5) && ((Math.abs(ycoords - dot[i].y) <=5)) && !dot[i].isEaten()) {
and lastly you need to reevaluate your offsets from xcoords and ycoords in your placement and drawing of the pacman arc. Offsetting -50 from x and y are causing your pacman to be drawn in the wrong location relative to xcoords and ycoords values you are checking against the dot coordinates.
You are close. You just need to check your relative coordinate and bounding box usage to fine tune it.
You might want to also use an ArrayList for the Dots instead of a fixed 1000 element array and remove a dot when it is eaten, rather than leaving it in an array and continuing to check it after it's long gone.
I told you in my post above. The slowMoveVertical() method needs to move all of the object up by "distance" and I would assume from the name that it should occur incrementally as a timed paint operation.
You may want to read through this tutorial article on animation in applets:
http://www.javaworld.com/javaworld/jw-03-1996/jw-03-animation.html
I am a final year student and thinking of a project topic to do. Any suggetion?
Track fish... some kind of fish... maybe gather and analyze some kind of stats on something they do...
That's really all that comes to mind.
Hi chaps,
im sort of continuing where Jezeral stopped - were in the same class here at uni.
Assuming i have a reasonably similar solution to Jez and iv got the thing displaying the time in readable format (im writing this at the moment!), how would i go about writing this time and date related data into a file and loading it back into the system?
I can do basic save/load methods fine but im not sure how to handle gregoriancalender data in these cases.
many thanks in advance,
Al
SimpleDateFormat has methods to format a date to a string and to parse a string to a date. If you are using a particular format, you can format the date before you write it into the file and parse it when you read it back out.
If you get the icon moving working as you like, you could also consider setting the cursor to that image while the new position is being selected with this method: http://java.sun.com/javase/6/docs/api/java/awt/Toolkit.html#createCustomCursor(java.awt.Image,%20java.awt.Point,%20java.lang.String)
So you retrieve the icon from the one button just like Black Box showed in his example. I'm not understanding what you want to do differently.
Because that is what you have for an increment statement i+=key.length
in your loop.
Parsing them into valid dates as masijade mentioned is really best, but if you have simple date strings like "12/01/2006", you could use the String split() function to put them in year-month-day form "20031201" for integer sorting
String date = "12/10/2006";
String[] datePieces = date.split("/");
String rebuiltDate = datePieces[2]+datePieces[0]+datePieces[1];
System.out.println(rebuiltDate);
If you have times in the string as well then it gets trickier and you would need to use regex parsing to create the sortable representation - at which point you would have just been better off using the date formatter in the first place...
You have moved ALL of your class code into the main() method. You cannot nest all of that into main. It needs to remain part of the class. Your main method is just a driver to create a Stopwatch object and then call the methods on that object.
And btnA2 is not displaying "pic"? Or are you expecting btnA1 to no longer show that pic as well?
Just to give the solution to everyone (we worked it out over IRC).
I think the getClass() method didn't really do what it was supposed to be doing. Instead using ClassName.class.getResource() did the job.Black Box
Glad you got it worked out there. getClass() works fine in our app context here, but as usual with varying application structures, you have to fiddle around a bit sometimes to get context issues resolved.
You can probably even ditch the URL variable and just use the original string path, since you're turning around and calling getPath on the URL in the getResource() call.
You don't want to put all of the class code in main. Main just needs to create a Stopwatch object and call the methods on it.
My bad, brackets problem... the Image returns a Image not an ImageIcon... I guess that raises the question as to whether I'm ment to be using ~Image or ImageIcon... Interesting...
That just depends on what else you are doing with it :) If a method needs an Image reference you can just call getImage() if you have an existing ImageIcon object.
the .getImage() isn't a functiuon thats assicated with this file type??
Sorry, mistype from hacking two different sources together
new ImageIcon(getClass().getResource(IMAGE_NOTBROADCAST_URL.getPath ())).getImage()
if "img" is an Image reference. If it's an ImageIcon, then you don't need the getImage() call;
Try
new ImageIcon( getClass().getResource(IMAGE_NOTBROADCAST_URL.getPath ())).getImage()
. You may need to alter the classpath as well.
Just what it says - you have no main() method defined.
Also, your class is called Counter, but it looks like you want this method public void Stopwatch()
to be a constructor? Or am I misunderstanding that?
Your IDE is most likely treating it's project root directory as the root context when it executes. If you are clicking on a jar in the dist folder, that is most likely the root context. Try dropping a copy of your images directory into the dist folder. If it runs fine then you'll know that is the issue.
We actually include our images folder on the classpath and use
getClass().getResource(imagePath)).getImage()
to load an image.
That's why the compiler gives you those handy messages when there are problems :)
What do they say?
A couple of other minor points:
You don't really need 7 elements in your array. You are only using six.
With a six element array, this entire count function
if (roll == 1)
countArray[1] = countArray[1] + 1;
else if (roll == 2)
countArray[2] = countArray[2] + 1;
else if (roll == 3)
countArray[3] = countArray[3] + 1;
else if (roll == 4)
countArray[4] = countArray[4] + 1;
else if (roll == 5)
countArray[5] = countArray[5] + 1;
else if (roll == 6)
countArray[6] = countArray[6] + 1;
reduces to
countArray[roll-1]++;
There a couple of other minor index changes you'll need to make in your output, but I think those will be pretty clear :)
Since your method already has the number of rolls, you're all set to calc the percentage. You do have to watch out for the integer division though or you'll get 0 for every one of them
(dCount[index]/(float)numRolls)*100f
You need to use a formatter to convert the Calendar instance to a desired date/time display format. Here is the simplest example
java.util.Calendar cal = java.util.Calendar.getInstance();
String date = java.text.SimpleDateFormat.getInstance().format(cal.getTime());
That uses the default "short" date-time format of SimpleDateFormat. There are many other variations that you can specify if you wish. Take a look at the SimpleDateFormat API and DateFormat:
http://java.sun.com/javase/6/docs/api/java/text/SimpleDateFormat.html
and this tutorial information
http://java.sun.com/docs/books/tutorial/i18n/format/dateintro.html
Erm, that method does not do anything at all and this declaration doesn't really make any sense
private slowMoveVertical balloon;
Your slowMoveVertical() needs to move all of the drawn objects up by a certain distance.
What are you using for logging currently? You might take a look at http://java.sun.com/javase/6/docs/api/java/util/logging/package-summary.html
or Log4J.
Where is the main method that you are executing? You only have one valid constructor (the other is commented out) and very little is initialized in that default constructor.
Date is actually deprecated and should be replaced with Calendar
java.util.Calendar now = java.util.Calendar.getInstance();
String currentTime= java.text.SimpleDateFormat.getInstance().format(now.getTime());
Send it as a gift to your foe. He will be happy that hes getting "something" from his "enemy". He will then stop hating you :D
So a "foe" would be happy to receive a broken item and stop hating you? Are you high?
JToggleButton[][] buttons = new JToggleButton[5][5];
That just declares the type and dimensions. You still have to set each element equal to a new instance of JToggleButton.
Well, is there any body to the method? Does it have a valid return statement? Somewhere you have an incomplete statement or block and the compiler cannot parse it as valid.
And that is a method you are trying to declare or is it a variable you are declaring? Either way it looks to be an invalid statement. Is that the entire line of code?
You can use JOptionPane.showMessageDialog() with a message type of WARNING_MESSAGE:
http://java.sun.com/javase/6/docs/api/javax/swing/JOptionPane.html#showMessageDialog(java.awt.Component,%20java.lang.Object,%20java.lang.String,%20int)
Glad it worked out for you :)
Yes, that is the code I was asking about, but you have commented out all of the relevant initializations.
The static class method will only be able to access static class variables or a parameter that is passed to it. So you can either declare the OutputFile variable static at the class level and initialize it in main(), or you can alter the method signature to take that OutputFile as a parameter and use it within the method.
I would actually recommend altering the method signature and passing the OutputFile as a parameter.
Edit: Also, you don't need to close the file in that method based on "closeLoop" - just let the method write the information to the file that is passed to the method. The main() program can close the file after you are finished with it.
there we go. What is the parameter or way to get the detailed line method to recognize the outputfile summary report.
Ok, that is not the code I was referring to. You posted the OutputFile class, but your questions relate to how you are using it in another program. That is the code I was asking about, because your question is not clear.
You may be able to get the 0-255 grayscale value like this
int grayVal = ((int) sample2[0]) & 0xff;
(I haven't worked with it myself, but some reading suggests that might work for you.)
You will need to start this on your own. If you run into difficulties, post the code you are having problems with, the exact error messages, and specific questions about the problem.
When I put it in main the method just below the initialzation of the variables the detailed line method gives the error cannot find symbol. There appears to be a need to reference or call the file in the detailedline method. What would be a better way.
I'm not following your description of the problem. If you would post your code (use the [ code] tags around it please), it would certainly help.
You would use the inputs to construct a GregorianCalendar instance that represents the date and time they entered. Keep in mind, you would still have to write that info into your file and if comparing to another appointment, read the info from file to construct the Calendar instance that represents the other appointment.
Do you have a class called OutputFile? The code he posted was using some wrapper class called OutputFile - it's not a standard API class.
You don't need to have all of the separate variables in your program to use the GregorianCalendar. It encapsulates all of that in itself. You use it by setting the fields as needed, adding or subtracting various time increments, comparing different Calendar (date) instances, etc. Perhaps these examples will help a bit more:
http://www.exampledepot.com/egs/java.util/GetDateFromCalendar.html?l=rel
Working with the calendar can be a bit non-intuitive at first, as you probably see by now. Take the time to read through the API document for it, the methods available on it, and the tutorials you can find.
(Edit: I was referring to the original code you posted when I wrote this. Not the code above that you added in the mean time :) )
The HashMap just provides a mechanism to look up a frame reference by name (the string key assigned when it was registered). The showView() method just loops through all of the views in the map and sets all but the requested one to not be visible.
This was just a quick-and-dirty example of using a controller to mediate some of your component interactions. There may be a much more suitable arrangement for your interface and usage needs, but you would need to post some more specific information the app and it's organization.
Yes, you just move it up as indicated above. It would need to be declared static since the method that is writing to it is static and it is accessed in main. (That is not really a good way to code things, but the original poster decided to use everything statically)
Hibernate will work with H2 and McKoi as well, so you can still use an embedded database without a server installation.
For those images, you can store the path to it.
Agreed. I'd recommend that even with a database.
It depends on how you need to access the data, but I would imagine the simple file would suffice. You don't mention what the data is, but basically you have the equivalent of a single table. With file-based storage you will need to write the methods yourself if you want to query the data in any manner. If such queries are straightforward, such as just finding a couple entries based on simple criteria, you really don't need the database.
That said, if you expect to grow to have several other tables of information and will need to correlate information between them in a variety of ways, you should go ahead and start with a database.
McKoi and H2 are a couple of good open-source Java embedded databases (they don't need a separate installation on a server) if you decide you want to use the database.
Yes, moving your console app over to a Swing component isn't just a matter of stuffing the output into a message box. Message boxes don't work like the console at all. You will need to work with frames/panels and either arrays of components or custom 2D painting with mouse listeners.
It gets deep pretty quickly once you decide to move into GUI programming and as Black Box noted, you need to start at the beginning.
If you do go that route and get a bit of understanding of Swing under your belt, feel free to post back with questions on what components and techniques can be used to build your interface.
The weightx and weighty properties control how much each grid cell can grow or shrink in the x and y directions as the container is resized. If you want all cells to resize equally, you need to set that property to the same non-zero value, such as 1.0. The fill property will allow you to specify whether the component in that cell fills the horizontal or vertical space alloted, so in conjunction with the weight properties you can control how each component resizes within its grid cell.
You often don't necessarily want everything to grow the same amount. You may want text fields to get longer but not taller when the form is made larger. You may want all text fields to keep their size and have only the message or comment text area to grow to fill the larger space. Getting that behavior is a matter of balancing the weightx and weighty properties to let the components grow in the manner you desire.
Blank labels can be useful as spacers if you need some areas to remain fixed while other areas grow. The blank labels can be assigned a weight of 1.0 and this will cause them to take on all of the new space from a resize.
GridBagLayout is extremely flexible and allows for a very fine degree of control in how your layout behaves, but it does take some time and experimentation to get the behavior you want.
Personally, my recommendation on your …
It's not a matter of verifying a random change after it's done. Generate the random salary progression by starting with a base and adding a random raise to it. Assigning a series of random salaries to an employee makes little sense if an upward progression is desired (and I think most employees would agree that is the only acceptable progression :P )