简体   繁体   中英

Cannot Use or import javax.swing and java.awt in IntelliJ IDEA with jdk1.7 or 1.8

I want to use GUI tools in Java, my IDE is IntelliJ IDEA in Win8.1 and I have:

java -version

java version "1.7.0_51"
Java(TM) SE Runtime Environment (build 1.7.0_51-b13)
Java HotSpot(TM) 64-Bit Server VM (build 24.51-b03, mixed mode)

in my path and another jdk (1.8) somewhere else.

In the commadLine (using javac) I can make/compile/build codes that are like these:

import java.awt.*; // Using AWT container and component classe
import java.awt.event.*; // Using AWT event classes and listener interfaces
// An AWT program inherits from the top?level container java.awt.Frame
public class AWTCounter extends Frame implements ActionListener {
private Label lblCount; // Declare component Label
private TextField tfCount; // Declare component TextField
private Button btnCount; // Declare component Button
private int count = 0; // Counter's value

(etc, the codes are not really important)

In my project structure in IntelliJ, I have added jdk 1.7.0_51 (same as above) but it says: "cannot resolve symbol 'event'" in the 2nd line:

import java.awt.event.*;

(the color of 'event' is red, means it does not exist)

I may have missed something about path. I spent hours searching and I didn't find anything related.

The problem was declaring Android SDK instead of JDK in my project structure. Android software development kit does not include anything from java.awt or related packages because Android has it's own graphics package and libraries like android.graphics or android.widget .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM