Win a copy of Modern JavaScript for the Impatient this week in the Server-Side JavaScript and NodeJS forum!

Stephan van Hulst

Saloon Keeper
+ Follow
since Sep 20, 2010
Cologne, Germany
Cows and Likes
Total received
In last 30 days
Total given
Total received
Received in last 30 days
Total given
Given in last 30 days
Forums and Threads
Scavenger Hunt
expand Rancher Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Stephan van Hulst

Ahh sorry. Rename getWindow(Event event) to getStage(Event event) and change its implementation to this:

The rest of your code can remain the same.
8 hours ago
Our company works for some Dutch government agencies, and (sadly but understandably) many of them will not drop support for IE. Funny enough, many of them have completely ditched IE for internal services.
Yeah, but the initialize() method is probably never called. That's because you are creating the controller class manually, instead of letting FXMLLoader do it.

Don't create controllers by calling their constructors. Ditch viewSwitcherMethod() and instead create the new scene as I've shown you.
13 hours ago
All you need to do is replace the four vars I used with JOptionPane, JDialog, T and String respectively.
13 hours ago
A few comments on your code:

  • Don't extend heavy-weight containers (JFrame, JDialog, JWindow and JApplet). Use a private field instead.
  • Translucent components need to return false from their isOpaque() method.
  • The paintComponent() method always receives a Graphics2D instance. If it does not you can perform an early return or even throw an AssertionError.
  • Instead of implementing listener interfaces with lots of no-op implementations, extend the appropriate adapter class. Instead of MouseListener, use MouseAdapter.
  • You can replace your anonymous Runnable implementation in your invokeLater() call with a lambda expression.
  • Don't call System.exit(). Simply call return.
  • If you want to draw on top of an entire frame and catch mouse events that may occur anywhere in the frame, consider using the frame's glass pane instead of its content pane.
  • 1 day ago
    The serialization mechanism doesn't use initializers or constructors when deserializing instances of Serializable classes. If a class is not Serializable, its constructors and initializers will be called as usual. This is what happens:

    1) The ObjectInputStream sees that the stream contains an instance of Moo. It creates an instance of Moo using "magic".
    2) It initializes the new instance starting at the root of the class hierarchy. Boo is not Serializable, so it calls Boo's constructor.
    3) BooBoo is not Serializable, so it calls BooBoo's constructor.
    4) Moo IS Serializable, so it does NOT call its initializers/constructor. Instead, it writes 20 to the moo field.
    5) Finally, System.out.println(moo.moo) is called, which prints 20.
    Your code doesn't check that a is null. It's possible to assign certain values to a so that your condition will evaluate to true anyway, the most obvious of which you have demonstrated yourself by assigning the empty string to a.

    There are three approaches you can take, depending on what a represents and what you want your application to do with it:

    1) Check that a is exactly null: if (a === null) {

    2) Check that a is similar to null: if (a == null) {

    3) Check that a is falsey: if (!a) {

    The most common approach is the third.
    Your assertion contains two mistakes:

  • Clients are humans.
  • Clients that call a method can also see the implementation of that method.

  • First of all, when we talk about hiding implementation details from a client, by client we usually mean "the calling method". The calling method won't be able to see that the returned list in an ArrayList or LinkedList, unless you explicitly cast the return value first. Most programmers won't do this.

    Secondly, if by 'client' we refer to the human programmer, it's not necessarily so that they can see the implementation of a method even if they can call it. A lot of libraries contain only compiled classes and the source hasn't been publicized. Some API implementations run on a web service, and the client doesn't even have access to the compiled classes.

    The most important point of hiding implementation details is not the hiding itself. Nobody really cares if the calling code knows that it got a LinkedList or an ArrayList. The point is that by using List as the return type, you signal to the caller that whatever the implementation is NOW, they shouldn't rely on this because it could change at any moment.
    1 day ago
    You could change your design so that your DataMapper is just a collection of smaller component mappers. You can then test each implementation separately:
    1 day ago
    Please show us the directory structure of your project, and highlight where your image is located.
    1 day ago
    What does your view switcher do? I feel that your problem is caused because you are not using the regular way to instantiate FXML controllers. Also, you need to treat the initialize() method like you treat constructors: Use them for initialization of fields ONLY. Don't perform any business logic in constructors or initializers.

    You'll want to do something like this:

    1 day ago
    If you change the starting code to:then you can get the number of Unicode code points with 22 additional characters of code. I'm assuming my solution is the same as Campbell's.
    So what do you think is the answer, and why?
    How is it a bug? It's intended behavior. It explicitly says so in the JLS.

    Campbell Ritchie wrote:Since uminus and predecrement are right‑associative operators, it would be right to parse it as -(--i).

    Why? Determining operator precedence is a parsing step. Lexing takes priority. Besides, why would it be correct to interpret ---i as -(--i) and not as -(-(-i))?
    2 days ago
    This seems to work for me:
    2 days ago