这是我的错误消息
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);
}
}
}
}
您需要:
import java.awt.event.*;
编辑:
并且您需要声明托盘图标:
JLabel trayicon = new JLabel();
重现错误:
$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);
}
}
}
添加到 Mellamokb,您正在使用一个未在任何地方声明的变量 trayicon。
所以添加
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
并声明 trayicon