Recognise a PushButton in Netbeans (DigitalRead, SerialConnection, JSSC)

Hey guys,

i think this problem is so trivial that there is no tutorial that simple.

I have a Arduino Uno and a pushbutton connected to DigitalIn 2.
I want to use the pressing of the button inside my Java Code.

All I need is a Java code that recognises the press of a pushbutton. E.G. Printing out "button pressed". Later I want to use it in an If condition ( if button is pressed, then show image or do whatever)

I read about Jssc and have the library installed. Most tutorials however are about sending data to the arduino

The Arduino can send a serial message to the PC when a button press is detected.
A Java program on the PC can presumably detect when serial data is available, read the data and act on it.

Can you read a serial input in Java ?

Well, I tried some sample code and often I get things like CommPortIdentifier or SerialPort underlined red..

I tried some sample code and often I get things like CommPortIdentifier or SerialPort underlined red..

I presume that these are Java error on the PC. Is that right ?