Skip to content
This repository has been archived by the owner on Dec 16, 2017. It is now read-only.

Commit

Permalink
No commit message
Browse files Browse the repository at this point in the history
  • Loading branch information
bok.chan committed Apr 16, 2011
1 parent ddc9a22 commit f0f18d1
Show file tree
Hide file tree
Showing 6 changed files with 137 additions and 2 deletions.
46 changes: 46 additions & 0 deletions RandomCircles.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@

import java.awt.Graphics2D;
import java.awt.geom.Ellipse2D;
import java.awt.geom.Point2D;




public class RandomCircles {
private int circleCount;
private int frameW;
private int frameH;


public RandomCircles(int circleCount, int frameW, int frameH) {
this.circleCount = circleCount;
this.frameW = frameW;
this.frameH = frameH;

}
public void draw(Graphics2D g2) {

for (int i = 0; i < circleCount; i++) {
Point2D leftCorner = getLocation();
double diameter =
Math.random() * (
Math.min(frameW, frameH) - 2 * Math.max(leftCorner.getX(), leftCorner.getY()));

Ellipse2D.Double circle =
new Ellipse2D.Double(
leftCorner.getX(),
leftCorner.getY(),
diameter,
diameter);
g2.draw(circle);
}
}

private Point2D.Double getLocation() {
double x = Math.random() * frameW / 2;
double y = Math.random() * frameH / 2;

return new Point2D.Double(x, y);
}
}

37 changes: 37 additions & 0 deletions RandomCirclesApplet.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@


import java.awt.EventQueue;

import javax.swing.JApplet;

//VS4E -- DO NOT REMOVE THIS LINE!
public class RandomCirclesApplet extends JApplet {

private static final long serialVersionUID = 1L;

public void init() {
try {
EventQueue.invokeAndWait(new Runnable() {

public void run() {
initComponents();
}
});
} catch (Exception ex) {
ex.printStackTrace();
}
}

private void initComponents() {
setSize(320, 240);

RandomCirclesComponent rc = new RandomCirclesComponent();
rc.setCircleCount(400);
rc.setFrameW(320);
rc.setFrameH(240);


getContentPane().add(rc);
}

}
44 changes: 44 additions & 0 deletions RandomCirclesComponent.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@


import java.awt.Graphics;
import java.awt.Graphics2D;

import javax.swing.JComponent;

public class RandomCirclesComponent extends JComponent{
private int frameW;
private int frameH;
private int circleCount;

public void paintComponent(Graphics g) {
Graphics2D g2 = (Graphics2D) g;
RandomCircles rc = new RandomCircles(circleCount, frameW, frameH);
rc.draw(g2);
}

public int getFrameW() {
return frameW;
}

public void setFrameW(int frameW) {
this.frameW = frameW;
}

public int getFrameH() {
return frameH;
}

public void setFrameH(int frameH) {
this.frameH = frameH;
}

public int getCircleCount() {
return circleCount;
}

public void setCircleCount(int circleCount) {
this.circleCount = circleCount;
}


}
Binary file added jars/MagicSquare.jar
Binary file not shown.
10 changes: 10 additions & 0 deletions jars/applets.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<HTML>
<BODY>
<applet codebase=http://bok.me/uploads/applets code=MagicSquareApplet

>
Your browser is not Java enabled.
</applet>

</BODY>
</HTML>
2 changes: 0 additions & 2 deletions manifest.xml

This file was deleted.

0 comments on commit f0f18d1

Please sign in to comment.