This repository has been archived by the owner on Dec 16, 2017. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
bok.chan
committed
Apr 16, 2011
1 parent
ddc9a22
commit f0f18d1
Showing
6 changed files
with
137 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file was deleted.
Oops, something went wrong.