开发者

Java can't find symbol

开发者 https://www.devze.com 2023-02-11 14:47 出处:网络
This is my error message test.java:17: cannot find symbol symbol: class MouseAdapter location: class test

This is my error message

test.java:17: cannot find symbol
symbol  : class MouseAdapter
location: class test
        private class click extends MouseAdapter
                                    ^
test.java:19: cannot find symbol
symbol  : class MouseEvent
location: class test.click
                public void mouseEntered(MouseEvent e)
                                         ^
test.java:14: cannot find symbol
symbol  : variable trayicon
location: class test
        trayicon.addMo开发者_开发知识库useListener(new click());
        ^
3 errors

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

public class test extends JFrame
{

    private JFrame frame;

    public void init()
    {
        trayicon.addMouseListener(new click());
    }

        private class click extends MouseAdapter
        {
            public void mouseEntered(MouseEvent e)
            {
                {
                frame.setVisible(true);
            }
        }
    }
}


You need:

import java.awt.event.*;

Edit:

and you need to declare trayicon:

JLabel trayicon = new JLabel();


Reproducing the error:

$cat >test.java <<. 
import javax.swing.*;
import javax.swing.event.*;
import java.awt.*;

public class test extends JFrame
{

    private JFrame frame;

    public void init()
    {
        trayicon.addMouseListener(new click());
    }

        private class click extends MouseAdapter
        {
            public void mouseEntered(MouseEvent e)
            {
                {
                frame.setVisible(true);
            }
        }
    }
}
.
$javac test.java 
test.java:15: cannot find symbol
symbol  : class MouseAdapter
location: class test
        private class click extends MouseAdapter
                                    ^
test.java:17: cannot find symbol
symbol  : class MouseEvent
location: class test.click
            public void mouseEntered(MouseEvent e)
                                     ^
test.java:12: cannot find symbol
symbol  : variable trayicon
location: class test
        trayicon.addMouseListener(new click());
        ^
3 errors

Adding the import

$ed test.java 
431
1i
import java.awt.event.*;
.
wq
456
$javac test.java 
test.java:13: cannot find symbol
symbol  : variable trayicon
location: class test
        trayicon.addMouseListener(new click());
        ^
1 error

Declaring trayicon at line 13

$ed test.java 
456
13i
        JLabel trayicon = new JLabel();// or something that makes sense
.
wq
528
$javac test.java 
$

Fixed!

Resulting code:

$cat test.java 
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
import java.awt.*;

public class test extends JFrame
{

    private JFrame frame;

    public void init()
    {
        JLabel trayicon = new JLabel();// or something that makes sense
        trayicon.addMouseListener(new click());
    }

        private class click extends MouseAdapter
        {
            public void mouseEntered(MouseEvent e)
            {
                {
                frame.setVisible(true);
            }
        }
    }
}

BTW, you don't need lines 26 and 21:

$ed test.java 
633
26d
21d
wq
605
$javac test.java 
$
$cat test.java 
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
import java.awt.*;

public class test extends JFrame
{

    private JFrame frame;

    public void init()
    {
        JLabel trayicon = new JLabel();// or something that makes sense
        trayicon.addMouseListener(new click());
    }

        private class click extends MouseAdapter
        {
            public void mouseEntered(MouseEvent e)
            {
                frame.setVisible(true);
            }
        }
    }


adding to mellamokb, you are using a variable trayicon which is not declared anywhere.

So add

import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;

and declare trayicon

0

精彩评论

暂无评论...
验证码 换一张
取 消