0

I have a JpopUpMenu that sends this to a frame called "j4a_Lainat", but it only leads me to "Incompatible types: cannot be converted to j3_Paaikkuna". Any help would be appreciated.

EDIT:

    private void MENUMousePressed(java.awt.event.MouseEvent evt) {                                  

    ImageIcon PlusIcon = new ImageIcon(getClass().getResource("/Img/Buttons/menu_button_pressed.png"));
    MENU.setIcon(PlusIcon);
    BtnPressed = true;

    JPopupMenu menu;
    JMenuItem m1,m2,m3, m4;

    // Create JButtons

    // Create a JPopupMenu

    menu = new JPopupMenu() {
        @Override
        public void paintComponent(final Graphics g) {
            g.setColor(Color.WHITE);
            g.fillRect(0,0,getWidth(), getHeight());

        }
    };

    // Create JMenuItems

    m1=new JMenuItem(new AbstractAction("Lainat"){

        @Override
        public void actionPerformed(ActionEvent e) {
          j4a_Lainat j4 = new j4a_Lainat(this);         
          j4.setVisible(true);


        }


    }


    );


    m3=new JMenuItem(new AbstractAction("Hyväntekeväisyys"){
        @Override
        public void actionPerformed(ActionEvent e) {
            j4d_Hyvantekevaisyys HT = new j4d_Hyvantekevaisyys(YRNIMI);
            HT.setVisible(true);

        }
    });
    m2=new JMenuItem(new AbstractAction("Tilastot"){
        @Override
        public void actionPerformed(ActionEvent e) {
            try {
                j4e_Tilastot T = new j4e_Tilastot(YRNIMI);
                T.setVisible(true);
            } catch (ClassNotFoundException ex) {
                Logger.getLogger(j3_Paaikkuna.class.getName()).log(Level.SEVERE, null, ex);
            } catch (SQLException ex) {
                Logger.getLogger(j3_Paaikkuna.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
    });
    m4=new JMenuItem("CREDITS");


    menu.add(m1);
    menu.add(m2);
    menu.add(m3);
    menu.add(m4);



    Component b=(Component)evt.getSource();


    Point p=b.getLocationOnScreen();




    menu.show(this,0,0);



    menu.setLocation(p.x-74,p.y+2+b.getHeight());
    System.out.println(send);
    if(send == true){
        System.out.println("Toimii");
         j4a_Lainat l = new j4a_Lainat(this);
         l.setVisible(true);

    }
}
              //j4a_Lainat contructor goes as following

              j4a_Lainat(j3_Paaikkuna aThis){
              initComponents();
              j= aThis;
              }

The class from which I am calling this is j3_Paaikkuna. Simply put, I just want to open a jpopupmenu, import j3_Paaikkuna to it and use it to call an update method in j3_Paaikkuna.

Naldery
  • 11
  • 5
  • Can you post the [Stacktrace](https://stackoverflow.com/questions/3988788/what-is-a-stack-trace-and-how-can-i-use-it-to-debug-my-application-errors) (or the full error message, since it's a compiler error)? – Impulse The Fox Mar 22 '18 at 07:55
  • Please provide the class where this code belongs to, and also show us the constructor of `j4a_Lainat` that you are calling. – Seelenvirtuose Mar 22 '18 at 07:55
  • @ImpulseTheFox It's a compiler error! – Seelenvirtuose Mar 22 '18 at 07:56
  • 1
    Your class names are confusing, they should be camel case to make it easier to read. What is the constructor for `j4a_Lainat` that you are trying to call? `this` is refering to the AbstactAction, you should probably use NameOfOuterClass.this, but it needs more code to be sure. – matt Mar 22 '18 at 07:56
  • j4a_Lainat constructor has j3_Paaikkuna parameter, which is what I am trying to convert. Will edit with more code. – Naldery Mar 22 '18 at 08:14
  • 1
    1) For better help sooner, post a [MCVE] or [Short, Self Contained, Correct Example](http://www.sscce.org/). 2) A single blank line of white space in source code is all that is *ever* needed. Blank lines after `{` or before `}` are also typically redundant. 3) Use a logical and consistent form of indenting code lines and blocks. The indentation is intended to make the flow of the code easier to follow! 4) See [The Use of Multiple JFrames, Good/Bad Practice?](http://stackoverflow.com/q/9554636/418556) – Andrew Thompson Mar 22 '18 at 08:28

0 Answers0