Simon Hunt

Greenhorn
+ Follow
since Jul 17, 2006
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Simon Hunt

Henry Wong wrote:Nope. No irritation whatsoever. It is just a bunch of hints phrased in a form of a question. Pretty common technique for me.... And trust me, it takes a *LOT* of effort to get me irritated....



All's good then. It just goes to show how tricky conversations are without voice tone and body-language cues.

Many thanks for leading me to the answers. I admit freely to thinking "Just give me the damn fish!", but the question phrased hints really did work and it really is the best way.
14 years ago
Gentlemen

Ulf - many thanks for the suggestion, but I'm afraid it causes the program to fail in both the IDE (Netbeans) and in the .jar. Curiously enough "src/solowarforedadhopponent/resources/MasteryCardData.esd" works just as well in the IDE as "src\\solowarforedadhopponent\\resources\\MasteryCardData.esd". As I said in my last post, I really don't understand the \\ vs / thing, but I hope it's not key.

Henry - it seems from your tone that you're finding this exchange irritating, for which I apologise, but the reason I'm posting to this forum is that I'm very much a Java beginner despite having joined this forum some years ago. I'm a hobbyist programmer, and I only usually get to programming about once a year, and it usually involves me largely re-learning Java from scratch (I use "Head First Java" mainly because it's fun).

Henry Wong wrote: First of all, why do you absolutely need the readLine() method? Are you saying that you can't parse it, if the BufferedReader class isn't available?

I'm saying I don't know how to parse it if the BufferedReader class isn't available. I'm sure that there are plenty of other ways of parsing a file I don't know about. During my scouring of the API I found a bunch of bit-wise methods in the getResourceAsStream section, so I know that's possible to do it bit-wise, but that seems a crazy way to tackle a .csv file; the readLine() method gives me a line at a time as a string which I know how to manipulate satisfactorily.

Essentially I've written some code to parse the .csv file which works fine, and re-writing it to solve what I perceive (albeit probably wrongly) as a path issue looks like tail wagging dog. That said, there are probably more elegant ways of doing this I don't know about as well, however I'm relying on a code segment from the "Head First Java" book, which only mentions this way of handling text files, so it's the only method I know.

Here's the full code section (I was avoiding posting this because it's long but I think the time has come) so you can see what I'm up to:
I've left in all the ideas I've tried and failed with, as comments, to avoid re-treading the same ground; happily it also allows you to see what I've tried too.

Henry Wong wrote:Second, why do you need a FileReader ? Are you saying that you can't get a BufferedReader without a FileReader ?

I'm really not asserting anything. It just appears from the section of the book and the code examples that a BufferedReader takes a FileReader as a constructor argument.
*looks at API*
The API suggests I simply need a Reader of which BufferedReader, CharArrayReader, FilterReader, InputStreamReader, PipedReader, StringReader are all sub-classes. It's interesting that FileReader is not on that list.

However, InputStreamReader looks promising...

I'll try this:
This works inside the IDE fine... but not in the .jar

Okay Simon, don't panic yet. Try "resources/MasteryCardData.esd"
This works inside the IDE fine... AND AS A .jar

Yes! He can be taught!

Many Thanks Henry
p.s. I still don't know why the IDE takes \\ but the jar only likes /?


14 years ago
Dear Henry

Many thanks for the initial clues, but I'm still struggling.


I'm not sure what you mean by the getResourceXXX() methods. When I look at the Class class in the API it only lists two similar methods:
1. getResource(String name) which returns a URL object.
To test this I put a "test print" line into my code
which gives something that looks correct but doesn't work - even if I make the string "resources\\MasteryCardData.esd". (Not sure about \\ and / either - using \\ inserts %5c into the string in this case)

2. getResourceAsStream(String name) returns an InputStream object which doesn't have a readLine() method which I need to parse my csv file.

My problem seems to be that ultimately I need a File object to pass to my FileReader to pass to my BufferedReader for that.



Just in case it's relevant, here's the code that follows the file open:


Many Thanks for any additional clues.
14 years ago
Sorry to ask such a basic question, but I have a simple app. reading data from a text file I have put in the src directory resources section as detailed below.



