Java找不到符号

发布于 2024-10-17 17:54:19 字数 1008 浏览 1 评论 0原文

这是我的错误消息

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);
            }
        }
    }
}

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.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);
            }
        }
    }
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

我乃一代侩神 2024-10-24 17:54:20

您需要:

import java.awt.event.*;

编辑:

并且您需要声明trayicon:

JLabel trayicon = new JLabel();

You need:

import java.awt.event.*;

Edit:

and you need to declare trayicon:

JLabel trayicon = new JLabel();
倾听心声的旋律 2024-10-24 17:54:20

重现错误:

$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

在第 13 行添加声明

$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

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);
            }
        }
    }

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);
            }
        }
    }
春花秋月 2024-10-24 17:54:20

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

因此添加

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

并声明trayicon

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文