【发布时间】:2016-08-26 15:38:02
【问题描述】:
我有一些鼠标监听器的点点滴滴,但我不知道如何将它们联系在一起。当用户单击“玩游戏”按钮时,我正在尝试激活井字游戏。协助将不胜感激。
import java.awt.*;
import java.awt.BorderLayout;
import java.awt.FlowLayout;
import java.awt.EventQueue;
import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;
import java.awt.GridBagLayout;
import java.awt.event.*;
import java.awt.event.ActionListener.*;
import javax.swing.*;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JLabel;
import javax.swing.JButton;
import javax.swing.ImageIcon;
import javax.swing.border.EmptyBorder;
import javax.swing.JOptionPane;
import java.awt.Color;
public class Use_PF_Interface extends JFrame implements Pet_Fish_Interface, MouseListener
{
// instance variables - replace the example below with your own
private JFrame window;
private JPanel backgroundPanel;
private JLabel lblBackgroundImage = new JLabel();
private JButton feedButton = new JButton("Feed Fish");
private JButton playGamesButton = new JButton("Play Game");
volatile private boolean mouseDown = false;
//creates frame window
public Use_PF_Interface()
{
setTitle("Virtual Pet Fish");
setSize(400, 400);
//initializes panels and panel layout
backgroundPanel = new JPanel();
backgroundPanel.setOpaque(false);
backgroundPanel.setLayout(new FlowLayout());
lblBackgroundImage.setLayout(new FlowLayout());
//sets background image of panel
lblBackgroundImage.setIcon(new ImageIcon("OCEAN2.jpg"));
lblBackgroundImage.setLayout(new BorderLayout());
lblBackgroundImage.setBounds(0, 0, 400, 400);
//adds button to panels
backgroundPanel.add(feedButton);
backgroundPanel.add(playGamesButton);
lblBackgroundImage.add(backgroundPanel);
add(lblBackgroundImage);
feedButton.addMouseListener(this);
playGamesButton.addMouseListener(listener);
addMouseListener(this);
}//creates frame window
/**
* This method will create an action for the button.
* @pre none
* @return tic tac toe game
* @param none
* @post none
*/
public void mousePressed(MouseEvent e)
{
if (e.getButton() == MouseEvent.playGamesButton)
{
mouseDown = true;
Tic_Tac_Toe();
}
}
public void mouseReleased(MouseEvent e)
{
if(e.getButton() == MouseEvent.feedButton)
{
mouseDown = false;
}
}
public void mouseExited(MouseEvent e)
{
}
我目前收到此错误:Use_PF_interface 不是抽象的,并且不会覆盖 java.awt.event.MouseListener 中的抽象方法 mouseEntered(java.awt.event.MouseEvent)
【问题讨论】:
标签: java mouselistener