This works fine when running the project from within my IDE. However, when I build the project and try and run it from the .jar the program fails to find the file (I can see the error when I run it from the command line, because I've put the code line I detailed above within an appropriate try - catch block and it throws a file not found error). I've tried editing the Path but nothing seems to work, even though I can see the file within the .jar using winzip. There are also two other (empty) resources folders within the .jar, one at the top level and one below the level I've stored the file at (i.e. within resources!), however I chose the mid level one because all the other resources like .jpg images are there and the program seems to find them without trouble. I thought, just removing the src\\ ought to do the trick because the path within the .jar is solowarforedadhopponent\resources\MasteryCardData.esd, but this stops the program functioning both within the IDE and as a .jar.

So, my question is this: Where should this data file actually go and how can I refer to the file so that the program runs correctly both inside the IDE and as a .jar?

References to other threads, articles and tutorials all welcome.

Many Thanks
14 years ago
Thanks for the answers so far. I realise that my original post wasn't terribly clear. I'm talking about manipulating the records for about 1400 students, and the records are very large - everything from academic tracking through their timetable to their date of birth and home address.

Does the larger dataset make a difference?

Thanks

Simon*
I am a school teacher who spends a lot of his time manipulating pupil data in Excel. I've already had an excellent experience with HF Java, and am now happily programming little apps, so I know the HF style really works (in fact it's something I try to emulate in my teaching).

I've read the sample first chapter and although it is obviously very much sandbox level, SQL seems clunky (especially data entry) compared with Excel and a little data validation.

So, I'm wondering why I might benefit from learning SQL (I'm pretty sure I will - I'm just wondering why!). Where's the power in it over Excel? What kind of things will I learn to do in HF SQL that I can't do with Excel and a little VB? I'm sure there is a way of getting my Excel data into a SQL database should I want to, because I get a warning that a SQL statement is being run each time I open a mailmerge document that uses my Excel lists. I'm interested in why I should bother.

Thanks

Simon*
[ October 16, 2007: Message edited by: Bear Bibeault ]
Thanks Ilja

I'll check this out and return with any questions!

Cheers

Simon*
17 years ago
This post is ancient history, but I'd like to log my belated thanks to Craig. I was also having problems cracking this one, but I cut and pasted Craig's code, ran it and finally annotated it until I knew what was going on.

Finally (it took about three hours ) the penny dropped... the listener is the PANEL in which the polygons are drawn, not the polygons themselves. Once the panel says it's clicked THEN you check to see if it's inside a polygon. :") It ALWAYS seems embarrassingly obvious once you understand...

Anyhow, just to let you know that your help is still bearing fruit even 2 years later!



Simon*
17 years ago
Just to say (a very belated) thanks for the replies. I'm afraid that my programming only ever happens very sporadically (i.e. out of term time when I get a break from marking), so this is the first time I've looked at it since the summer.

Michael - Am I right in thinking that

Is actually allowing me access to the original "frame" variable? I'll try this out on the next panel class I write. Thanks!

Ilja - I'm now working on a slightly different (but related) app. This one has lots of little panel objects as you suggest. However, my understanding of generating events is too weak currently to implement your

"It then could fire an event to all panels listening (or several events, one for each changed value), and the panels could update their GUI elements accordingly.]"

idea. Are there any sandbox references you could suggest (or even a code snippet if it's reasonably simple)?

I've actually recently gone over to passing the frame variable to the panel objects, which allows all the control code to be in the correct place - each button's listener does it's own little bit, as Ilja suggested, rather than the large ugly listener class you saw last time. This also seems to work fine.



Simon*
[ January 07, 2007: Message edited by: Simon Hunt ]
17 years ago
I recently programmed my first Java app, which is a utility for a game (the .jar is here: http://www.h3rne.dircon.co.uk/AVT/AVTTargetTracker.htm).

The GUI consists of a JFrame into which I've placed a "Board" panel and an "Interface" panel. The interface panel has a series of sub-panels showing various bits of information, one of which has the input elements -some text boxes, spinners and a button.

The individual GUI elements are all separate objects extending JPanel. However, whereas I can add the textboxes and spinners to the input panel inside its own code, the button has to be added at the same level as the creation of the Jpanel in order for the actionListener to be able to repaint it using an inner class (it needs access to the "frame" variable). This seems clunky and very non-OO - I'd like to be adding the button along with all the other elements in that panel. Is there a better solution?


here I am adding the button to a panel, which I then add to the input panel - all the other elements on the input panel that do not need actionListeners are added when the inputPanel is created - see below

So really it's this block of code above, between this and the provious comment that "feels", from an OO point of view, that it belongs elsewhere.

The clunkiness is compounded by the fact that I've had to add a whole raft of getters for the references to the textboxes and spinners in order to update the values in the actionListener.


And the input panel class

All the variables and getters below were a work around to extract the information to the actionListener level. However, because repaint needs the frame variable, and there doesn't seem a way of having the button on this level where I think it belongs

That's the end of the work around


The question of how the repaint method can be empty can wait for another time!

Thanks

Simon*
[ September 15, 2006: Message edited by: Simon Hunt ]
17 years ago
Dear Earnest

Just a quick "thank you". This post solved an embarassingly simple problem I was having with trying to output a group of objects to a Jpanel, whilst trying to keep their graphics behaviour inside the objects.

The problem: I was only able to see one object at a time (the last one). This post finally got me to realise that I needed to be painting them all on the _same_ panel. :roll:

Cheers!

Simon*
17 years ago