// drawings in the graphic public void paint(Graphics g) { super.paint(g); // calling super class's constructor int x, y; // x,y values to use in fillRoundRect int counter; // Calculating the color to fill for each row and filling it for (int n = this.baseLength; n > 0; n--) { // Update the x,y values of top left corner of each block. This is done once per row x = this.startX + (10 - n) * (this.legoWidth / 2); y = this.startY - (10 - n) * (this.legoHeight); counter = 0; // set the counter to 0 for each row // below loop runs for each block in a given row while (counter < n) { // If the block is at odd numbered position, set color to fill as red, blue otherwise. Uses // ternary operator Color toFill = (counter % 2 == 0) ? Color.RED : Color.BLUE; // Set the color to the color calculated above and fill the rectangle with this color g.setColor(toFill); g.fillRoundRect(x, y, this.legoWidth, this.legoHeight, 2, 2); x = x + this.legoWidth; // Update x position of top left coordinate of each block counter++; // Update the counter } } }
// draw all the shapes on the list public void paint(Graphics g) { super.paint(g); // is no super.paint(), then lines stay on screen for (int i = 0; i < allTheShapesCount; i++) { allTheShapes[i].drawMe(g); } }
public void paint(Graphics g) { super.paint(g); Graphics2D g2d = (Graphics2D) g; g2d.draw( new Ellipse2D.Double( centerx - (centery - 500), centery - (centery - 500), 2 * (centery - 500), 2 * (centery - 500))); try { g2d.draw( new Ellipse2D.Double( player.x - player.size / 2, player.y - player.size / 2, player.size, player.size)); } catch (NullPointerException e) { } k = 1; while (k <= ballCount) { g2d.draw( new Ellipse2D.Double( ball[k].x - ball[k].size / 2, ball[k].y - ball[k].size / 2, ball[k].size, ball[k].size)); k++; } }
public void paintComponent(Graphics2D g) { super.paint(g); Tile.paintMap(g); Player.draw(g); GamePlayer.paintPlayers(g); Item.paint(g); }
@Override public void paint(Graphics g) { if (host.PaintCbk( PaintArgs.new_( GfxAdpBase.new_((Graphics2D) g), RectAdp_.Zero))) // ClipRect not used by any clients; implement when necessary super.paint(g); }
public void paint(Graphics g) { super.paint(g); g.setFont(fotn); Random generator1 = new Random(); height = bird.getBirdy(); g.drawImage(Backgroundtop, 0, 0, 450, 644, null); g.drawImage(Bird, 100, height, 40, 30, null); if (firstrun == true) { // intiate threads pipethread[currentthreads].start(); birdthread.start(); firstrun = false; } for (int index = 0; index <= currentthreads; index++) { g.drawImage(Pipes, pipeob[index].getpipex(), pipeob[index].getpipey(), null); } g.drawImage(Backgroundbottom, 0, 644, 450, 156, null); g.setColor(Color.black); if (pipeob[currentthreads].getpipex() <= 550) { currentthreads++; pipethread[currentthreads].start(); score++; } g.drawString("Score: " + score + "", 50, 50); for (int index = 0; index < currentthreads; index++) { if (((height < pipeob[index].getpipey() + 730) || (height > pipeob[index].getpipey() + 870)) && ((pipeob[index].getpipex() < 100) && (pipeob[index].getpipex() + 72 > 100)) || ((height < pipeob[index].getpipey() + 730) || (height > pipeob[index].getpipey() + 870)) && ((pipeob[index].getpipex() < 140) && (pipeob[index].getpipex() + 72 > 140)) || ((height + 30 < pipeob[index].getpipey() + 730) || (height + 30 > pipeob[index].getpipey() + 870)) && ((pipeob[index].getpipex() < 100) && (pipeob[index].getpipex() + 72 > 100)) || ((height + 30 < pipeob[index].getpipey() + 730) || (height + 30 > pipeob[index].getpipey() + 870)) && ((pipeob[index].getpipex() < 140) && (pipeob[index].getpipex() + 72 > 140)) || ((height + 30 >= 644))) { g.drawImage(gameover, 125, 200, null); JOptionPane.showMessageDialog( null, "You Dead. \n you scored " + score, "Oh no!", JOptionPane.INFORMATION_MESSAGE); } } for (int counter = 0; counter <= 50000000; counter++) { counter++; counter--; } do { repaint(); } while (replay = true); }
public void paint(Graphics g) { super.paint(g); // notebook(g); // colorGrid(g); // randomBoxes(g); // flower(g, 200, 200 ); // flower(g,300,350); // fieldOfFlowers(g); // randomWalk(g); Gasket(g); }
public void paint(Graphics g) { super.paint(g); g.setColor(Color.blue); g.drawRect(30, 80, 100, 140); int ms = Integer.parseInt(sp1.getValue().toString()); int mi = Integer.parseInt(sp2.getValue().toString()); g.setColor(Color.red); g.drawLine(30, 80 + ms, 130, 80 + ms); g.drawLine(30, 220 - mi, 130, 220 - mi); String direccion = (String) comboBox.getSelectedItem(); if (direccion.equals("Horizontal")) g.drawRect(320, 120, 200, 100); else g.drawRect(320, 120, 100, 200); }
@Override public void paint(Graphics g) { super.paint(g); StringBuffer sb = new StringBuffer(); sb.append("X="); sb.append(mouseX); sb.append(" Y="); sb.append(mouseY); sb.append(" code="); sb.append(KeyEvent.getKeyText(keyCode)); g.drawString(sb.toString(), 20, 90); }
@Override public synchronized void paint(Graphics g) { Double max = 0.0; try { super.paint(g); for (HashMap<String, String> v : this.Points) if (Math.abs(Double.parseDouble(v.get("y"))) > max) max = Math.abs(Double.parseDouble(v.get("y"))); if (max > 1.0) max = Math.ceil(max) + 1; wx = (Double) (Double.parseDouble(width + "") - (Double.parseDouble(offset_x + "") * 2)) / Double.parseDouble("" + this.Points.size()); wy = (Double) (Double.parseDouble(height + "") - (Double.parseDouble(offset_y + "") * 2)) / max; // Draw line for (int k = -(getSize().height - offset_y) / 2; k < (getSize().height - 2 * offset_y); k += (getSize().height - 2 * offset_y) / 9) { int y = k + offset_y + getSize().height / 2; DecimalFormat df = new DecimalFormat("#.######"); g.drawString(df.format((-1) * (double) (k) / (double) wy), 5, y); for (int i = offset_x - 10; i < (getSize().width - offset_x); i += (getSize().width - offset_x) * 0.01) g.drawString(".", i, y); } String p = "."; for (HashMap<String, String> v : this.Points) { int x = (int) Math.ceil(Double.parseDouble(v.get("x")) * wx + offset_x); int y = (int) Math.ceil(Double.parseDouble(v.get("y")) * wy + offset_y + getSize().height / 2); Color c; if (v.get("val").equals("0")) c = Color.RED; else if (v.get("val").equals("1")) c = Color.GREEN; else c = Color.BLACK; g.setColor(c); g.drawString(".", x, y); } } catch (Exception e) { System.out.println("Warning : " + e.getMessage()); } }
public void paint(Graphics g) { super.paint(g); if (screen.equalsIgnoreCase("title")) { MyPanel.score = 0; hs = new Highscore(); c.removeAll(); c.add(ts); panel = null; ts.revalidate(); } else if (screen.equalsIgnoreCase("instructions")) { c.removeAll(); c.add(instructions); instructions.revalidate(); } else if (screen.equalsIgnoreCase("mode")) { c.removeAll(); c.add(mode); mode.revalidate(); } else if (screen.equalsIgnoreCase("difficulty")) { c.removeAll(); c.add(dif); dif.revalidate(); } else if (screen.equalsIgnoreCase("highscore")) { if (hs.returnCount() == 0) { c.removeAll(); c.add(hs); c.validate(); } } else if (screen.equalsIgnoreCase("gameover")) { if (!once) { c.removeAll(); c.add(gg); once = true; c.validate(); } } else { if (once) { c.removeAll(); panel = new MyPanel(THA.WIDTH, THA.HEIGHT, ai, diff); c.setLayout(new BorderLayout()); c.add(panel.returnNs(), BorderLayout.WEST); c.add(panel, BorderLayout.CENTER); c.add(btns, BorderLayout.SOUTH); c.add(panel.returnAmmo(), BorderLayout.EAST); c.validate(); once = false; } } repaint(); }
@Override public void paint(Graphics g) { super.paint(g); Graphics2D g2 = (Graphics2D) g; g2.setColor(Color.red); float maxX = getSize().width; float maxY = getSize().height; Line2D.Float line = new Line2D.Float(0F, 0F, maxX, maxY); g2.draw(line); }
public void paint(Graphics g) { super.paint(g); int size = 130; g.drawLine( (Questions10.width - size) / 2 - 10, 160, (Questions10.width - size) / 2 + size + 10, 160); g.drawLine( (Questions10.width - size) / 2 - 10, 207, (Questions10.width - size) / 2 + size + 10, 207); g.drawLine((Questions10.width - size) / 2 - 10, 160, (Questions10.width - size) / 2 - 10, 207); g.drawLine( (Questions10.width - size) / 2 + size + 10, 160, (Questions10.width - size) / 2 + size + 10, 207); }
/** * ************************************************************************* CONCRETE Class::paint * Purpose: The paint() method is an overridden method inherited from JFrame that draws the * indicator on the screen. This method must be overridden so that various JRE services can update * the display. If you do not override paint, the indicator will not be consistiently drawn to the * screen and may have various graphics disappear at run time. This method is invoked indirectly * by the repaint() method. * * <p>Arguments: Graphics g this is the indicator's graphic instance. * * <p>Returns: none * * <p>Exceptions: none ************************************************************************** */ public void paint(Graphics g) { super.paint(g); FontMetrics fm = g.getFontMetrics(); int xLabelPosition = (int) (Height * 0.5) - (int) (fm.stringWidth(MessageLabel) * 0.5); int yLabelPosition = (int) (Height * 0.90); g.setColor(IluminationColor); g.fillRoundRect( (int) (Height * 0.15), (int) (Height * 0.35), (int) (Height * 0.70), (int) (Height * 0.40), (int) (Height * 0.20), (int) (Height * 0.20)); g.setColor(TextColor); g.drawString(MessageLabel, xLabelPosition, yLabelPosition); } // paint
public void paint(Graphics g) { super.paint(g); if (lastX > firstX && lastY > firstY && dragStatus) { int weightRec = (lastX > firstX) ? (lastX - firstX) : (firstX - lastX); int heightRec = (lastY > firstY) ? (lastY - firstY) : (firstY - lastY); g.drawRect(firstX, firstY, weightRec, heightRec); Color dragColor = new Color(255, 255, 255, 70); Color finishColor = new Color(0, 0, 0, 0); if (isPress) g.setColor(dragColor); else g.setColor(finishColor); g.fillRect(firstX, firstY, weightRec, heightRec); System.out.println("Draw Rec at X:" + firstX + ", Y:" + firstY); } }
@Override public void paint(Graphics g) { super.paint(g); for (int i = 0; i < images.size(); i++) { for (int j = 1; j < images.get(i).getPoints().size(); j++) { Point p1 = images.get(i).getPoints().get(j - 1); Point p2 = images.get(i).getPoints().get(j); if (images.get(i).isSelected() == true) { g.setColor(Color.RED); } else { g.setColor(Color.BLACK); } g.drawLine(p1.x, p1.y, p2.x, p2.y); // System.out.println("x: "+p1.x+" --> "+p2.x+" y: "+p1.y+" --> // "+p2.y); } } }
@Override public void paint(Graphics graphics) { super.paint(graphics); String msg = "I rule Frames!"; graphics.drawString(msg, 100, 100); }
public void animation(Graphics g) { super.paint(g); Graphics2D g2d = (Graphics2D) g; for (int y = 0; y <= mapy; y++) { for (int x = 0; x <= mapx; x++) { int L = x * size; int U = y * size; int R = size; int D = size; /// g2d.rotate(Math.toRadians(-90)); if (map[y][x] == 1) { // no black wall g2d.setColor(Color.green); g2d.fillRect(L, U, R, D); } else if (map[y][x] == 2) { // on left g2d.setColor(Color.green); g2d.fillRect(L, U, R, D); g2d.setColor(Color.black); g2d.fillRect(L - size / 2 + 2, U, 8, size); } else if (map[y][x] == 3) { // on right g2d.setColor(Color.green); g2d.fillRect(L, U, R, D); g2d.setColor(Color.black); g2d.fillRect(L + size, U, 8, size); } else if (map[y][x] == 4) { // on top g2d.setColor(Color.green); g2d.fillRect(L, U, R, D); g2d.setColor(Color.black); g2d.fillRect(L, U - size / 2 + 2, size, 8); } else if (map[y][x] == 5) { // on bottom g2d.setColor(Color.green); g2d.fillRect(L, U, R, D); g2d.setColor(Color.black); g2d.fillRect(L, U + size, size, 8); } else if (map[y][x] == 10) { // on bottom g2d.setColor(Color.green); g2d.fillRect(L, U, R, D); g2d.setColor(Color.black); g2d.fillRect(L, U - size / 2 + 2, size, 8); g2d.fillRect(L - size / 2 + 2, U, 8, size); } else if (map[y][x] == 11) { // on bottom g2d.setColor(Color.green); g2d.fillRect(L, U, R, D); g2d.setColor(Color.black); g2d.fillRect(L, U + size, size, 8); } else if (map[y][x] == 12) { // on bottom g2d.setColor(Color.green); g2d.fillRect(L, U, R, D); g2d.setColor(Color.black); g2d.fillRect(L, U + size, size, 8); } else if (map[y][x] == 13) { // on bottom g2d.setColor(Color.green); g2d.fillRect(L, U, R, D); g2d.setColor(Color.black); g2d.fillRect(L, U + size, size, 8); } } } g.drawImage(TestImage, cordX, cordY, 20, 20, this); }
public void paint(Graphics g) { g.drawImage(backgroundImage, 0, 0, this); super.paint(g); }
// JFrame.paint é um gancho da clase javax.swing.JFrame // ou seja, o template method tb foi utilizado aqui public void paint(Graphics graphics) { super.paint(graphics); String msn = "HELLO WORLD"; graphics.drawString(msn, 100, 100); }
@Override public void paint(Graphics g) { super.paint(g); Insets insets = getInsets(); imageIconProxy.paintIcon(this, g, insets.left, insets.top); }
/** * @param args the command line arguments * @throws java.lang.InterruptedException * @throws java.util.concurrent.BrokenBarrierException */ public static void main(String[] args) throws InterruptedException, BrokenBarrierException { int NTHREADS = Runtime.getRuntime().availableProcessors(); int m = 1000; int n = 1000; int steps = 1000; boolean graphics = false; boolean glider = false; int seed = 0; boolean seedBool = false, optimised = false; if (args.length == 9) { try { m = Integer.parseInt(args[0]); } catch (NumberFormatException e) { System.err.println("Argument" + args[0] + " must be an integer."); System.exit(1); } try { n = Integer.parseInt(args[1]); } catch (NumberFormatException e) { System.err.println("Argument" + args[1] + " must be an integer."); System.exit(1); } try { steps = Integer.parseInt(args[2]); } catch (NumberFormatException e) { System.err.println("Argument" + args[2] + " must be an integer."); System.exit(1); } try { optimised = Boolean.parseBoolean(args[3]); } catch (NumberFormatException e) { System.err.println("Argument" + args[3] + " must be a bool."); System.exit(1); } try { graphics = Boolean.parseBoolean(args[4]); } catch (NumberFormatException e) { System.err.println("Argument" + args[4] + " must be a bool."); System.exit(1); } try { glider = Boolean.parseBoolean(args[5]); } catch (NumberFormatException e) { System.err.println("Argument" + args[5] + " must be a bool."); System.exit(1); } try { NTHREADS = Integer.parseInt(args[6]); } catch (NumberFormatException e) { System.err.println("Argument" + args[6] + " must be an integer."); System.exit(1); } try { seedBool = Boolean.parseBoolean(args[7]); } catch (NumberFormatException e) { System.err.println("Argument" + args[7] + " must be a bool."); System.exit(1); } try { seed = Integer.parseInt(args[8]); } catch (NumberFormatException e) { System.err.println("Argument" + args[8] + " must be an integer."); System.exit(1); } } else { System.err.println("Ooops. Wrong parameters as arguments."); System.exit(1); } final Board board = new Board(m, n); Interval[] bounds = board.splitBoard(NTHREADS); if (glider) { board.initializeGlider(); } else { if (seedBool) board.initializeBoard(seed); else board.initializeBoard(); } if (graphics) { JFrame frame = new JFrame("Game of Life - Multithreaded"); Graphics g = frame.getGraphics(); frame.pack(); Insets insets = frame.getInsets(); frame.getContentPane().add(new GraphicBoard(board), BorderLayout.CENTER); frame.paint(g); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setSize(insets.left + insets.right + n, insets.top + insets.bottom + m); frame.setVisible(true); } final CyclicBarrier barrier = new CyclicBarrier(NTHREADS, board::swapBoards); ExecutorService threadPool = Executors.newFixedThreadPool(NTHREADS); final long startTime = System.currentTimeMillis(); for (int j = 0; j < NTHREADS; j++) { threadPool.execute(new Consumer(board, bounds[j].a, bounds[j].b, steps, barrier)); } threadPool.shutdown(); threadPool.awaitTermination(10, TimeUnit.MINUTES); final long endTime = System.currentTimeMillis(); System.out.println(endTime - startTime); System.exit(0); }
@Override public void paint(Graphics g) { super.paint(g); g.drawImage(content, 10, 40, this); }
public void paint(Graphics g) { super.paint(g); }