[Java] com.sun.glass.WindowEvent is imported and the window does not close

Development environment

IDE: Eclipse photon 4.8 MacBook: Catalina 10.15.7 Language: java8

Code to close the window with the close button

		addWindowListener(new WindowAdapter() {
//			@SuppressWarnings("unused")
			public void windowClosing (WindowEvent e) {
				dispose();
				System.exit(0);
			}
		});

@SuppressWarnings ("unused ") is a comment proposed by Eclipse. When I insert this, the error disappears, but I'm telling the JVM that I'm not using it, so I don't have to recognize any unused variables as an error. The person who wrote it also knows `so a comment to prevent the error from being displayed.

In other words, it hasn't been solved!

Of course, you can't close the window. But I'm going to write it according to the teaching materials.

I can't understand if I rely on Eclipse

//An error occurs in this part
public void windowClosing (WindowEvent e) {

Since the suggestion to import com.sun.glass.events.WindowEvent came out at the top of the editor of Eclipse, I added an import statement.

import com.sun.glass.events.WindowEvent;

** This was the cause. ** **

The next error displayed is The method windowClosing (WindowEvent) from type new WindowAdapter () {} is not used locally

I'm sorry I fixed it as Eclipse said. What is it?

The simple error above is that you can't use the method, but ... why did you do what Eclipse said, but it didn't seem to be resolved.

From there it is suggested to insert the following comment

@SuppressWarnings("unused")

No, I'm not using this. .. ..

Looking at the teaching materials, it seems that the relevant parts are completely the same even when compared with the sample. Even if you copy and paste the relevant part of the sample, the same error will occur, so it is unlikely that there is a spelling mistake or invisible code mixed in. .. .. ..

So I went to the swamp more and more. .. .. ..

Multiple classes with the same name in different packages

I also went back to the code with the first error, checked the suggestions displayed in Eclipse, and scrolled down to find another suggestion.

There was a suggestion like importing java.awt.Event`.

Isn't that the case? I thought it was bingo.

If you are inexperienced, it is a mistake to think that you should adopt the proposal part that appears at the top of ʻEclipse and correct it. Absolutely no.

After all, the import statement was wrong

import java.awt.Event;

If so, it was solved in an instant.

So what is com.sun.glass.WindowEvent?

micromagic_ouyou_src_myApp_BufferedStream_java_-_Users_onoharamakoto_Desktop_work_java-_Eclipse_IDE.png

It was here. It's in a different package. It's complicated.

After all, this took a lot of time. .. .. ..

It took about 2 hours, but I wonder if it was fruitful

Have you learned how to resolve an error?

This is what I think,

  1. Don't rely on Eclipse
  2. Check the official documentation
  3. When I try to google, only the English page comes up, but I read it properly
  4. Now check the JRE library
  5. Gained experience of mistakes other than spelling mistakes
  6. I got the experience of solving it myself

It seems stupid that it took about 2 hours even though it was a terrible mistake that the import statement was wrong at most, but I believe that such an experience will be acquired.

Basically, I can solve the error myself, but when a similar error appears, it is much faster than what I was told.

Then, somehow the error resolution procedure became my own form, so I felt that the procedure itself could be used for new errors.

Recommended Posts

[Java] com.sun.glass.WindowEvent is imported and the window does not close
Eclipse does not start after Java 11 is installed
[JAVA] What is the difference between interface and abstract? ?? ??
PATH does not pass ... The cause is the character code
What is the difference between Java EE and Jakarta EE?
What to do if the breakpoint is shaded and does not stop during debugging
What is the LocalDateTime class? [Java beginner] -Date and time class-
Java passes at the command prompt, but javac does not
Java is the 5th day
[Java] What is the difference between form, entity and dto? [Bean]
Where is the Java LocalDateTime.now () timezone?
Java Calendar is not a singleton.
Why Java Vector is not used
The story of forgetting to close a file in Java and failing
[Java] Nowadays, the extended for statement is not exclusively for List, isn't it?
A story that suffered from a space that does not disappear even if trimmed with Java The cause is BOM
Java Integer comparison (==) does not work correctly
What is the best file reading (Java)
What is Java and Development Environment (MAC)
What is the main method in Java?
The Java EE Security API is here!
[Java 7] Divide the Java list and execute the process
[Java8] Search the directory and get the file
Setting method that the size does not change even if CSS is changed
[Java] Calculate the day of the week from the date (Calendar class is not used)