Problem with a program
Hi there. I'm new to IntelliJ IDEA, and I have a problem when running simple program composed of 3 classes:
import java.awt.*; import javax.swing.*; public class Program { public static void main(String[] args) { EventQueue.invokeLater(new Runnable() { public void run() { Frame frame = new Frame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setVisible(true); } }); } }
import java.awt.*; import javax.swing.*; public class Frame extends JFrame { public Frame() { setSize(600, 500); panel = new JPanel(); add(panel, BorderLayout.CENTER); Action firstAction = new Action("One", new ImageIcon("adin.png")); Action secondAction = new Action("Two", new ImageIcon("dwa.png")); Action thirdAction = new Action("Three", new ImageIcon("tri.png")); JToolBar bar = new JToolBar(); bar.add(firstAction); bar.add(secondAction); bar.add(thirdAction); add(bar, BorderLayout.WEST); } private JPanel panel; }
import java.awt.event.*; import javax.swing.*; public class Action extends AbstractAction { public Action(String name, Icon icon) { putValue(Action.NAME, name); putValue(Action.SMALL_ICON, icon); } public void actionPerformed(ActionEvent event) { //kod } }
In Program class setDefaultCloseOperation and setVisible are highlited red with notes " Cannot resolve method '...' ". The same situation is in Frame class, where highlited on red are SetSize and add. This program works fine under NetBeans. Thanks in advance for replies.
请先登录再写评论。
Hi Piotr,
You should define project java jdk to use.
Denis
SDK (JDK) path is set properly, the hello world program from "Setting_up_a_project_in_IntelliJ_IDEA" works fine. I still have an errors.
Provide archived directory of your project.
Denis
Could you please be more clearly ? I don't know if i understand you correctly.
Attachment(s):
program.zip
I suspect your problem to be related to the incorrect project setup, so, I need to have a look on it. The proposal is to deliver complete project (source and config files).
Denis
I have updated my previous post enclosing the project. Thanks for help.
Denis
Class Frame extends JFrame. One of the "built in" method of JFrame is setDefaultCloseOperation. One of the method inherited from class java.awt.window is setVisible. Like i said, that program works fine under NB, so i still don't understand why it doesn't work under IJI.
Sorry, but the source you provide looks like below:
I.e. your class doesn't extend JFrame.
Mea culpa. After copy/paste the interior code of class Frame, i forgot to add "extends JFrame". What a stupid oversight...