Java, how to draw constantly changing graphics

后端 未结 4 2122
甜味超标
甜味超标 2020-11-22 15:44

Have not done this before, so obviously I suck at it. Here 64 pixels around current mouse position get drawn little bigger on a form. Problem is, that it\'s \'kind of\' to s

4条回答
  •  情话喂你
    2020-11-22 15:59

    Add this method to the Paint method:

    public void clear(Graphics g, Color currentColor) {
        g.setColor(backgroundColor);
        g.fillRect(0, 0, width, height);
        g.setColor(currentColor);
        int delay = 5; //milliseconds
    
        ActionListener taskPerformer = new ActionListener() {
        public void actionPerformed(ActionEvent evt) { } };
    
        new Timer(delay, taskPerformer).start();
    } //run this right before you draw something
    

    Okay so use timer to slow down delay, not a threading, that's bad.

提交回复
热议问题