Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.awt.*;
- public class Dinner {
- private String name;
- private String sex;
- private int number;
- public Dinner(int number,String name,String sex){
- this.number=number;
- this.name=name;
- this.sex=sex;
- }
- public int getNumber(){
- return number;
- }
- public String getName(){
- return name;
- }
- public String getSex(){
- return sex;
- }
- public void setNumber(int number){
- this.number=number;
- }
- public void setName(String name){
- this.name=name;
- }
- public void setSex(String sex){
- this.sex=sex;
- }
- public void draw(Graphics g){
- //判断性别判断圆圈颜色
- if(sex.equals("male"))
- g.setColor(Color.blue);
- else if(sex.equals("female"))
- g.setColor(Color.red);
- //判断序号判断圆圈位置
- int x,y;
- final int MID=50;
- final int TOP=50;
- if(number==1){
- g.fillOval(MID, TOP, 30, 30);//绘制园
- g.setColor(Color.black);//重新设置颜色
- g.drawString(name, MID, TOP);//输出字符串name的内容
- }else if(number==2){
- g.setColor(Color.blue);
- g.fillOval(MID+100, TOP, 30, 30);
- }
- /* switch(number){
- case 1:
- x=MID;
- y=TOP;
- g.fillOval(x,y,30,30);
- g.setColor(Color.black);
- g.drawString(name, x, y);
- break;
- case 2:
- x=MID+100;
- y=TOP;
- g.fillOval(x,y,30,30);
- g.drawString(name, x, y);
- break;
- case 3:
- x=MID+200;
- y=TOP;
- g.fillOval(x,y,30,30);
- g.drawString(name, x, y);
- break;
- case 4:
- x=MID;
- y=TOP+100;
- g.fillOval(x,y,30,30);
- g.drawString(name, x, y);
- break;
- case 5:
- x=MID+100;
- y=TOP+100;
- g.fillOval(x,y,30,30);
- g.drawString(name, x, y);
- break;
- case 6:
- x=MID+200;
- y=TOP+100;
- g.fillOval(x,y,30,30);
- g.drawString(name, x, y);
- break;
- }
- */
- }
- }
Add Comment
Please, Sign In to add comment