Java找不到符号

问题描述 投票:0回答:3

这是我的错误消息

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.addMouseListener(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);
            }
        }
    }
}
java object applet
3个回答
2
投票

您需要:

import java.awt.event.*;

编辑:

并且您需要声明托盘图标:

JLabel trayicon = new JLabel();

0
投票

重现错误:

$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

添加导入

$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

在第 13 行声明

trayicon

$ed test.java 
456
13i
        JLabel trayicon = new JLabel();// or something that makes sense
.
wq
528
$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);
            }
        }
    }
}

顺便说一句,你不需要第 26 行和第 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);
            }
        }
    }

0
投票

添加到 Mellamokb,您正在使用一个未在任何地方声明的变量 trayicon

所以添加

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

并声明 trayicon

© www.soinside.com 2019 - 2024. All rights reserved.