マルチメディアコンピューティングU
オプション課題
import java.applet.*;
import java.awt.*;
public class Illumination extends Applet {
Switch sw1,sw2;
int on1=0, on2=0;
public void init() {
setBackground(Color.black);
sw1=new Switch(this, 1000);
sw1.start();
sw2=new Switch(this, 2000);
sw2.start();
}
public void click(Switch sw) {
if(sw==sw1) {
if(on1 == 0) on1=1;
else on1=0;
};
if(sw==sw2) {
if(on2 == 0) on2=1;
else on2=0;
};
repaint();
}
public void paint(Graphics g) {
if(on1==1) g.setColor(Color.red);
else g.setColor(Color.black);
g.fillOval(100,90,20,20);
if(on2==1) g.setColor(Color.green);
else g.setColor(Color.black);
g.fillOval(200,90,20,20);
}
}
class Switch extends Thread {
int Interval;
Illumination ilum;
Switch(Illumination p1, int p2) {
ilum = p1;
Interval = p2;
}
public void run() {
int i;
for( i=0; i<10000; ++i) {
try {
Thread.sleep(Interval);
}
catch(InterruptedException e) {
}
ilum.click(this);
}
}
}

import java.applet.*;
import java.awt.*;
import java.awt.geom.*;
public class graphicsg13 extends Applet
{
public void paint(Graphics g)
{
Graphics2D g2=(Graphics2D)g;
Area e1=new Area(new Ellipse2D.Double(100,200,50,100));
g2.setColor(Color.white);
g2.fill(e1);
AffineTransform affine=new AffineTransform();
affine.rotate(-45.0*Math.PI/180.0, 125, 200);
g2.setTransform(affine);
g2.setColor(Color.blue);
g2.fill(e1);
}
}

import java.applet.*;
import java.awt.*;
public class nakawari extends Applet implements Runnable {
Thread th;
int[] x;
int[] y;
double[] xa = {10.0, 100.0, 10.0}; /* 始まりの図形 */
double[] ya = {10.0, 10.0, 300.0};
double[] xb = {110.0, 200.0, 200.0}; /* 終わりの図形 */
double[] yb = {100.0, 100.0, 300.0};
int c=0;
public void init() {
x= new int[3];
y= new int[3];
}
public void start() {
th= new Thread(this);
th.start();
}
public void run() {
int x;
for( x=0; x<10000; ++x) {
repaint();
try {
Thread.sleep(100);
}
catch(InterruptedException e) {
}
}
}
public void paint(Graphics g) {
int i;
for(i=0; i<3; i++) {
x[i]=(int)(xa[i] + (c/100.0)*(xb[i]-xa[i]));
y[i]=(int)(ya[i] + (c/100.0)*(yb[i]-ya[i]));
}
g.setColor(Color.red);
g.fillPolygon(x, y, 3);
c++;
if(c==101) c=0;
}
}

2004.1.9