1

I have a project that is on github. I have two different computers that use the project. The reason I mention github is because the two computers have the exact same project. But on one of the computers, I get a package does not exist error. That package is com.sun.glass

import com.sun.glass.events.KeyEvent;

Underneath I tried just using

import com.sun.glass

my netbeans autocomplete shows that the package sun exists in com, but the package glass does not exist in sun. I cannot find any info about this error online, and have been searching for days. The strangest part as I said is it works on a different computer.

Both computers are running jdk 1.8. I'm at a loss; Any help would be greatly appreciated.

Jesse Fogel
  • 75
  • 2
  • 10
  • 1
    That's why you should not use com.sun.... imports , it's part of a JRE, but there is no assurance that is part of _all_ JRE. – minus Apr 04 '17 at 21:34
  • So the issue could be a different JRE on the different computers? I need com.sun.glass.events.KeyEvent; program won't work without it... – Jesse Fogel Apr 04 '17 at 21:38
  • [It is a bad practice to use Sun's proprietary Java classes?](http://stackoverflow.com/q/1834826/5221149) – Andreas Apr 04 '17 at 21:38
  • 1
    Did you perhaps import the wrong class, e.g. did you mean to import [`java.awt.event.KeyEvent`](https://docs.oracle.com/javase/8/docs/api/java/awt/event/KeyEvent.html) or [`javafx.scene.input.KeyEvent`](https://docs.oracle.com/javase/8/javafx/api/javafx/scene/input/KeyEvent.html)? – Andreas Apr 04 '17 at 21:40
  • That section of code is not mine; I am the sole developer now but this wasn't developed by me. With minor alterations java.awt.event.KeyEvent does work though; Thank you – Jesse Fogel Apr 04 '17 at 21:41
  • why was this downvoted? – Jesse Fogel Apr 05 '17 at 04:44

1 Answers1

2
import java.awt.event.KeyEvent;

the above is the preferred method of importing the KeyEvent class. There are differences between java KeyEvent and sun KeyEvent, but they are minor. For example:

com.sun.glass.event.KeyEvent.VK_BACKSPACE

is the following in java:

java.awt.event.KeyEvent.VK_BACK_SPACE

So after changing the import from sun to java and making a few changes to its use in the program, it works and is no longer JRE specific.

Jesse Fogel
  • 75
  • 2
  • 10