<div>프로그램 내용 : 한점 (x,y)를 난수로 발생. 이후 case함수를 이용하여 한 방향으로 도형을 이동시킴 지정해놓은 위치까지 가면 다른 방향으로 튕기도록</div> <div>다른 case 함수를 불러옴.</div> <div> </div> <div>문제점 : 도형이 랜덤한 지점에 생성이 되나 도형들이 움직이지 않음.</div> <div>다른 어떤 문법 오류는 없었음...</div> <div> </div> <div>컴게 고수 님들 제가 뭘 잘못한걸까요 ㅠㅠ</div> <div> </div> <div>import java.awt.Color;<br />import java.awt.Graphics;<br />import javax.swing.JApplet;<br />import java.util.Random;</div> <div> </div> <div>public class TestClass2 extends JApplet <br />{<br /> private static final long serialVersionUID = 1L;<br /> private static final int WIDTH = 220, HEIGHT = 220;<br /> private static final int STEPS = 180;<br /> private static final int DELAY = 10;<br /> private static final int SIZE = 20;<br /> <br /> Random ran = new Random();</div> <div> @Override<br /> public void init()<br /> {<br /> resize(WIDTH, HEIGHT);<br /> }<br /> <br /> @Override<br /> public void paint(Graphics g)<br /> {<br /> int x, y;<br /> x = 1 + ran.nextInt(198);<br /> y = 1 + ran.nextInt(198);<br /> case1(g,x,y);<br /> }<br /> <br /> public void case1(Graphics g, int x, int y)<br /> {<br /> while(true)<br /> {<br /> if(x>=199) case4(g,x,y);<br /> if(y>=199) case2(g,x,y);<br /> x++;<br /> y++;<br /> drawBall(g, x, y);<br /> sleep(DELAY);<br /> }<br /> }<br /> <br /> public void case2(Graphics g, int x, int y)<br /> {<br /> while(true)<br /> {<br /> if(x>=199) case3(g,x,y);<br /> if(y<=1) case1(g,x,y);<br /> x++;<br /> y--;<br /> drawBall(g, x, y);<br /> sleep(DELAY);<br /> }<br /> }<br /> <br /> public void case3(Graphics g, int x, int y)<br /> {<br /> while(true)<br /> {<br /> if(x<=1) case2(g,x,y);<br /> if(y<=1) case4(g,x,y);<br /> x--;<br /> y--;<br /> drawBall(g, x, y);<br /> sleep(DELAY);<br /> }<br /> }<br /> <br /> public void case4(Graphics g, int x, int y)<br /> {<br /> while(true)<br /> {<br /> if(x<=1) case1(g,x,y);<br /> if(y>=199) case3(g,x,y);<br /> x--;<br /> y++;<br /> drawBall(g, x, y);<br /> sleep(DELAY);<br /> }<br /> }</div> <div> private void sleep(int delay)<br /> {<br /> try{Thread.sleep(delay);}<br /> catch(Exception e){e.printStackTrace();}<br /> }</div> <div> private void drawBall(Graphics g, int x, int y)<br /> {<br /> g.setColor(Color.gray);<br /> g.fillRect(0, 0, WIDTH, HEIGHT);<br /> g.setColor(Color.black);<br /> g.fillRect(x, y, SIZE, SIZE);<br /> }<br />}</div>
댓글 분란 또는 분쟁 때문에 전체 댓글이 블라인드 처리되었습니다.