Guest User

Untitled

a guest
Feb 11th, 2019
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.78 KB | None | 0 0
  1.  
  2. import java.awt.*;
  3.  
  4. public class Dinner {
  5.  
  6. private String name;
  7. private String sex;
  8. private int number;
  9.  
  10. public Dinner(int number,String name,String sex){
  11.  
  12. this.number=number;
  13. this.name=name;
  14. this.sex=sex;
  15. }
  16.  
  17. public int getNumber(){
  18. return number;
  19. }
  20. public String getName(){
  21. return name;
  22. }
  23. public String getSex(){
  24. return sex;
  25. }
  26.  
  27. public void setNumber(int number){
  28. this.number=number;
  29. }
  30. public void setName(String name){
  31. this.name=name;
  32. }
  33. public void setSex(String sex){
  34. this.sex=sex;
  35. }
  36.  
  37. public void draw(Graphics g){
  38.  
  39. //判断性别判断圆圈颜色
  40. if(sex.equals("male"))
  41. g.setColor(Color.blue);
  42. else if(sex.equals("female"))
  43. g.setColor(Color.red);
  44.  
  45. //判断序号判断圆圈位置
  46. int x,y;
  47. final int MID=50;
  48. final int TOP=50;
  49.  
  50. if(number==1){
  51. g.fillOval(MID, TOP, 30, 30);//绘制园
  52. g.setColor(Color.black);//重新设置颜色
  53. g.drawString(name, MID, TOP);//输出字符串name的内容
  54. }else if(number==2){
  55. g.setColor(Color.blue);
  56. g.fillOval(MID+100, TOP, 30, 30);
  57. }
  58. /* switch(number){
  59. case 1:
  60. x=MID;
  61. y=TOP;
  62. g.fillOval(x,y,30,30);
  63. g.setColor(Color.black);
  64. g.drawString(name, x, y);
  65. break;
  66. case 2:
  67. x=MID+100;
  68. y=TOP;
  69. g.fillOval(x,y,30,30);
  70. g.drawString(name, x, y);
  71. break;
  72. case 3:
  73. x=MID+200;
  74. y=TOP;
  75. g.fillOval(x,y,30,30);
  76. g.drawString(name, x, y);
  77. break;
  78. case 4:
  79. x=MID;
  80. y=TOP+100;
  81. g.fillOval(x,y,30,30);
  82. g.drawString(name, x, y);
  83. break;
  84. case 5:
  85. x=MID+100;
  86. y=TOP+100;
  87. g.fillOval(x,y,30,30);
  88. g.drawString(name, x, y);
  89. break;
  90. case 6:
  91. x=MID+200;
  92. y=TOP+100;
  93. g.fillOval(x,y,30,30);
  94. g.drawString(name, x, y);
  95. break;
  96. }
  97. */
  98. }
  99.  
  100. }
Add Comment
Please, Sign In to add comment