无法解析类型 javax.swing.JComponent。从必需的 .class 文件间接引用了它,菜鸟求解答,求赐教?
回答:你要用哪个类,你就要导入 import javax.swing.JFrame; 这里导入了JFrame ,再次使用这个语句导入 import java.swing.JComponent; 就好了。如果导入之后,导入的这句话有红叉,显示无法解析导入的这句话,可能是你jar包的路径问题。
package bo;
import java.awt.EventQueue;
import javax.swing.JFrame;
public class RunDialogDemo {
private JFrame frame;
/**
* Launch the application.
*/
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
RunDialogDemo window = new RunDialogDemo();
window.frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
/**
* Create the application.
*/
public RunDialogDemo() {
initialize();
}
/**
* Initialize the contents of the frame.
*/
private void initialize() {
frame = new JFrame();
frame.setBounds(100, 100, 450, 300);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.getContentPane().setLayout(null);
}
}
回答:你要用哪个类,你就要导入 import javax.swing.JFrame; 这里导入了JFrame ,再次使用这个语句导入 import java.swing.JComponent; 就好了。如果导入之后,导入的这句话有红叉,显示无法解析导入的这句话,可能是你jar包的路径问题。