Paint 메서드가 호출 될 때 코드를 실행할 때 Java의 Paint 메서드에 대해 질문하고 싶습니다.Java의 Paint 메서드
그럼 어떻게 페인트 방법을 중지 하시겠습니까?
참고 : 나는 페인트 방법을 수행하기 위해 버튼을 만들었습니다.
일반적으로 코드를 실행할 때 Paint 메서드가 기본적으로 호출됩니다. 그래서이를 멈추고 단추를 클릭 할 때 Paint 메서드를 호출해야합니다. 여기
코드
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);
}
}
}
구체적으로 무엇을하려고하는지 더 자세히 알려줘야합니다. 스윙을 사용하고 있습니까? 일반적으로 페인트 메서드는 다시 그릴 이유가있을 때만 호출됩니다. 당신의 프로그램을 무한 루프 나 블록/동결시킬 수있는 코드를 페인트 메소드에 가지고 있습니까? – collinjsimpson
버튼을 클릭하지 마십시오? 질문이 내게 명확하지 않다 ... –
코드가 완료된 후에 코드가 멈춘다. – Max