|
You could try Observer/Observable, but it really kind of sucks.
|
# ? Apr 29, 2012 01:24 |
|
|
# ? May 10, 2024 11:52 |
|
The *Listener pattern is basically a hack around Java's lack of delegates. Essentially a delegate represents "a function with a particular signature", allowing you to pass functions around in a type-safe fashion. In Java you can achieve sort of the same thing by declaring a one-method interface, and passing around "functors" that implement that interface. It's an ugly and verbose hack, but it does achieve the same result.
|
# ? Apr 29, 2012 02:36 |
|
MEAT TREAT posted:On Linux systems, directories starting with a dot are hidden, maybe OS X is the same? carry on then posted:In Finder just hit CMD+Shift+G and type in ~/.netbeans, should take you right to it. Thank you! That cleared it right up. If I'm not actually using the GUI builder "drag-and-drop" aspect of Netbeans anymore, is there a better utility in which to write code?
|
# ? Apr 29, 2012 06:14 |
|
Hidden Under a Hat posted:Thank you! That cleared it right up. IntelliJ community edition
|
# ? Apr 29, 2012 15:39 |
|
Hanpan posted:Does Java have any kind of event handling / dispatching ala Actionscript 3? I know it doesn't have delegates so the C# system I was hoping to port over won't work. The only thing I can find on Google is the ActionListener interface, but that seems to be specifically for Swing? Never used Actionscript 3, but EventBus (javadoc) in Guava might suit your fancy.
|
# ? Apr 29, 2012 20:42 |
|
relatively simple question, but it is giving me fits. Trying to implement an array based deque, with addFront(x), addRear(x), removeFront(), removeRear(), size(), and isEmpty() methods. This is done with an array whose size is passed as an argument, and then front and rear variables that wrap around the array.code:
|
# ? Apr 30, 2012 00:10 |
|
Firstly, you are decrementing front after you take its modulus. Secondly, this code:
I assume is reversed.
|
# ? Apr 30, 2012 00:20 |
|
This one's killing me. I place a "customer" into a queue withcode:
code:
|
# ? Apr 30, 2012 04:25 |
|
Airconswitch posted:However, time is not properly assigned a value. What stupid mistake am I making here? Nothing looks wrong with the posted code, what do you see in the debugger when you step into the line? As an aside, Java classes are capitalized by convention.
|
# ? Apr 30, 2012 06:16 |
|
I'm having an issue running a piece of code from an applet. I have a method in a static class that reads a file and returns an object based on the contents of the file. However, I get a FileNotFound exception when testing the code within a JApplet.code:
Edit: Thanks baquerd Plank Walker fucked around with this message at 00:41 on May 2, 2012 |
# ? May 1, 2012 23:54 |
|
Plank Walker posted:I'm having an issue running a piece of code from an applet. I have a method in a static class that reads a file and returns an object based on the contents of the file. However, I get a FileNotFound exception when testing the code within a JApplet. Your applet does not run on your server, rather the client executes the applet and does not have a copy of the file. You need to access the file via a URL: http://stackoverflow.com/questions/574675/read-file-in-an-applet edit also this: http://docs.oracle.com/javase/tutorial/deployment/applet/appletExecutionEnv.html baquerd fucked around with this message at 00:11 on May 2, 2012 |
# ? May 2, 2012 00:09 |
|
If anyone's interested in Java certification, I'm looking for reviewers for this book. OCA Java SE7 Study Guide Earning the Oracle Certified Associate Java Programmer I Exam is an easy task only if you prepare for it in the focused manner. Your search for a hands-on and practical guide for the exam ends here. This book will hand-hold you while imparting you with necessary knowledge through a step-by-step process and will give you confidence to pass the exam. This book is primarily for entry level Java programmers or Students studying to become a Certified Oracle Java Associate, Java programmer I. To learn more about the whole review thing, check out this thread: http://forums.somethingawful.com/showthread.php?threadid=3463489&userid=0&perpage=40&pagenumber=1
|
# ? May 3, 2012 23:17 |
|
Ok, I give up. I cannot figure out how to paint a pixel I click on. I have googled for hours, and I keep finding ways to set it up, but the examples never make a call to paint(), they just set it up. I am probably just missing something, but I have no idea what to pass when it comes to calling paint(Graphics g); I mean obviously you pass a Graphics variable, but I ave no idea what I am suppose to set it to. I suppose this is what I get for just jumping into graphics.
|
# ? May 4, 2012 05:39 |
|
Suran37: You never explicitly call paint() on a Component- call repaint() and paint() will be called for you by the AWT/Swing event thread. How's this:code:
|
# ? May 4, 2012 05:53 |
|
How can I make an array take values input at the command line? For example typing "java Calc 1 2 3 4" into the console should make an array of [1,2,3,4].
|
# ? May 4, 2012 06:02 |
|
RADmadness: Use a Scanner attached to System.in. I guess finals week isn't over yet, hunh?
|
# ? May 4, 2012 06:05 |
|
It's not that simple. The program is tested by another program that I am not allowed to see. I cannot figure out how to let it input what it wants straight from the command line.
|
# ? May 4, 2012 06:21 |
|
It's right there in the loving main method's signaturecode:
|
# ? May 4, 2012 06:30 |
|
edit: beaten ^^^ Arguments made to the call to "java Calc" go in the args parameter of public static void main(String[] args), so if that's how you're doing it, the array is already made. That only works for starting the program; you can't do something like that if it's already running.
|
# ? May 4, 2012 06:30 |
|
Internet Janitor posted:Suran37: You never explicitly call paint() on a Component- call repaint() and paint() will be called for you by the AWT/Swing event thread. How's this: Thanks for explaining as the examples didn't have repaint() either. Anyway it still isn't working. I'm trying to copy an algorithm I saw in a different language to Java, but I may be in a little over my head. I'll take another stab at it tomorrow, and I'll post some code if I am still having troubles.
|
# ? May 4, 2012 07:13 |
|
How do I measure the pixel size of a String? Oracle's tutorial only gives a solution for the width, and saysquote:If this solution is insufficient, other text measurement APIs in the Java 2D™ software can return rectangular bounding boxes. These boxes account for the height of the specific text to be measured and for pixelization effects. e: oh, and to ask x not y: I'm trying to find the amount of space a String actually takes. So "...." will be something like 18x2 (obv depending on font). Malloc Voidstar fucked around with this message at 15:45 on May 4, 2012 |
# ? May 4, 2012 15:32 |
|
Aleksei Vasiliev posted:e: oh, and to ask x not y: I'm trying to find the amount of space a String actually takes. So "...." will be something like 18x2 (obv depending on font). public Rectangle2D getStringBounds(String str, Graphics context) in FontMetrics is probably what you want.
|
# ? May 4, 2012 16:01 |
|
If I recall correctly, getStringBounds doesn't take descenders into account, which can lead to some serious WTF moments.
|
# ? May 4, 2012 16:50 |
|
Internet Janitor posted:If I recall correctly, getStringBounds doesn't take descenders into account, which can lead to some serious WTF moments. That may be the case, but won't you have some line width anyway? Set to something like: getStringBounds("X").getHeight()*2? Or even user definable? I'm talking out of my rear end right now, as the last time I wrote a java application that had to paint what was going to a printer was 10 years ago, but if i'm not mistaken that's how I solved the issue.
|
# ? May 5, 2012 00:10 |
|
Trying to import a True TypeFace font file into a program and display it on a Frame, so that the font will appear for those who haven't got it installed on their operating system. Nothing fails or exceptions out, but it simply doesn't display text in the imported font on a Frame, and the imported font isn't listed in a call to the GraphicsEnvironment's "getAvailableFontFamilyNames()" method. In short, the second and third lines should be looking like the fourth line: Anyone willing to have a poke about and see what's going wrong? The font file itself is "frogger_.ttf" from here. It's sat within "FontImportTest\build\classes\fontimporttest\resources" folder. code:
|
# ? May 7, 2012 22:20 |
|
Is registerFont actually returning true?
|
# ? May 7, 2012 22:28 |
|
The problem is likely that code:
Also, your download link says the size of the Frogger font is 19kb, but the size of the downloader is 154kb and it wanted administrator access to my computer, which I, of course, didn't give. dafont.com looks like it has actually free fonts for various uses. I tested with a random font and using the correct font family name everything should work.
|
# ? May 7, 2012 23:28 |
|
What's a good book / set of online tutorials for learning Java if you already know how to program? I'm a college student who knows C, C++ and Python, how to write object oriented programming for the last two, and I've taken a Data Structures class in C++. My curriculum was more mathematics based, so I've never touched Java. I'm not particularly interested in taking a Java class in the other computer science track at my university, mainly because they'll be focusing on beginner stuff, but that could be a possibility. I'd like to learn Java (or C#, I guess) because it's the dominant language in the Real World, Android app development seems interesting, and I feel weird not knowing it when every other CS grad is fed with it.
|
# ? May 9, 2012 06:18 |
|
Devvo posted:What's a good book / set of online tutorials for learning Java if you already know how to program? While I cannot recommend you a good Java book (there are bazillions, just pick whatever has good reviews at amazon), I would recommend reading something like Clean Code. It'll help immensely regardless of the language of choice.
|
# ? May 9, 2012 07:15 |
|
Devvo posted:What's a good book / set of online tutorials for learning Java if you already know how to program? I can't speak to any particular text for learning the language, since I mostly learned it through osmosis, but I can't stress enough how important it is to pick good tools to work with it. I would recommend Eclipse, and get to know it well (and rebind the Content Assist key to 'escape'). One thing that many people don't grok about Java is that programming it effectively is, essentially, computer-aided programming: code:
Going back to what I said about books for teaching the language, I should amend that by saying that there are two books that are absolutely essential reading once you've got some footing with the language: Effective Java and Java Concurrency in Practice (the former being the most important IMO). These will give you clues on how to use Java well, but aren't exactly language books, per se. I think that Java itself is not terribly complex, but lends itself well to creating complexity (for better or worse) and hiding it behind abstracted interfaces. Doctor w-rw-rw- fucked around with this message at 07:46 on May 9, 2012 |
# ? May 9, 2012 07:40 |
|
Doctor w-rw-rw- posted:One thing that many people don't grok about Java is that programming it effectively is, essentially, computer-aided programming: IDEA is even smarter than Eclipse when it comes to autocompleting and programming aides http://blog.codeborne.com/2012/03/why-idea-is-better-than-eclipse.html
|
# ? May 9, 2012 08:12 |
|
pigdog posted:IDEA is even smarter than Eclipse when it comes to autocompleting and programming aides Not significantly smarter for me to pass on official ADT support for Eclipse, is what it boils down to for me. Doctor w-rw-rw- fucked around with this message at 08:34 on May 9, 2012 |
# ? May 9, 2012 08:32 |
|
Fair enough. IDEA does have some Android support even in the free edition, but I've no idea how it compares.
|
# ? May 9, 2012 09:06 |
|
pigdog posted:IDEA is even smarter than Eclipse when it comes to autocompleting and programming aides I'm trying to give IDEA a go at the moment and while stuff like that is really nice in it I just can't seem to get it to 'feel' right, if that makes sense.
|
# ? May 9, 2012 10:22 |
|
I recently received a Java project from a colleague that implemented a class diagram's relations with sets. By that I mean something like A -> B -> C means A will have a Set<B> and B a Set<C>. I'm wondering if there's a better implementation of it, because when I need to, say, get C from A I need to do 2 chained foreach, and I wonder if that's a good thing to do, since it could grow out of hand. Honest Thief fucked around with this message at 10:31 on May 9, 2012 |
# ? May 9, 2012 10:25 |
|
With the caveat of not knowing the context, it doesn't look wrong at all. Are you sure you need to use foreach loops rather than say a HashSet, or something like someInstanceOfA.getSomeKindaB(someParameter).getSomeKindOfC(someOtherParameter)?
|
# ? May 9, 2012 11:29 |
|
Honest Thief posted:I recently received a Java project from a colleague that implemented a class diagram's relations with sets. By that I mean something like A -> B -> C means A will have a Set<B> and B a Set<C>. And with WeakReferences, it could definitely grow out of hand in verbosity and error-checking. What kind of thing do you need to implement?
|
# ? May 9, 2012 17:10 |
|
The idea of the project was: we used USE and OCL expressions to define invariants and constraints for a certain model, then we were asked to implement those same constraints in Java; I should mention, the project is done and been delivered I simply had this nagging issue with it. Anyway, the model in case was for a football championship, and we added some simple constraints and methods; for example to get the eldest of the players with OCL it was done simply by running: "self.participation.team.age(self.birthDate)->max" The issue came up in java, where I had to basically do something like for(Participation p : this.participation) for(Team t : p.team) for(Player p:t.players) p.age .....yadda yadda.... due to the how the model was implemented Honest Thief fucked around with this message at 18:29 on May 9, 2012 |
# ? May 9, 2012 18:26 |
Blacknose posted:I'm trying to give IDEA a go at the moment and while stuff like that is really nice in it I just can't seem to get it to 'feel' right, if that makes sense. I was using Eclipse for about 4 years and recently switched to IDEA. I don't think I can go back to eclipse now, everything in IDEA is just way more intuitive.
|
|
# ? May 9, 2012 18:37 |
|
|
# ? May 10, 2024 11:52 |
|
Honest Thief posted:etc Well, seems reasonable to me, then. fletcher posted:I was using Eclipse for about 4 years and recently switched to IDEA. I don't think I can go back to eclipse now, everything in IDEA is just way more intuitive.
|
# ? May 9, 2012 18:39 |