// ------------------------------------------------------------------------ // SCREEN PAINTER // Put some function here to paint whatever you want over the screen before and after // all edges and nodes have been painted. public void PaintScreenBefore(Graphics g) { Dimension d = MainClass.mainFrame.GetGraphDisplayPanel().getSize(); NodeInfo nodeInfo; int x = 0; int y = 0; int step = 10; for (; x < d.width; x += step) { for (y = 0; y < d.height; y += step) { double val = 0; double sum = 0; double total = 0; double min = 10000000; for (Enumeration nodes = proprietaryNodeInfo.elements(); nodes.hasMoreElements(); ) { nodeInfo = (NodeInfo) nodes.nextElement(); double dist = distance(x, y, nodeInfo.centerX, nodeInfo.centerY); if (nodeInfo.value != -1 && nodeInfo.nodeNumber.intValue() != 1) { // 121 if (dist < min) min = dist; val += ((double) nodeInfo.value) / dist / dist; sum += (1 / dist / dist); } } int reading = (int) (val / sum); reading = reading >> 2; if (reading > 255) reading = 255; g.setColor(new Color(reading, reading, reading)); g.fillRect(x, y, step, step); } } }
public void draw(Graphics g, ImageObserver ob) { if (!todraw) { g.setColor(bgcolor); g.drawRect(x, y, w + 2 * border, h + 2 * border); g.fillRect(x, y, w + 2 * border, h + 2 * border); return; } if (selected) g.setColor(selected_color); else g.setColor(unselected_color); g.drawRect(x, y, w + 2 * border, h + 2 * border); g.fillRect(x, y, w + 2 * border, h + 2 * border); g.drawImage(image[im], x + border, y + border, ob); // g.setColor(Color.black); // g.drawString("" + im,x+5,y+5); }
/** * This paints the entire plot. It calls the draw methods of all the attached axis and data sets. * The order of drawing is - Axis first, data legends next, data last. * * @params g Graphics state. */ public void paint(Graphics g) { int i; Graphics lg = g.create(); Rectangle r = bounds(); /* The r.x and r.y returned from bounds is relative to the ** parents space so set them equal to zero. */ r.x = 0; r.y = 0; if (DefaultBackground == null) DefaultBackground = this.getBackground(); if (DataBackground == null) DataBackground = this.getBackground(); // System.out.println("Graph2D paint method called!"); if (!paintAll) return; r.x += borderLeft; r.y += borderTop; r.width -= borderLeft + borderRight; r.height -= borderBottom + borderTop; paintFirst(lg, r); if (!axis.isEmpty()) r = drawAxis(lg, r); else { if (clearAll) { Color c = g.getColor(); g.setColor(DataBackground); g.fillRect(r.x, r.y, r.width, r.height); g.setColor(c); } drawFrame(lg, r.x, r.y, r.width, r.height); } paintBeforeData(lg, r); if (!dataset.isEmpty()) { datarect.x = r.x; datarect.y = r.y; datarect.width = r.width; datarect.height = r.height; for (i = 0; i < dataset.size(); i++) { ((DataSet) dataset.elementAt(i)).draw_data(lg, r); } } paintLast(lg, r); lg.dispose(); }
public void paint(Graphics g) { if (mainMenu) { drawTitleScreen(g); } else if (gamePlaying) { drawBricks(g); g.setColor(Color.green); g.fillRect(pad.x(), 590, pad.width(), 10); g.fillOval( ball.x_Pos() - ball.radius(), ball.y_Pos() - ball.radius(), ball.radius() * 2, ball.radius() * 2); } } // paint method
void drawBricks(Graphics g) { for (int x = 0; x < numBricksX; x++) { for (int y = 0; y < numBricksY; y++) { if (brickWall[x][y].notBroken()) { g.setColor(brickWall[x][y].colour()); g.fillRect( brickWall[x][y].brickX(), brickWall[x][y].brickY(), brickWall[x][y].brickWidth(), brickWall[x][y].brickHeight()); } } } }
public void paint(Graphics g) { Message("Copyright Feb, 2000 Weicon Conan Yuan.", "All Rights Reserved", 7); for (int i = 0; i < NUM_LOCATIONS; i++) { locs[i].draw(g, this); g.setColor(txtcolor); if (locs[i].ToDraw()) { g.drawString("" + i, locs[i].GetX(), locs[i].GetY() + 10); } } g.setColor(Color.red); g.drawRect(400, 200, 30, 30); g.fillRect(400, 200, 30, 30); Message("Cheat", 4); }
/** Update - Method, implements double buffering */ public void update(Graphics g) { // initialize buffer if (dbImage == null) { dbImage = createImage(this.getSize().width, this.getSize().height); dbg = dbImage.getGraphics(); } // clear screen in background dbg.setColor(getBackground()); dbg.fillRect(0, 0, this.getSize().width, this.getSize().height); // draw elements in background dbg.setColor(getForeground()); paint(dbg); // draw image on the screen g.drawImage(dbImage, 0, 0, this); }
public void Message(String s, int i) { Graphics g = getGraphics(); if (s == null) { g.setColor(bgcolor); g.drawRect(400, 50 * i - 10, 200, 10); g.fillRect(400, 50 * i - 10, 200, 10); return; } /* g.setColor(Color.blue); g.drawRect(400,50 * i - 10,200,10); g.fillRect(400,50 * i - 10,200,10); */ g.setColor(txtcolor); g.drawString(s, 400, 50 * i); }
/** * This method is called via the Graph2D.repaint() method. All it does is blank the canvas (with * the background color) before calling paint. */ public void update(Graphics g) { // System.out.println("Graph2d update method called"); if (clearAll) { Color c = g.getColor(); /* The r.x and r.y returned from bounds is relative to the ** parents space so set them equal to zero */ Rectangle r = bounds(); r.x = 0; r.y = 0; g.setColor(getBackground()); g.fillRect(r.x, r.y, r.width, r.height); g.setColor(c); } if (paintAll) paint(g); }
/** * Parse the text then draw it without any rotation. * * @param g Graphics context * @param x pixel position of the text * @param y pixel position of the text */ public void draw(Graphics g, int x, int y) { TextState ts; int xoffset = x; int yoffset = y; if (g == null || text == null) return; Graphics lg = g.create(); parseText(g); if (justification == CENTER) { xoffset = x - width / 2; } else if (justification == RIGHT) { xoffset = x - width; } if (background != null) { lg.setColor(background); lg.fillRect(xoffset, yoffset - ascent, width, height); lg.setColor(g.getColor()); } if (font != null) lg.setFont(font); if (color != null) lg.setColor(color); for (int i = 0; i < list.size(); i++) { ts = ((TextState) (list.elementAt(i))); if (ts.f != null) lg.setFont(ts.f); if (ts.s != null) lg.drawString(ts.toString(), ts.x + xoffset, ts.y + yoffset); } lg.dispose(); lg = null; }
/** * Draw the Axis. As each axis is drawn and aligned less of the canvas is avaliable to plot the * data. The returned Rectangle is the canvas area that the data is plotted in. */ protected Rectangle drawAxis(Graphics g, Rectangle r) { Axis a; int waxis; Rectangle dr; int x; int y; int width; int height; if (square) r = ForceSquare(g, r); dr = getDataRectangle(g, r); x = dr.x; y = dr.y; width = dr.width; height = dr.height; if (clearAll) { Color c = g.getColor(); g.setColor(DataBackground); g.fillRect(x, y, width, height); g.setColor(c); } // Draw a frame around the data area (If requested) if (frame) drawFrame(g, x, y, width, height); // Now draw the axis in the order specified aligning them with the final // data area. for (int i = 0; i < axis.size(); i++) { a = ((Axis) axis.elementAt(i)); a.data_window = new Dimension(width, height); switch (a.getAxisPos()) { case Axis.LEFT: r.x += a.width; r.width -= a.width; a.positionAxis(r.x, r.x, y, y + height); if (r.x == x) { a.gridcolor = gridcolor; a.drawgrid = drawgrid; a.zerocolor = zerocolor; a.drawzero = drawzero; } a.drawAxis(g); a.drawgrid = false; a.drawzero = false; break; case Axis.RIGHT: r.width -= a.width; a.positionAxis(r.x + r.width, r.x + r.width, y, y + height); if (r.x + r.width == x + width) { a.gridcolor = gridcolor; a.drawgrid = drawgrid; a.zerocolor = zerocolor; a.drawzero = drawzero; } a.drawAxis(g); a.drawgrid = false; a.drawzero = false; break; case Axis.TOP: r.y += a.width; r.height -= a.width; a.positionAxis(x, x + width, r.y, r.y); if (r.y == y) { a.gridcolor = gridcolor; a.drawgrid = drawgrid; a.zerocolor = zerocolor; a.drawzero = drawzero; } a.drawAxis(g); a.drawgrid = false; a.drawzero = false; break; case Axis.BOTTOM: r.height -= a.width; a.positionAxis(x, x + width, r.y + r.height, r.y + r.height); if (r.y + r.height == y + height) { a.gridcolor = gridcolor; a.drawgrid = drawgrid; a.zerocolor = zerocolor; a.drawzero = drawzero; } a.drawAxis(g); a.drawgrid = false; a.drawzero = false; break; } } return r; }
public void paint(Graphics g) { path = findOptimizedPath(srcID, dstID, type); /// Create the drawing board Dimension d = getSize(); g.setColor(Color.white); g.fillRect(1, 1, d.width - 2, d.height - 2); g.setColor(Color.black); g.drawRect(1, 1, d.width - 2, d.height - 2); g.setFont(serifFont); /// Draw the whole network, including all routers with /// delay and flow level, sources and destinations. int numR = 1; int w = 95; int h = d.height / 5; int pos = -1; for (int i = 0; i < 3; i++) { g.drawOval(w, h + 100 * i, 40, 40); g.drawString("S" + String.valueOf(i + 1), w + 13, h + 100 * i - 5); } for (int i = 0; i < 3; i++) { pos++; Router temp = statMux.getRouter(pos); g.drawOval(w + 110, h + 100 * i, 40, 40); g.drawString("R" + String.valueOf(numR++), w + 123, h + 100 * i - 5); g.drawString( String.valueOf(temp.getDelay() * temp.getPriority(type) + temp.getFlowLevel()), w + 125, h + 100 * i + 15); g.drawString(String.valueOf(temp.getFlowLevel()), w + 125, h + 100 * i + 35); } h = d.height / 11; for (int i = 0; i < 4; i++) { pos++; Router temp = statMux.getRouter(pos); g.drawOval(w + 210, h + 100 * i, 40, 40); g.drawString("R" + String.valueOf(numR++), w + 223, h + 100 * i - 5); g.drawString( String.valueOf(temp.getDelay() * temp.getPriority(type) + temp.getFlowLevel()), w + 225, h + 100 * i + 15); g.drawString(String.valueOf(temp.getFlowLevel()), w + 225, h + 100 * i + 35); } h = 20; for (int i = 0; i < 6; i++) { pos++; Router temp = statMux.getRouter(pos); g.drawOval(w + 310, h + 80 * i, 40, 40); g.drawString("R" + String.valueOf(numR++), w + 320, h + 80 * i - 5); g.drawString( String.valueOf(temp.getDelay() * temp.getPriority(type) + temp.getFlowLevel()), w + 325, h + 80 * i + 15); g.drawString(String.valueOf(temp.getFlowLevel()), w + 325, h + 80 * i + 35); } for (int i = 0; i < 4; i++) { g.drawOval(w + 410, d.height / 11 + 100 * i, 40, 40); g.drawString("D" + String.valueOf(i + 1), w + 423, d.height / 11 + 100 * i - 5); } g.setColor(Color.black); int[][] connection = statMux.getConnections(); /// Check buffer for connections at each step and draw links at layer1 for (int i = 0; i < connection[path[0] - 1].length; i++) { int temp = connection[path[0] - 1][i] - 3; g.drawLine(w + 40, (path[0]) * d.height / 5 + 20, w + 110, temp * d.height / 5 + 20); } /// Check buffer for connections at each step and draw links at layer2 for (int i = 0; i < connection[path[1] - 1].length; i++) { int temp = connection[path[1] - 1][i] - 7; g.drawLine( w + 150, (path[1] - 3) * d.height / 5 + 20, w + 210, (d.height / 11) + 100 * temp + 20); } /// Check buffer for connections at each step and draw links at layer3 for (int i = 0; i < connection[path[2] - 1].length; i++) { int temp = connection[path[2] - 1][i] - 11; g.drawLine(w + 250, (d.height / 11) + 100 * (path[2] - 7) + 20, w + 310, 80 * temp + 40); } /// Draw optimized path for packets traveling between source /// and destination h = d.height / 5; Graphics2D g2 = (Graphics2D) g; g2.setStroke(new BasicStroke(2)); g2.setColor(Color.red); g2.drawLine(w + 40, h * (path[0]) + 20, w + 110, h * (path[1] - 3) + 20); g2.drawLine( w + 150, h * (path[1] - 3) + 20, w + 210, (d.height / 11) + 100 * (path[2] - 7) + 20); g2.drawLine( w + 250, (d.height / 11) + 100 * (path[2] - 7) + 20, w + 310, 80 * (path[3] - 11) + 40); g2.drawLine( w + 350, 80 * (path[3] - 11) + 40, w + 410, (d.height / 11) + 100 * (path[4] - 17) + 20); /// Calculate and display loss, delay, and throughput delayTime = getDelay(path, type); throughPut = getThroughput(path); int numPackLost = getLossRate(numTransfer); lossRate = numPackLost / 100000.0 + 0.0005 * delayTime; delayVal.setText(String.format("%.2f", delayTime)); throuVal.setText(String.valueOf(throughPut)); lossVal.setText(String.format("%.4f", lossRate)); }
public void drawTitleScreen(Graphics g) { // color the screen g.setColor(Color.red); g.fillRect(posx_cursor - 5, posy_cursor - 5, 150, 50); g.fillRect(posx_cursor + 5, posy_cursor - 5, 150, 50); // Place the body of the drawing method here g.setColor(Color.white); g.setFont(new Font("Vineta BT", Font.ITALIC, 50)); g.drawString("SUPER", 125, 80); g.drawString("SMASH", 120, 130); g.drawString("BRICKS", 115, 180); g.setFont(new Font("Vineta BT", Font.PLAIN, 50)); g.drawString("SUPER", 125, 80); g.drawString("SMASH", 120, 130); g.drawString("BRICKS", 115, 180); g.setFont(new Font("Arial", Font.PLAIN, 20)); g.setColor(Color.white); g.fillRect(posx_new, posy_new, 150, 40); g.setColor(Color.black); g.fillRect(185, 255, 140, 30); g.setColor(Color.white); g.setFont(new Font("Imprint MT Shadow", Font.PLAIN, 20)); g.drawString("New Game", 205, 275); g.setColor(Color.white); g.fillRect(posx_diffi, posy_diffi, 150, 40); g.setColor(Color.black); g.fillRect(185, 305, 140, 30); g.setColor(Color.white); g.drawString("Difficulty", 215, 325); g.setColor(Color.white); g.fillRect(posx_controls, posy_controls, 150, 40); g.setColor(Color.black); g.fillRect(185, 355, 140, 30); g.setColor(Color.white); g.drawString("Controls", 217, 375); g.setColor(Color.white); g.fillRect(posx_credits, posy_credits, 150, 40); g.setColor(Color.black); g.fillRect(185, 405, 140, 30); g.setColor(Color.white); g.drawString("Credits", 222, 425); g.setColor(Color.white); g.fillRect(posx_highscores, posy_highscores, 150, 40); g.setColor(Color.black); g.fillRect(185, 455, 140, 30); g.setColor(Color.white); g.drawString("High Scores", 205, 475); g.setFont(new Font("Arial", Font.BOLD, 15)); g.setColor(Color.white); g.drawString("Instructions:", 218, 520); g.setFont(new Font("Arial", Font.PLAIN, 15)); g.drawString("Scroll to the appropriate button and hit [Enter] to continue.", 70, 535); g.drawString("Press [Esc] to return back to Main Menu.", 130, 550); }