0
我編寫了一個關於Swing的簡單項目(沒有動作偵聽器)。 我想添加一個按鈕到JPanel
並添加面板(名爲panel
)到JFrame
(名爲frame
)。但是,當我加入了面板框架,Eclipse中有一個錯誤:Eclipse:在JFrame中添加JPanel
The type javax.swing.JComponent cannot be resolved. It is
indirectly referenced from required .class files
這是我的源:
import javax.swing.*;
public class Click {
public static void main(String[] args) {
JFrame frame = new JFrame();
frame.setTitle("oooooo");
frame.setVisible(true);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JPanel panel = new JPanel();
frame.add(panel); //the error
}
}
我該怎麼辦?
這似乎是Eclipse的常見問題 - 只需搜索[eclipse javax.swin g.JComponent can not be resolved](https://www.google.com.au/search?q=eclipse+javax.swing.JComponent+cannot+be+resolved&oq=eclipse+javax.swing.JComponent+cannot+be+解決&aqs = chrome..69i57j0l5.2627j0j7&sourceid = chrome&ie = UTF-8),你會發現一些其他人也有類似的問題 – MadProgrammer
所以我應該改變我的編譯器? – amm
已閱讀其他一些問題/答案,嘗試幾件事情,如果您仍然遇到問題,請發佈問題列出您嘗試過的所有內容 – MadProgrammer