示例#1
0
 public static DrawingPanel background(String meaning) {
   DrawingPanel panel = new DrawingPanel(780, 560);
   Graphics g = panel.getGraphics();
   panel.setBackground(Color.white);
   g.setColor(Color.LIGHT_GRAY);
   g.fillRect(0, 0, 781, bannerHeight);
   g.fillRect(0, 530, 781, bannerHeight);
   g.setColor(Color.black);
   g.drawString(meaning, 0, 16);
   for (int i = startYear; i <= 2010; i += 10) {
     g.drawString("" + i, (decadeWidth / 10) * (i - startYear), 552);
   }
   return panel;
 }
示例#2
0
 public static void bars(DrawingPanel panel, String nameInfo) {
   Graphics g = panel.getGraphics();
   Scanner s = new Scanner(nameInfo);
   s.next(); // skips name
   String gender = s.next();
   for (int i = startYear; i <= 2010; i += 10) {
     g.setColor(Color.BLACK);
     int rank = s.nextInt();
     int x = ((decadeWidth / 10) * (i - startYear));
     int y = 30 + (rank / 2);
     if (rank == 0) y = 560 - bannerHeight;
     g.drawString("" + rank, x, y);
     if (gender.equals("f")) g.setColor(Color.pink);
     else g.setColor(Color.blue);
     g.fillRect(x, y, decadeWidth / 2, 560 - bannerHeight - y);
   }
   s.close();
 }