⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 chart.src

📁 一种实时操作系统
💻 SRC
📖 第 1 页 / 共 2 页
字号:
                                   } else if (rs.equals("gray")) {
                                       colors[i] = Color.gray;
                                   } else if (rs.equals("darkGray")) {
                                       colors[i] = Color.darkGray;
                                   } else {
                                       colors[i] = Color.gray;
                                   }
                               } else {
                                   colors[i] = Color.gray;
                               }
                           }
                           switch (orientation) {
                             case VERTICAL:
                             default:
                               barWidth = maxLabelWidth;
                               resize(Math.max(columns * (barWidth + barSpacing),
                                               titleFontMetrics.stringWidth(title)) +
                                      titleFont.getSize() + 5,
                                      (max * scale) + (2 * titleFont.getSize()) + 5 + titleFont.getSize());
                               break;
                             case HORIZONTAL:
                               barWidth = titleFont.getSize();
                               resize(Math.max((max * scale) + titleFontMetrics.stringWidth("" + max),
                                               titleFontMetrics.stringWidth(title)) + maxLabelWidth + 5,
                                      (columns * (barWidth + barSpacing)) + titleFont.getSize() + 10);
                               break;
                           }
                       }

                       public synchronized void paint(Graphics g) {
                           int i, j;
                           int cx, cy;
                           char l[] = new char[1];


                           // draw the title centered at the bottom of the bar graph
                           g.setColor(Color.black);
                           i = titleFontMetrics.stringWidth(title);
                           g.setFont(titleFont);
                           g.drawString(title, Math.max((size().width - i)/2, 0),
                                        size().height - titleFontMetrics.getDescent()); 
                           for (i=0; i < columns; i++) {
                               switch (orientation) {
                                 case VERTICAL:
                                 default:
                                   // set the next X coordinate to account for the label
                                   // being wider than the bar size().width.
                                   cx = (Math.max((barWidth + barSpacing),maxLabelWidth) * i) +
                                       barSpacing;

                                   // center the bar chart
                                   cx += Math.max((size().width - (columns *
                                                            (barWidth + (2 * barSpacing))))/2,0);
                                   
                                   // set the next Y coordinate to account for the size().height
                                   // of the bar as well as the title and labels painted
                                   // at the bottom of the chart.
                                   cy = size().height - (values[i] * scale) - 1 - (2 * titleFont.getSize());

                                   // draw the label
                                   g.setColor(Color.black);                
                                   g.drawString((String)labels[i], cx,
                                                size().height - titleFont.getSize() - titleFontMetrics.getDescent());

                                   // draw the shadow bar
                                   if (colors[i] == Color.black) {
                                       g.setColor(Color.gray);
                                   }
                                   g.fillRect(cx + 5, cy - 3, barWidth,  (values[i] * scale));
                                   // draw the bar with the specified color
                                   g.setColor((Color)(colors[i]));
                                   switch (styles[i]) {
                                     case SOLID:
                                     default:
                                       g.fillRect(cx, cy, barWidth, (values[i] * scale));
                                       break;
                                     case STRIPED:
                                       {
                                           int steps = (values[i] * scale) / 2;
                                           int ys;

                                           for (j=0; j < steps; j++) {
                                               ys = cy + (2 * j);
                                               g.drawLine(cx, ys, cx + barWidth, ys);
                                           }
                                       }
                                       break;
                                   }
                                   g.drawString("" + values[i],
                                                cx,
                                                cy - titleFontMetrics.getDescent());
                                   break;
                                 case HORIZONTAL:
                                   // set the Y coordinate
                                   cy = ((barWidth + barSpacing) * i) + barSpacing;
                                                  
                                   // set the X coordinate to be the size().width of the widest
                                   // label 
                                   cx = maxLabelWidth + 1;

                                   cx += Math.max((size().width - (maxLabelWidth + 1 +
                                                            titleFontMetrics.stringWidth("" +
                                                                                  max) +
                                                            (max * scale))) / 2, 0);
                                   // draw the labels and the shadow
                                   g.setColor(Color.black);                
                                   g.drawString((String)labels[i], cx - maxLabelWidth - 1,
                                                cy + titleFontMetrics.getAscent());
                                   if (colors[i] == Color.black) {
                                       g.setColor(Color.gray);
                                   }
                                   g.fillRect(cx + 3,
                                              cy + 5,
                                              (values[i] * scale),
                                              barWidth);

                                   // draw the bar in the current color
                                   g.setColor((Color)(colors[i]));
                                   switch (styles[i]) {
                                     case SOLID:
                                     default:
                                       g.fillRect(cx,
                                                  cy,
                                                  (values[i] * scale),
                                                  barWidth);
                                       break;
                                     case STRIPED:
                                       {
                                           int steps = (values[i] * scale) / 2;
                                           int ys;

                                           for (j=0; j < steps; j++) {
                                               ys = cx + (2 * j);
                                               g.drawLine(ys, cy, ys, cy + barWidth);
                                           }
                                       }
                                       break;
                                   }
                                   g.drawString("" + values[i],
                                                cx + (values[i] * scale) + 3,
                                                cy + titleFontMetrics.getAscent());
                                                
                                   break;
                               }
                           }
                       }
                   }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -