MouseListener的重写方法

时间:2019-10-15 00:36:38

标签: java swing mouselistener

我正在创建一个使用Swing绘制面孔的Java程序,然后使用MouseListener响应鼠标单击以使一只眼睛眨眼。如何使用MouseListener使一只眼睛眨眼?用该名称只能创建一次paint(Graphics g)方法,所以如果我要重复它并在MouseListener代码下对其进行编辑,并且一只眼睛变成闪烁的线条,我该怎么做? >

到目前为止,这是我的代码:

import javax.swing.JFrame;
import javax.swing.JPanel;
import java.awt.*;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;

public class Sans extends JPanel {

public void paint(Graphics g) {

    super.paintComponent(g);
    setSize(650, 650);
    g.drawOval(110, 250, 500, 275);
    g.setColor(new Color(226, 222, 217));
    g.fillOval(110, 250, 500, 275);

    g.drawOval(475, 300, 75, 75);
    g.setColor(new Color(74, 199, 226));
    g.fillOval(475, 300, 75, 75);

    g.drawOval(505, 330, 15, 15);
    g.setColor(new Color(0, 0, 0));
    g.fillOval(505, 330, 15, 15);

    g.drawOval(175, 300, 75, 75);
    g.setColor(new Color(0, 0, 0));
    g.fillOval(175, 300, 75, 75);

    g.drawOval(205, 330, 15, 15);
    g.setColor(new Color(232, 255, 243));
    g.fillOval(205, 330, 15, 15);

    g.drawOval(350, 375, 20, 50);
    g.setColor(new Color(0, 0, 0));
    g.fillOval(350, 375, 20, 50);

    g.drawArc(290, 360, 150, 150, 180, 180);
    g.setColor(new Color(255, 255, 255));
    g.fillArc(290, 360, 150, 150, 180, 180);
}


public static void main(String[] args) {

    Font font = new Font("TimesRoman", Font.PLAIN, 15);

    JFrame frame = new JFrame();
    Sans spook = new Sans();
    frame.add(spook);
    frame.setSize(750, 750);

    frame.setTitle("I'VE GOTTEN A TON OF WORK DONE TODAY. A SKELE-TON.");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setLocationRelativeTo(null);
    frame.setResizable(false);
    frame.setVisible(true);
}

public class BlinkHandler implements MouseListener {



    public void mouseClicked(MouseEvent e) {

    }


    public void mousePressed(MouseEvent e) {

    }


    public void mouseReleased(MouseEvent e) {

    }


    public void mouseEntered(MouseEvent e) {

    }

    public void mouseExited(MouseEvent e) {

    }
}

}

0 个答案:

没有答案