본문 바로가기
Technote/JAVA

2주차 JAVA 과제물

by Pooh0216 2009. 3. 23.

2주차 JAVA 과제물

import java.awt.Color;
import java.util.Random;
import java.awt.geom.Ellipse2D;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Rectangle;
import javax.swing.JPanel;
import javax.swing.JComponent;


	public class RectangleComponent extends JComponent
	{  
	   public void paintComponent(Graphics g)
	   {  
		  
	      // Recover Graphics2D
	      Graphics2D g2 = (Graphics2D) g;
	      g2.setColor(Color.RED);
	      final int SQUARE_LENGTH = 100;
	      
	      int x = (getWidth()- SQUARE_LENGTH)/2;
	      int y = (getHeight()- SQUARE_LENGTH)/2;
	  
	      // Construct a rectangle and draw it
	      Ellipse2D.Double box = new Ellipse2D.Double (10, 10, 30, 30);
//	      Ellipse2D.Double box = new Ellipse2D.Double (x, y, SQUARE_LENGTH, SQUARE_LENGTH);
//	      Ellipse2D.Double aox = new Ellipse2D.Double (100, 10, 30, 30);
	      Random a2 = new Random();
	      int a3 = a2.nextInt(256);
	      int a4 = a2.nextInt(256);
	      int a5 = a2.nextInt(256);
	      int a6 = a2.nextInt(256);
	      int b1 = a2.nextInt(256);
	      
	      int b2 = a2.nextInt(256);
	      int b3 = a2.nextInt(256);
	      int b4 = a2.nextInt(256);
	    
	      g2.setColor(new Color(a3,a4,a5,a6));
	      g2.fill(box);
	    //  g2.setColor(new Color(b1,b2,b3,b4));
	   //   g2.fill(aox);
	      
//	      g2.draw(box);
//	      g2.draw(aox);

	      // Move rectangle 15 units to the right and 25 units down
	      
	      // Draw moved rectangle
	      g2.draw(box);
	   }
	}

'Technote > JAVA' 카테고리의 다른 글

9주차 2번문제  (0) 2009.05.09
9주차 1번문제  (0) 2009.05.09
JAVA 4주차  (0) 2009.03.25
JAVA 3주차  (0) 2009.03.25
JAVA 1주차  (0) 2009.03.25