English 中文(简体)
java油漆方法
原标题:Paint method in java

我想问一下,在我执行《法典》时,“油漆”的方法是什么。

因此,如何制止油漆方法?

注:我用 but子做油漆方法。

通常在一执行法典时,油漆方法就被停用了,因此,当我点击时,需要停用,用油漆方法。

本条准则

import javax.swing.JApplet;
import java.awt.Graphics;
import java.awt.Color;
import javax.swing.JButton;
import java.awt.FlowLayout;
import java.awt.event.*;
import java.util.Random;

public class RandDraw extends JApplet  implements ActionListener {

JButton Draw1 = new JButton ("Draw");

public void init() {
  this.setLayout (new FlowLayout());
  this.add(Draw1);
  Draw1.addActionListener(this);
}

public void actionPerformed(ActionEvent e){
  if(e.getSource()==Draw1)
    repaint();
  }
}

public void paint(Graphics g){
  for(int i=0;i<50;i++){
    g.setColor
      (new Color(i*655%256,i*355%256,i*958%256));
    Random r = new Random ();
    int rr= r.nextInt(40)+10;
    Random r1 = new Random ();
    int rr1= r1.nextInt(70)+10;
    Random r2 = new Random ();
    int rr2= r2.nextInt(10)+10;
    g.fillOval(2*rr1,rr*rr2,O+O1*2,O+O1*2);
  }
}
}
问题回答
  1. Add a boolean member variable doDraw to your class. Mark it as volatile.
  2. In the ActionListener for the button, toggle the value of doDraw. If it s true, make it false; if it s false, make it true.
  3. 最后,附上<代码>paint()方法的正本。

    if (doDraw) { // Rest of the code here }

你们走了!

通常,你应压倒涂料委员会,它最终被油漆(油漆)所指。 您在油漆中是否有任何缺陷。

我不了解你问题的其他部分——见欧内斯特的答复。





相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签