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.
10 comments
Comment actions Permalink

Hi Piotr,

You should define project java jdk to use.

Denis

0
Comment actions Permalink

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.

0
Comment actions Permalink

Provide archived directory of your project.

Denis

0
Comment actions Permalink

Could you please be more clearly ? I don't know if i understand you correctly.



Attachment(s):
program.zip
0
Comment actions Permalink

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

0
Comment actions Permalink

I have updated my previous post enclosing the project. Thanks for help.

0
Comment actions Permalink
  1. You created class called 'Frame';
  2. Class 'Program' uses that custom class;
  3. Class 'Frame' doesn't have 'setDefaultCloseOperation()' and 'setVisible()' methods;
  4. Class 'Program' tries to call those unexisted methods;


Denis

0
Comment actions Permalink

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.

0
Comment actions Permalink

Sorry, but the source you provide looks like below:

/**
* Created by IntelliJ IDEA.
* User: p200353
* Date: 11.08.11
* Time: 10:49
* To change this template use File | Settings | File Templates.
*/

import java.awt.*;
import javax.swing.*;

public class Frame {
    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;
}


I.e. your class doesn't extend JFrame.

0
Comment actions Permalink

Mea culpa. After copy/paste the interior code of class Frame, i forgot to add "extends JFrame". What a stupid oversight...

0

Please sign in to leave a comment.