Adding values to an int myPoints array
I have been struggling with this program for much longer than I should be. I am teaching myself java and I was wanting to try to knock out a few of the basics by reading in a file formatted like:
Looks to me that you have jumped into the deep end of the pool before trying out the shallow end. There's a lot here you are wanting to do, but you're not familiar with the basics before continuing into the intermediate functionality.
Start simple, then move to complex. The idea you have is right, but its implementation is incorrect. You have datatype mismatches here, and incorrect usage of object properties.
Here's what I suggest. Start without worrying about a visual rendering component. Drop all associations with gui components, and work it off of a command line app. The goal is to get the data from the file, and into an array or collection. Choose if the array should be primitive like a double, or an array of object such as Point. I'd suggest using a multidimensional primitive since that will kill two birds with one stone. Once you have the data in the array, then iterate it using a for or foreach style for syntax and just a tabular style output. When you have this data, then you can move into gui components.
Watch for your datatypes and property handling. myPoints isn't a datatype, so it cannot be instantiated, and points isn't defined as any datatype. Watch your scope as well, nested loops cannot use the same control variable (ie: i), since i will be altered in both the inner and outer loops. Use different variables for control (i, j are typically good options). I'd suggest using split on a simple space character, and then using trim on the strings provided.
When you can get the data into the array properly, then you can look at the gui aspect. I'd extend a JPanel directly and accept the data collection into the constructor OR give it a file to read itself.
If you don't follow the simple to complex approach when learning a language, you'll always end up in the situation of "its not working but I don't know what is wrong". This is why you need to get a solid understanding of each part one at a time in order to diagnose what is wrong. That way you can look at something and say "the file is correctly read and stored, but its not rendered on the panel properly" so that gives you a spot to debug instead of being unsure of what in particular isn't working.
|All times are GMT +1. The time now is 06:38 PM.|
Powered by vBulletin®
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.