Adam Nadeau

Greenhorn
+ Follow
since Aug 07, 2015
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 Adam Nadeau

As I learned late last night, the magic bullet is getResourceAsStream(). The getResource() method was failing because the path only exists in a single .jar file, not in the file system, so the OS can't resolve it. I wrapped the right code in a Scanner and everything works now.
4 years ago
Okay, I opened the .jar file and found three folders in it: "mingyavalleydraft", which holds all of the class files, "META-INF" with the MANIFEST.MF file, and "data", which has my playerlist.txt file in it. I was assuming that the .jar file is the root of the package, which means that /data/playerlist.txt would or should be a valid reference, but clearly there's an error in this logic. What bothers me most is that the class.getResource() call works fine from the IDE, but the whole program fails when I run the .jar file. In reality, I can live with the JFileChooser call; I only need to open one file, and I'll only be running the app once (for now). I just figured that the automatic retrieval would save me the steps of digging through my hard drive to get the file (it's buried pretty deep in the directory tree), especially while I'm testing things and running the code over and over again. I may try a few more things to see if I can make it work, but I have more important logic to tweak in the next two days, so I'll probably just end up putting on the back burner until I upgrade the app for next year. Thanks for helping.
4 years ago
Thanks, Paul; you didn't have to write code for me. Anyhow, I think I've figured out my problem. "Apple Color Emoji" is a proprietary Apple font that is not a vector font, but rather a collection of images disguised as a font. If I switch the font to "Segoe UI Emoji" and run under Windows, I get a (considerably less interesting) clock as I was expecting at the beginning. The difference is that the Windows font is a standard grayscale vector font, which makes it universally usable (such as by Java or a web browser, etc.). Luckily, I have also determined today that I will be running the app in Windows, so I can just stick with that. Thanks again for your help.
4 years ago
Honestly, I stuck the file in a folder ("data") under the "src" folder in the NetBeans project folder assuming that NetBeans would include the file in the .jar file automatically. The fact that the new code worked when run from the IDE gave me some hope for a minute there. Is there a process that needs to be followed to make NetBeans include the file in the build?
4 years ago
I've built a custom fantasy football draft application that I will be using in a few days. I have all of the logic working and the GUI close to pinned down, so I thought I would try to make life easier by packaging the player data file with the program. I changed this code:

to this:

and it worked great. Until I closed NetBeans and tried to run the .jar file directly. The .jar file runs fine with the JFileChooser code (I tested it on two computers, Mac and Windows). With the getResource code, the app fails to launch completely. In NetBeans, my project tree shows
MingyaValleyDraft
    v Source Packages
        v data
            playerlist.txt
        > mingyavalleydraft
    >Libraries
Are there additional steps that the IDE takes to include the file that aren't necessarily taken when the .jar is built?
4 years ago
This seems like the most accurate way, but I'll have to try it later. I only have a few days left to make this useful, and I'm still testing and tweaking the GUI to make sure it works on whichever display I'm using at run time (could be anything from a 15" monitor to a 47" TV). Thanks for the info.
4 years ago
I never actually considered that "UTF-8" might be a valid font. Anyhow, I tried that, then tried UTF-16, but still nothing. Thanks for the idea.
4 years ago
I'm trying to use the Unicode alarm clock symbol (23F0) in a project I've been building. I have a grid of JLabels and JPanels that works correctly, and the left column of the grid is a column of JLabels that are supposed to "hand off" the alarm clock as a method is called; one should have the alarm clock while the rest display a single hyphen (-). In all the reading I've done on this problem, I've been led to the conclusion that I had to set the font correctly in order for the symbol to display. I opened TextEdit (Apple's Notepad, essentially), opened the special character box, searched the Unicode number, found the clock, inserted it into a txt file, and looked at the font parameters. TextEdit shows the character in the Font "Apple Color Emoji" with "Regular" as the only style option, and a range of font sizes available, from which I chose 18 as probably appropriate. Here are the pertinent lines of code from my project:


I can see that the code is working, because every time the code is called, I get nothing where the clock is supposed to be. No strange symbols, no formatting anomalies, just an empty space. Does anyone have any idea why I can't make this single character appear in my app? I chose the Unicode character because it was supposed to be a matter of changing a single String instead of creating and using an Image; I need to have this thing done in a few days and I still have more important logic to tweak before then. I'm not even a fan of the way I have the Font called out as it is because I'm not sure if I'm going to be running this under Windows or Mac when the time comes (another reason I want to avoid adding an Image file to the problem). For what it's worth, the other all of the other text throughout the grid also has a font size of 18 and everything fits very well. Thanks for reading.
4 years ago
I've got this little program I wrote as a homework assignment, and I thought I'd take some functional liberties with it. The purpose is to take four test scores and four decimals and return the weighted average. I figured I'd add a little flair with an error message if the weights didn't add to 1, and just decided to do it by swapping out JLabels. What's odd is that each result (the average or the error) will work properly once, but it will never update again. Could somebody give me some insight into why each swap would only work once? Here's the entire code (it's all in one file on purpose; assignment requirements):

EDIT: Nevermind, I just realized what I did. I originally wrote the program with everything in the window JPanel, but then added the resultPanel to the gui frame afterwards, and didn't realize I was only repainting the window.


Thanks for looking.
4 years ago
Wait a minute, I just realized you were referring to my reply, not my original post. That didn't come from a tutorial, that was gleaned from reading through posts at other forums. I know that Java has enough built-in functionality to accomplish most tasks, but it seems too many people like to use stock classes as suggestions rather than their intended purposes.
4 years ago
I didn't actually read anything that explicitly suggested that, it was an idea that occurred to me in the absence of a defined list of JButton customization methods. The Java tutorials from Oracle (and most others I've seen) have been virtually useless in the area between beginner and career programmer. They show you how to make one and give a couple examples that demonstrate different use cases. Outside of that, there is just the page that defines the object and gives a short list of defined methods and dozens of links for inheritance; I don't have time to fish through that much information hoping to stumble upon the line that fits my goals. However, I did find yesterday some examples of ways to manipulate JButtons, so I will go that route instead of trying to create a host of event handlers for JLabels.
4 years ago
I guess that answers my question; I will look into recoding as a Map. Thanks everyone.
4 years ago

Bear Bibeault wrote:Welcome to the Ranch.

Sounds to me like a Map with your generated ids as keys.

P.S. I suggest using paragraphs in posts. Big blocks of text are hard to read.



I had expected my question to be much shorter, but I lost track as I added information. Thanks for the welcome, though!

As for the Map, I was looking into that (specifically TreeMap as HashMap "doesn't guarantee" sort order), but each ID is going to be effectively random. The original file is contrived from publicly available data and sorted in an unpredictable way, but IDs will be assigned in the order in which they appear in the file. In a search or filter capacity, is it possible to traverse the map without an ID? For example, is it possible to return every Map entry that matches Player.lastName or Player.position? Then, if I can display Players like that, would it then be possible to extract and pass the ID to remove a Player from the Map?

I realize some of these questions seem sophomoric, but I have yet to see an explanation of the Map class that didn't include reinventing the wheel; literally, I haven't seen an example that didn't use "extends" and a half dozen custom methods just to bend the Map class to the coder's will.

By the way, thanks for answering so quickly.
4 years ago
There is no shortage of collection classes in Java, and that has left me spending more time deciding how to approach my project than actually coding it. The bottom line is, I'm trying to throw together a fantasy football draft application (for my use, not for distribution) and I can't decide on the best way of handling the data portion of the program. I need to read in 700-800 Player objects from a file, which are essentially random little groups of data (firstName, lastName, position, team); there are no unique identifiers in this situation. Then, I have to remove them one by one as they are drafted, which changes all of the original index numbers. I had actually written code to read the file into an ArrayList, but that becomes cumbersome as the players are removed from the list (drafted) as the index numbers constantly change. My current thought is to read the file into a regular array and set up a separate ArrayList<Integer> to use as an iterating tool; basically, assign each Player Object an integer ID number as it is created and control access to the array through loops over the separate ArrayList. I'm thinking that this way, each ID number will always correspond to the proper array index, and the ID ArrayList will only refer to available players. Anyhow, I could really use some informed opinions of the best/easiest way to go about this. This little project (which has to be done in four weeks, before the start of football season) is my personal foray into learning Java. With that in mind, I'm not asking anyone to write code for me (I'll learn faster by trying and failing), but I am asking that you don't give me any overly technical answers (I only recognize a few built-in classes and methods at this point. Thank you in advance to anyone who can give me some advice.
4 years ago