Zaphod42 posted:The problem is that you're extending Application in the last one, not the others. That's creating a new thread, which then invokes the start method. But you've also got a main method? I'm pretty sure that's wrong, and that's what's causing all your issues. In my defense, ALL of the JavaFX examples have main inside the main Application. This is how Oracle says to do it (http://docs.oracle.com/javase/8/javafx/get-started-tutorial/hello_world.htm). No matter the case, it still doesn't work after I remove main: code:
code:
|
|
# ? Sep 3, 2015 22:15 |
|
|
# ? Jun 13, 2024 03:03 |
|
Jo posted:In my defense, ALL of the JavaFX examples have main inside the main Application. This is how Oracle says to do it (http://docs.oracle.com/javase/8/javafx/get-started-tutorial/hello_world.htm). No, you're misunderstanding. Its not just a matter of having main inside application. Its a matter of having the code that handles image manipulation INSIDE the main(). You can't do that. You can have a main inside it or external to it, or not even have one at all. Sorry if I was confusing by saying that. You don't need main at all with an application class, you can invoke it as an application and java knows what to call or there's a default main() or whatever. But you have to do the javafx calls from inside the javafx thread if you're starting an application, not from within your main. You have to invoke the application and let it call start() on its own, and THEN you're allowed to do image manipulation. Following that link shows the following code code:
When I google "javafx image manipulation" I get: https://docs.oracle.com/javafx/2/image_ops/jfxpub-image_ops.htm Which has several examples, all of which have the code in the start() method and have the main method invoke the application, exactly like I told you to do. None of them do image manipulation IN the main() method. Zaphod42 fucked around with this message at 22:31 on Sep 3, 2015 |
# ? Sep 3, 2015 22:22 |
|
Jo posted:No matter the case, it still doesn't work after I remove main: What? Didn't you say on the last page that this worked fine for you? code:
In which case that's my bad, looks like you have to have an application to invoke JavaFX methods, hence the graphics not initialized problem. If you're trying to run it without any GUI, then just do exactly like what Volguus posted. Or use a simpler image manipulation library and not a full window graphics library, yeah. But then you probably don't need JavaFX. You said before you kinda wanted it with GUI sometimes but not with GUI other times? Zaphod42 fucked around with this message at 22:33 on Sep 3, 2015 |
# ? Sep 3, 2015 22:30 |
Zaphod42 posted:What? Didn't you say on the last page that this worked fine for you? Emphasis mine. Yes. I had to remove just the extends Application part to get a new exception. With extends Application I get a GUI (or an exception if I'm on a headless box), and it automatically spawns the GUI even if I do it outside of start(). Without extends Application I get the exception above. Unfortunately, It turns out it's not possible to use JavaFX Image without a GUI, as I found just now: https://bugs.openjdk.java.net/browse/JDK-8093075 Looks like if I want a headless and GUI application I have to use two different Image classes. EDIT: Thank you both for the input, though. Wish the outcome could have been better. EDIT EDIT: \/\/ Jo fucked around with this message at 22:59 on Sep 3, 2015 |
|
# ? Sep 3, 2015 22:48 |
|
Jo posted:Emphasis mine. Yeah that's pretty much exactly what I said in my last post Easiest would probably be to have a image manipulation class using some library that just does the image manipulation, then if you want headless you just invoke those from command line and if you want GUI then you can create a JavaFX application (or a Swing window or whatever) and then call the image manipulation class from there. Its a little messy since you're using two different libraries but with each class only using one or the other that's pretty simple, and then you're still using the same exact image manipulation code in both the headless and GUI implementations so you don't have to worry about fixing something twice or the results being different.
|
# ? Sep 3, 2015 22:56 |
|
How can I have an appender write to a file as well as stdout? Write now I've got two appenders logging to different files, but I'd also like to see their output in stdout code:
|
# ? Sep 4, 2015 07:12 |
|
Additivity true
|
# ? Sep 4, 2015 07:14 |
|
thanks
|
# ? Sep 4, 2015 08:04 |
|
Yeah Log4j is the poo poo, it can do pretty much whatever you want. Additivity true means when you call a log at that level, you also call the log on the parent levels above (and up until you hit additivity = false at some point or the root) Additivity false means only trigger the one level.
|
# ? Sep 4, 2015 16:08 |
|
thanks for the explanation, that makes sense to me now
|
# ? Sep 4, 2015 23:20 |
How I wish they cold come up with normal names for things, like "propagate" or something.
|
|
# ? Sep 5, 2015 00:31 |
|
Just FYI (not really that important), but log4j's successor is nowadays logback. I've been using logback in a fair amount of projects for a few years and is quite good. Haven't seen anything yet that it cannot do (plus it has slf4j integration out of the box), and it has once nice feature that I don't remember log4j having: by default it loads logback-test.xml for configuration, which makes it really handy for unit testing. Have logback.xml in the main/resources folder for normal running, and have logback-test.xml in test/resources to be loaded only for the unit tests. As for usage, via slf4j everything is just like before, not a line of code to change ....
|
# ? Sep 5, 2015 01:30 |
|
Doesn't look very good compared to log4j2 though.
|
# ? Sep 5, 2015 03:03 |
|
working with java7 and trying to call an anonymous function inside the main class to load test data. this is mostly just an experiment. first: how is this code below not working? nothing is loading, while if i were to call the load method normally from a separate java class from main there's no issue. second: when is it actually a good idea to use anonymous classes and functions like this? all i know is that the class is supposed to hide code a little better, and that the anonymous function is immediately called just once. i guess i should also ask if this is used at all in java 8, or what's the practice there? lambda functions look cool and i'll be playing with them soon.code:
edit2: of course i figure it out in a few ... code:
pepito sanchez fucked around with this message at 20:07 on Sep 7, 2015 |
# ? Sep 7, 2015 19:58 |
|
You typically wouldn't want to do something like this. If you want to remove a block of code from the flow of your function, you'd do that in a private method of the same class. If you needed it to be accessible by other classes, you could make an appropriately named class with public static methods. (This is sometimes considered an antipattern, but is frequently done anyway.) Anonymous classes (and lambdas, in Java 8, which actually are anonymous classes) are mostly used when you have a method that accepts an interface, a need to call this method inline, and you don't want to bother creating a full class to do work. Ususally something like: Java code:
Java code:
|
# ? Sep 7, 2015 21:10 |
|
Gravity Pike posted:In Java 8, this becomes a bit less unwieldy: And how you'd actually write the above in Java 8: Java code:
|
# ? Sep 7, 2015 21:15 |
|
thank you. it sucks because we're limited to using java 7. lambda expressions just seem very interesting, but i'll make do. i don't want to seem like i'm being fancy or clever for no real gain. i suppose a lot might come down to design decision and a need for these things.
|
# ? Sep 7, 2015 21:21 |
|
The Laplace Demon posted:And how you'd actually write the above in Java 8: My company just upgraded to Java 7. Now I want them to upgrade to 8 because this involves a good portion of what I deal with.
|
# ? Sep 7, 2015 21:40 |
|
Is there anyway to do something like this:code:
Just curious if there's a way to instantiate from a generic type like that.
|
# ? Sep 8, 2015 16:40 |
|
emanresu tnuocca posted:Is there anyway to do something like this: Is it because you wrote T in the declaration but K in the method? e: Looks like it wouldn't work even if you did. From what I can see (like http://stackoverflow.com/a/1090488), you could pass the class object itself on construction and store it in your generic class, then call newInstance() on it when you need a new particle. carry on then fucked around with this message at 16:48 on Sep 8, 2015 |
# ? Sep 8, 2015 16:43 |
|
carry on then posted:Is it because you wrote T in the declaration but K in the method? Thanks. Well it looks like if I do that I'll only be able to use the default constructor. Which I guess could still work.
|
# ? Sep 8, 2015 17:18 |
|
emanresu tnuocca posted:Thanks. Well it looks like if I do that I'll only be able to use the default constructor. Which I guess could still work. You can use some fancy reflection shenanigans to do other constructors too, but it makes it harder to be generic. class.getConstructor(String.class).newInstance("String Parameter");
|
# ? Sep 8, 2015 18:03 |
|
I've started helping out with a local high school robotics team, and I'd like to learn Java. Can anyone recommend some resources for someone starting out? Most of the programming I've done has been in dead languages like FORTH and various BASICs. Currently, I use SQL and VBA regularly to perform data analysis for my job.
|
# ? Sep 9, 2015 00:14 |
|
The official Java trails are always recommended https://docs.oracle.com/javase/tutorial/ Just go through them in order - you might want to skip Generics at first (and maybe Annotations) until you have a handle on Java in general, it's powerful but I found it pretty confusing when I was starting out. More professional people may disagree though!
|
# ? Sep 9, 2015 00:55 |
|
Perfect, thank you. I'm totally happy with dry, technical text. When I googled around, I mostly found pay stuff.
|
# ? Sep 9, 2015 01:35 |
|
You might want to check out Udemy for some of their free content on Java. They have been really good with a lot of their intro courses I have checked out.
|
# ? Sep 9, 2015 02:58 |
|
baka kaba posted:The official Java trails are always recommended I agree with you. Generics are cool, but you should have a firm grasp on typing first. Annotations can be skipped for quite a while as it isn't until you get into frameworks were they start to shine.
|
# ? Sep 9, 2015 14:34 |
|
emanresu tnuocca posted:Is there anyway to do something like this: Java 8 lets you skip all the reflection, if you make ParticleEmitter an interface (or just use Supplier) code:
|
# ? Sep 10, 2015 02:58 |
|
I'm having trouble getting my program to loop properly. The "q" used for ending the input is staying in the buffer and interfering with the yes/no prompt. I'm relatively new to Java and programming in general, so is there some buffer clearing method I'm not aware of that would fix this? I apologize if my code is sloppy.quote:public static void main()
|
# ? Sep 13, 2015 20:09 |
|
Jocoserious posted:I'm having trouble getting my program to loop properly. The "q" used for ending the input is staying in the buffer and interfering with the yes/no prompt. I'm relatively new to Java and programming in general, so is there some buffer clearing method I'm not aware of that would fix this? I apologize if my code is sloppy. then straight after the while(again) loop add a call to read in the q so that its clear for the y/n
|
# ? Sep 13, 2015 20:17 |
|
TheresaJayne posted:then straight after the while(again) loop add a call to read in the q so that its clear for the y/n Of course, can't believe I didn't think of that. Thanks.
|
# ? Sep 13, 2015 20:31 |
|
To expand on what TheresaJayne said, whats happening is when you call while (in.hasNextInt()){} it keeps calling it while hasNextInt() is true. When the cursor on the line gets to where the next letter would be q, hasNextInt() returns false, so you stop. But the input reader is still on the same line, still with its cursor before the q. So next time you call read, it gives you q. Just simply call in.next(); on its own after you finish the while loop, don't even bother to save the results as a variable. That way the reader cursor gets moved to the next line, and then when you call in.next(); again, you'll get something after the q. A cleaner way to do it would be instead of reading character by character, get yourself a BufferedReader and read each line at a time from the console. Then you can break down the lines with string manipulation if you need to, but it makes it easier to keep track of where the cursor is; just deal with lines of text at a time. Nothing wrong per se about doing it the way you are though, for this application anyways.
|
# ? Sep 13, 2015 20:33 |
|
Zaphod42 posted:Just simply call in.next(); on its own after you finish the while loop This is exactly what I did. It never occurred to me to read the next character just to get it out of the way. Thanks again for the explanation.
|
# ? Sep 13, 2015 20:40 |
|
I making a Caesar Cipher for schoolwork, and I am trying to modify it to take lowercase letters, but my arithmetic seems to be failing me. The cipher subtracts 'A' in Unicode, and displays the number, however when I do this with 'a' I get an out of bounds exception, which only seems to happen when I have a space. Why?code:
|
# ? Sep 15, 2015 18:20 |
|
I am probably missing point but why not just use Character.touppercase() ?
|
# ? Sep 15, 2015 18:41 |
|
emanresu tnuocca posted:I am probably missing point but why not just use Character.touppercase() ? I can try it, the thought never occured to me. EDIT: This works but I would prefer to know why my code wont work. Modulo16 fucked around with this message at 18:57 on Sep 15, 2015 |
# ? Sep 15, 2015 18:47 |
|
Uhm yeah I was also a little confused but looking at the table: http://unicode-table.com/en/ Unicode A = '65', unicode 'a' - '97', the difference is 32, so 'a' - 'A' != 'A', looks like you need to do 'smallCaps' - 32 = 'largeCap'. Edit: ('SmallCharacter' - (a - A)) = LargeCaps Edit: yeah this works code:
emanresu tnuocca fucked around with this message at 19:35 on Sep 15, 2015 |
# ? Sep 15, 2015 19:16 |
|
^^^ That's an issue for reals, but also:Frank Viola posted:I making a Caesar Cipher for schoolwork, and I am trying to modify it to take lowercase letters, but my arithmetic seems to be failing me. The cipher subtracts 'A' in Unicode, and displays the number, however when I do this with 'a' I get an out of bounds exception, which only seems to happen when I have a space. Why? Your error message should tell you exactly which line it's failing on, and the type of Exception you get is a clue too. I'm guessing it's an ArrayOutOFBoundsException, and that means you're trying to access an index that's either bigger than the array, or less than zero. You say you get this problem when there's a space in your message (right?). Have a look through your cipher code and work out what happens when you get to a space in your message - work out the numbers and the result you get. I'm not sure why it would only fail when you add 'a' - doesn't it fail if you run it what you posted, where you subtract 'A' whether it's uppercase or not?
|
# ? Sep 15, 2015 19:59 |
|
baka kaba posted:^^^ That's an issue for reals, but also: This was no help, I already know that it has to do with the array. I'm looking for the exact point that the code causes out of bounds and why it doesn't execute properly. It executed fine with all caps. I don't need to know where to look I need to know why the code I am using isn;t working, and why it specifically wont work, not some clue as to what to do. Modulo16 fucked around with this message at 20:22 on Sep 15, 2015 |
# ? Sep 15, 2015 20:14 |
|
|
# ? Jun 13, 2024 03:03 |
|
Frank Viola posted:This was no help Ok fine Java code:
isUpperCase(" ") is always false so you always hit the else part with a space
|
# ? Sep 15, 2015 20:21 |