List of usage examples for java.awt Graphics fillRect
public abstract void fillRect(int x, int y, int width, int height);
From source file:com.aistor.common.servlet.ValidateCodeServlet.java
private void createBackground(Graphics g) { // //from w ww. j a v a2 s . c o m g.setColor(getRandColor(220, 250)); g.fillRect(0, 0, w, h); // ? for (int i = 0; i < 10; i++) { g.setColor(getRandColor(40, 150)); Random random = new Random(); int x = random.nextInt(w); int y = random.nextInt(h); int x1 = random.nextInt(w); int y1 = random.nextInt(h); g.drawLine(x, y, x1, y1); } }
From source file:apm.common.servlet.ValidateCodeServlet.java
private void createBackground(Graphics g) { // /*from ww w . j a va 2s .c o m*/ g.setColor(getRandColor(220, 250)); g.fillRect(0, 0, w, h); // ? for (int i = 0; i < 8; i++) { g.setColor(getRandColor(40, 150)); Random random = new Random(); int x = random.nextInt(w); int y = random.nextInt(h); int x1 = random.nextInt(w); int y1 = random.nextInt(h); g.drawLine(x, y, x1, y1); } }
From source file:TextBox3D.java
public synchronized void paint(Graphics g) { FontMetrics fm = g.getFontMetrics(); Dimension size = getSize();//from w ww . j av a 2s. co m int x = (size.width - fm.stringWidth(text)) / 2; int y = (size.height - fm.getHeight()) / 2; g.setColor(SystemColor.control); g.fillRect(0, 0, size.width, size.height); g.setColor(SystemColor.controlShadow); g.drawLine(0, 0, 0, size.height - 1); g.drawLine(0, 0, size.width - 1, 0); g.setColor(SystemColor.controlDkShadow); g.drawLine(0, size.height - 1, size.width - 1, size.height - 1); g.drawLine(size.width - 1, 0, size.width - 1, size.height - 1); g.setColor(SystemColor.controlText); g.drawString(text, x, y); }
From source file:Clock.java
public void paintComponent(Graphics g) { super.paintComponent(g); Color colorRetainer = g.getColor(); g.setColor(getBackground());/*ww w. j av a 2s . c o m*/ g.fillRect(0, 0, getWidth(), getHeight()); getBorder().paintBorder(this, g, 0, 0, getWidth(), getHeight()); calendar.setTime(new Date()); // get current time int hrs = calendar.get(Calendar.HOUR_OF_DAY); int min = calendar.get(Calendar.MINUTE); g.setColor(getForeground()); if (isDigital) { String time = "" + hrs + ":" + min; g.setFont(getFont()); FontMetrics fm = g.getFontMetrics(); int y = (getHeight() + fm.getAscent()) / 2; int x = (getWidth() - fm.stringWidth(time)) / 2; g.drawString(time, x, y); } else { int x = getWidth() / 2; int y = getHeight() / 2; int rh = getHeight() / 4; int rm = getHeight() / 3; double ah = ((double) hrs + min / 60.0) / 6.0 * Math.PI; double am = min / 30.0 * Math.PI; g.drawLine(x, y, (int) (x + rh * Math.sin(ah)), (int) (y - rh * Math.cos(ah))); g.drawLine(x, y, (int) (x + rm * Math.sin(am)), (int) (y - rm * Math.cos(am))); } g.setColor(colorRetainer); }
From source file:ColorSource.java
public void paintComponent(Graphics g) { g.setColor(color);/*from www . java 2 s. c o m*/ Dimension s = this.getSize(); Insets i = this.getInsets(); g.fillRect(i.left, i.top, s.width - i.left - i.right, s.height - i.top - i.bottom); }
From source file:painting.IconDisplayer.java
protected void paintComponent(Graphics g) { if (isOpaque()) { //paint background g.setColor(getBackground());/*from w w w .j a va 2s .co m*/ g.fillRect(0, 0, getWidth(), getHeight()); } if (icon != null) { //Draw the icon over and over, right aligned. Insets insets = getInsets(); int iconWidth = icon.getIconWidth(); int iconX = getWidth() - insets.right - iconWidth; int iconY = insets.top; boolean faded = false; //Copy the Graphics object, which is actually //a Graphics2D object. Cast it so we can //set alpha composite. Graphics2D g2d = (Graphics2D) g.create(); //Draw the icons, starting from the right. //After the first one, the rest are faded. //We won't bother painting icons that are clipped. g.getClipBounds(clipRect); while (iconX >= insets.left) { iconRect.setBounds(iconX, iconY, iconWidth, icon.getIconHeight()); if (iconRect.intersects(clipRect)) { icon.paintIcon(this, g2d, iconX, iconY); } iconX -= (iconWidth + pad); if (!faded) { g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.1f)); faded = true; } } g2d.dispose(); //clean up } }
From source file:ColorsBeanInfo.java
public void paint(Graphics g) { Dimension d = getSize();//from www. j a v a2s .com int h = d.height; int w = d.width; g.setColor(color); if (rectangular) { g.fillRect(0, 0, w - 1, h - 1); } else { g.fillOval(0, 0, w - 1, h - 1); } }
From source file:OptimalPrimitives.java
protected void paintComponent(Graphics g) { Graphics2D g2d = (Graphics2D) g; long startTime, endTime, totalTime; g.setColor(Color.WHITE);/*from w w w . j a v a2 s . co m*/ g.fillRect(0, 0, getWidth(), getHeight()); g.setColor(Color.BLACK); g.drawString("Bad vs. Good Primitive Rendering", 50, 20); g.drawString("(" + ITERATIONS + " iterations)", 100, 35); g.drawString("Bad: ", 10, BAD_Y + 30); g.drawString("Good: ", 10, GOOD_Y + 30); // Bad line Shape line = new Line2D.Double(LINE_X, BAD_Y, LINE_X + 50, BAD_Y + 50); startTime = System.nanoTime(); for (int i = 0; i < ITERATIONS; ++i) { g2d.draw(line); } endTime = System.nanoTime(); totalTime = (endTime - startTime) / 1000000; System.out.println("bad line = " + totalTime); g.drawString(totalTime + " ms", LINE_X, BAD_Y + 70); // Good line startTime = System.nanoTime(); for (int i = 0; i < ITERATIONS; ++i) { g.drawLine(LINE_X, GOOD_Y, LINE_X + 50, GOOD_Y + 50); } endTime = System.nanoTime(); totalTime = (endTime - startTime) / 1000000; System.out.println("good line = " + totalTime); g.drawString(totalTime + " ms", LINE_X, GOOD_Y + 70); // Bad rect Shape rect = new Rectangle(RECT_X, BAD_Y, 50, 50); startTime = System.nanoTime(); for (int i = 0; i < ITERATIONS; ++i) { g2d.fill(rect); } endTime = System.nanoTime(); totalTime = (endTime - startTime) / 1000000; System.out.println("bad rect = " + totalTime); g.drawString(totalTime + " ms", RECT_X, BAD_Y + 70); // Good rect startTime = System.nanoTime(); for (int i = 0; i < ITERATIONS; ++i) { g.fillRect(RECT_X, GOOD_Y, 50, 50); } endTime = System.nanoTime(); totalTime = (endTime - startTime) / 1000000; System.out.println("good rect = " + totalTime); g.drawString(totalTime + " ms", RECT_X, GOOD_Y + 70); }
From source file:IconDisplayer.java
protected void paintComponent(Graphics g) { if (isOpaque()) { //paint background g.setColor(getBackground());/*from www . jav a2 s .c om*/ g.fillRect(0, 0, getWidth(), getHeight()); } if (icon != null) { //Draw the icon over and over, right aligned. Insets insets = getInsets(); int iconWidth = icon.getIconWidth(); int iconX = getWidth() - insets.right - iconWidth; int iconY = insets.top; boolean faded = false; //Copy the Graphics object, which is actually //a Graphics2D object. Cast it so we can //set alpha composite. Graphics2D g2d = (Graphics2D) g.create(); //Draw the icons, starting from the right. //After the first one, the rest are faded. //We won't bother painting icons that are clipped. g.getClipBounds(clipRect); while (iconX >= insets.left) { iconRect.setBounds(iconX, iconY, iconWidth, icon.getIconHeight()); if (iconRect.intersects(clipRect)) { icon.paintIcon(this, g2d, iconX, iconY); } iconX -= (iconWidth + pad); if (!faded) { g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.1f)); faded = true; } } g2d.dispose(); //clean up } }
From source file:MultiBufferTest.java
public MultiBufferTest(int numBuffers, GraphicsDevice device) { try {/* w ww . ja v a 2 s. c o m*/ GraphicsConfiguration gc = device.getDefaultConfiguration(); mainFrame = new Frame(gc); mainFrame.setUndecorated(true); mainFrame.setIgnoreRepaint(true); device.setFullScreenWindow(mainFrame); if (device.isDisplayChangeSupported()) { chooseBestDisplayMode(device); } Rectangle bounds = mainFrame.getBounds(); mainFrame.createBufferStrategy(numBuffers); BufferStrategy bufferStrategy = mainFrame.getBufferStrategy(); for (float lag = 2000.0f; lag > 0.00000006f; lag = lag / 1.33f) { for (int i = 0; i < numBuffers; i++) { Graphics g = bufferStrategy.getDrawGraphics(); if (!bufferStrategy.contentsLost()) { g.setColor(COLORS[i]); g.fillRect(0, 0, bounds.width, bounds.height); bufferStrategy.show(); g.dispose(); } try { Thread.sleep((int) lag); } catch (InterruptedException e) { } } } } catch (Exception e) { e.printStackTrace(); } finally { device.setFullScreenWindow(null); } }