为什么在一个Panel注册的JButton,当鼠标移到按钮上后另一个PANEL上也出现这个按钮?
代码如下 小弟刚学 写的乱七八糟 希望高手们别笑话我。
public class Game {
public static void main(String[] args) {
new MyFrame().show();
}
}
import java.awt.*;
import javax.swing.*;
public class MyFrame extends JFrame{
public MyFrame() {
super("我的游戏");
this.setSize(600,500);
OperatorPanel op=new OperatorPanel();
GraphicPanel gp=new GraphicPanel();
Container c=this.getContentPane();
c.setLayout(new BorderLayout());
c.add(gp,BorderLayout.CENTER);
c.add(op,BorderLayout.SOUTH);
}
}
import java.awt.*;
import javax.swing.*;
public class GraphicPanel extends JPanel{
public GraphicPanel() {
}
public void paint(Graphics g)
{
Image image=Toolkit.getDefaultToolkit().getImage("GIF/0004.gif");
g.drawImage(image,60,60,null,this);
setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
}
}
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import java.util.*;
public class OperatorPanel extends JPanel implements ActionListener{
JButton jb1=new JButton("移动");
JButton jb2=new JButton("闪躲");
JButton jb=new JButton("开始");
JPanel jp1=new JPanel();
JPanel jp2=new JPanel();
JLabel jl1=new JLabel("请点击上面的图片");
int x=60,y=50;
public OperatorPanel() {
this.setBackground(Color.BLACK);
this.setLayout(new BorderLayout());
jp2 .setLayout(new FlowLayout());
jp2.add(jb);
jp2.add(jb1);
jp2.add(jb2);
jp1.add(jl1);
this.add(jp1,BorderLayout.CENTER);
this.add(jp2,BorderLayout.SOUTH);
jb.addActionListener(this);
}
public void actionPerformed(ActionEvent e)
{
}
}
后面的代码还没想好怎么写。。。。如果谁知道教教我 我很想学好JAVA