List of usage examples for java.awt Graphics2D draw
public abstract void draw(Shape s);
From source file:BasicDraw.java
public void paint(Graphics g) { Graphics2D g2d = (Graphics2D) g; Color startColor = Color.red; Color endColor = Color.blue; int startX = 10, startY = 20, endX = 30, endY = 40; GradientPaint gradient = new GradientPaint(startX, startY, startColor, endX, endY, endColor); g2d.setPaint(gradient);/* ww w . j av a2 s . c o m*/ g2d.draw(new Rectangle(20, 20, 200, 200)); }
From source file:net.sf.mzmine.modules.visualization.tic.TICPlotRenderer.java
protected void drawFirstPassShape(Graphics2D g2, int pass, int series, int item, Shape shape) { g2.setComposite(makeComposite(transparency)); g2.setStroke(getItemStroke(series, item)); g2.setPaint(getItemPaint(series, item)); g2.draw(shape); }
From source file:DrawTest.java
public void paintComponent(Graphics g) { Graphics2D g2 = (Graphics2D) g; // draw a rectangle double leftX = 100; double topY = 100; double width = 200; double height = 150; Rectangle2D rect = new Rectangle2D.Double(leftX, topY, width, height); g2.draw(rect); // draw the enclosed ellipse Ellipse2D ellipse = new Ellipse2D.Double(); ellipse.setFrame(rect);//from ww w .ja v a 2s .co m g2.draw(ellipse); // draw a diagonal line g2.draw(new Line2D.Double(leftX, topY, leftX + width, topY + height)); // draw a circle with the same center double centerX = rect.getCenterX(); double centerY = rect.getCenterY(); double radius = 150; Ellipse2D circle = new Ellipse2D.Double(); circle.setFrameFromCenter(centerX, centerY, centerX + radius, centerY + radius); g2.draw(circle); }
From source file:MainClass.java
public int print(Graphics g, PageFormat pf, int pageIndex) { if (pageIndex != 0) return NO_SUCH_PAGE; Graphics2D g2 = (Graphics2D) g; g2.setFont(new Font("Serif", Font.PLAIN, 36)); g2.setPaint(Color.black);//from w w w. j ava2 s.c o m g2.drawString("www.java2s.com", 100, 100); Rectangle2D outline = new Rectangle2D.Double(pf.getImageableX(), pf.getImageableY(), pf.getImageableWidth(), pf.getImageableHeight()); g2.draw(outline); return PAGE_EXISTS; }
From source file:Main.java
@Override protected void paintComponent(Graphics g) { super.paintComponent(g); Graphics2D g2d = (Graphics2D) g.create(); if (myImage != null) { int x = (getWidth() - myImage.getWidth()) / 2; int y = (getHeight() - myImage.getHeight()) / 2; g2d.drawImage(myImage, x, y, this); g2d.setColor(Color.RED);//from www. ja v a2s . co m g2d.translate(x, y); g2d.draw(myOffice); } g2d.dispose(); }
From source file:CombiningShapes.java
public void paintComponent(Graphics g) { Graphics2D g2 = (Graphics2D) g; g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); String option = (String) mOptions.getSelectedItem(); if (option.equals("outline")) { // draw the outlines and return. g2.draw(mShapeOne); g2.draw(mShapeTwo);/*from w w w . jav a 2 s . c o m*/ return; } // Create Areas from the shapes. Area areaOne = new Area(mShapeOne); Area areaTwo = new Area(mShapeTwo); // Combine the Areas according to the selected option. if (option.equals("add")) areaOne.add(areaTwo); else if (option.equals("intersection")) areaOne.intersect(areaTwo); else if (option.equals("subtract")) areaOne.subtract(areaTwo); else if (option.equals("exclusive or")) areaOne.exclusiveOr(areaTwo); // Fill the resulting Area. g2.setPaint(Color.orange); g2.fill(areaOne); // Draw the outline of the resulting Area. g2.setPaint(Color.black); g2.draw(areaOne); }
From source file:MainClass.java
public int print(Graphics g, PageFormat pf, int pageIndex) throws PrinterException { // pageIndex 0 corresponds to page number 1. if (pageIndex >= 1) return Printable.NO_SUCH_PAGE; PrinterGraphics p = (PrinterGraphics) g; System.out.println(p.getPrinterJob().getCopies()); System.out.println(p.getPrinterJob().getJobName()); Graphics2D g2 = (Graphics2D) g; double w = pf.getImageableWidth(); double h = pf.getImageableHeight(); int xo = (int) pf.getImageableX(); int yo = (int) pf.getImageableY(); Rectangle2D r = new Rectangle2D.Double(xo, yo, w, h); g2.setColor(Color.red);/*from w w w . j a va 2 s. com*/ g2.draw(r); Shape s = new Ellipse2D.Double(xo + 4, yo + 4, 32, 32); g2.fill(s); return Printable.PAGE_EXISTS; }
From source file:org.evors.rs.kjunior.SimulatedKJunior.java
@Override public void render(Graphics2D g2) { g2.setStroke(bstroke);/*ww w. j a v a 2 s . com*/ g2.setColor(Color.RED); float[] input = getInput(); for (int i = 0; i < NUM_IRs; i++) { Line IR = Line.fromPolarVec(getIRBase(irAngles[i]), irAngles[i], input[i]); g2.draw(IR.toLine2D()); } g2.setColor(new Color(45, 45, 45)); g2.fill(getShape().toJava2DShape()); }
From source file:MainClass.java
public int print(Graphics g, PageFormat pf, int pageIndex) throws PrinterException { System.out.println("Page index = " + pageIndex); // pageIndex 1 corresponds to page number 2. if (pageIndex > 2) return Printable.NO_SUCH_PAGE; Graphics2D g2 = (Graphics2D) g; double w = pf.getImageableWidth(); double h = pf.getImageableHeight(); int xo = (int) pf.getImageableX(); int yo = (int) pf.getImageableY(); Rectangle2D r = new Rectangle2D.Double(xo, yo, w, h); g2.setColor(Color.red);/* w w w . j a v a 2 s . c o m*/ g2.draw(r); return Printable.PAGE_EXISTS; }
From source file:MainClass.java
public int print(Graphics g, PageFormat pf, int pageIndex) throws PrinterException { Graphics2D g2 = (Graphics2D) g; double w = pf.getImageableWidth(); double h = pf.getImageableHeight(); int xo = (int) pf.getImageableX(); int yo = (int) pf.getImageableY(); Rectangle2D r = new Rectangle2D.Double(xo, yo, w, h); g2.setColor(Color.red);//from w ww . j a va2 s .c o m g2.draw(r); PrinterGraphics p = (PrinterGraphics) g2; String s = p.getPrinterJob().getJobName(); g2.setPaint(Color.black); g2.drawString(s, 0, 0); return Printable.PAGE_EXISTS; }