importjava.awt.*;importjavax.swing.JApplet;publicclassCanzhuoextendsJApplet{publicDinnerc1,c2,c3,c4,c5,c6,c7;intnum=-1;publicvoidinit(){Dinnerc1=newDinner("1",'男');Dinne...
import java.awt.*;
import javax.swing.JApplet;
public class Canzhuo extends JApplet
{ public Dinner c1,c2,c3,c4,c5,c6,c7;
int num = -1;
public void init() {
Dinner c1 = new Dinner("1", '男');
Dinner c2 = new Dinner("2", '女');
Dinner c3 = new Dinner("3", '女');
Dinner c4 = new Dinner("4", '男');
Dinner c5 = new Dinner("5", '女');
Dinner c6 = new Dinner("6", '男');
Dinner c7 = new Dinner("7", '女');
// public static
setBackground(Color.black); //设置背景色
}
public void paint(Graphics page) {
super.paint(page);
final int MIDX = 400;
final int MIDY = 400;
int midx,midy;
page.setColor(Color.blue);
page.fillOval(MIDX - 100, MIDY - 100, 200, 200);
c1.draw(page);
c2.draw(page);
c3.draw(page);
c4.draw(page);
c5.draw(page);
c6.draw(page);
c7.draw(page);
}
class Dinner {
String name;
char sex;
int sate;
Dinner(String s, char c) { //构造方法
name = s;
sex = c;
num++;
sate = num;
}
public void draw(Graphics page) { //画每个人的座位...
int midx, midy;
double alfa = 360 * sate / num;
if (sex == '男') {
page.setColor(Color.blue);
}
else {
page.setColor(Color.red);
}
midx = MIDX + (int) (150 * Math.cos(alfa));
midy = MIDY + (int) (150 * Math.sin(alfa));
page.fillRect(midx - 20, midy - 20, 40, 40);
page.setFont(new Font("隶书", Font.BOLD, 30)); //设置字型为隶书粗体
page.setColor(Color.yellow);
page.drawString(name, midx - 15, midy - 15);
}
}
}
展开