List of usage examples for java.awt Graphics fillOval
public abstract void fillOval(int x, int y, int width, int height);
From source file:MainClass.java
public void paint(Graphics g) { Graphics2D g2 = (Graphics2D) g; RenderingHints rh = g2.getRenderingHints(); rh.put(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g2.setRenderingHints(rh);//from w w w . j a v a2s .co m int x = 40, y = 40; g.setColor(Color.red); g.fillOval(x, y, 50, 50); Composite old = g2.getComposite(); g2.setComposite(AlphaComposite.getInstance(AlphaComposite.DST_IN)); g.setColor(Color.green); g.fillOval(x + 30, y + 30, 30, 30); g2.setComposite(old); g.setColor(Color.black); g.drawString("AlphaComposite.DST_IN", x, y + 80); }
From source file:MainClass.java
public void paint(Graphics g) { Graphics2D g2 = (Graphics2D) g; RenderingHints rh = g2.getRenderingHints(); rh.put(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g2.setRenderingHints(rh);// w w w. j a v a 2s . co m int x = 40, y = 40; g.setColor(Color.red); g.fillOval(x, y, 50, 50); Composite old = g2.getComposite(); g2.setComposite(AlphaComposite.getInstance(AlphaComposite.DST_OVER)); g.setColor(Color.green); g.fillOval(x + 30, y + 30, 30, 30); g2.setComposite(old); g.setColor(Color.black); g.drawString("AlphaComposite.DST_OVER", x, y + 80); }
From source file:MainClass.java
public void paint(Graphics g) { Graphics2D g2 = (Graphics2D) g; RenderingHints rh = g2.getRenderingHints(); rh.put(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g2.setRenderingHints(rh);/*from w ww. jav a 2s. c o m*/ int x = 40, y = 40; g.setColor(Color.red); g.fillOval(x, y, 50, 50); Composite old = g2.getComposite(); g2.setComposite(AlphaComposite.getInstance(AlphaComposite.CLEAR)); g.setColor(Color.green); g.fillOval(x + 30, y + 30, 30, 30); g2.setComposite(old); g.setColor(Color.black); g.drawString("AlphaComposite.CLEAR", x, y + 80); }
From source file:MyCanvas.java
public void paintComponent(Graphics g) { super.paintComponent(g); // draw entire component white g.setColor(Color.white);/*from w w w.jav a 2s . com*/ g.fillRect(0, 0, getWidth(), getHeight()); // yellow circle g.setColor(Color.yellow); g.fillOval(0, 0, 240, 240); // magenta circle g.setColor(Color.magenta); g.fillOval(160, 160, 240, 240); // paint the icon below blue sqaure int w = java2sLogo.getIconWidth(); int h = java2sLogo.getIconHeight(); java2sLogo.paintIcon(this, g, 280 - (w / 2), 120 - (h / 2)); // paint the icon below red sqaure java2sLogo.paintIcon(this, g, 120 - (w / 2), 280 - (h / 2)); // transparent red square g.setColor(m_tRed); g.fillRect(60, 220, 120, 120); // transparent green circle g.setColor(m_tGreen); g.fillOval(140, 140, 120, 120); // transparent blue square g.setColor(m_tBlue); g.fillRect(220, 60, 120, 120); g.setColor(Color.black); g.setFont(monoFont); FontMetrics fm = g.getFontMetrics(); w = fm.stringWidth("Java Source"); h = fm.getAscent(); g.drawString("Java Source", 120 - (w / 2), 120 + (h / 4)); g.setFont(sanSerifFont); fm = g.getFontMetrics(); w = fm.stringWidth("and"); h = fm.getAscent(); g.drawString("and", 200 - (w / 2), 200 + (h / 4)); g.setFont(serifFont); fm = g.getFontMetrics(); w = fm.stringWidth("Support."); h = fm.getAscent(); g.drawString("Support.", 280 - (w / 2), 280 + (h / 4)); }
From source file:ColorsBeanInfo.java
public void paint(Graphics g) { Dimension d = getSize();//from w ww . j a v a 2s.c o m 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:com.jcraft.weirdx.Draw.java
private static void drawThickLine(Graphics graphics, int x1, int y1, int x2, int y2, int linewidth) { --linewidth;/*from ww w .ja v a 2s . c om*/ int lw2 = linewidth / 2; graphics.fillOval(x1 - lw2, y1 - lw2, linewidth, linewidth); if (x1 == x2 && y1 == y2) return; if (Math.abs(x2 - x1) > Math.abs(y2 - y1)) { int dy, srow; int dx, col, row, prevrow; if (x2 > x1) dx = 1; else dx = -1; dy = (y2 - y1) * 8192 / Math.abs(x2 - x1); prevrow = row = y1; srow = row * 8192 + 8192 / 2; col = x1; while (true) { if (row != prevrow) { graphics.drawOval(col - lw2, prevrow - lw2, linewidth, linewidth); prevrow = row; } graphics.drawOval(col - lw2, row - lw2, linewidth, linewidth); if (col == x2) break; srow += dy; row = srow / 8192; col += dx; } } else { int dx, scol; int dy, col, row, prevcol; if (y2 > y1) dy = 1; else dy = -1; dx = (x2 - x1) * 8192 / Math.abs(y2 - y1); row = y1; prevcol = col = x1; scol = col * 8192 + 8192 / 2; while (true) { if (col != prevcol) { graphics.drawOval(prevcol - lw2, row - lw2, linewidth, linewidth); prevcol = col; } graphics.drawOval(col - lw2, row - lw2, linewidth, linewidth); if (row == y2) break; row += dy; scol += dx; col = scol / 8192; } } }
From source file:com.google.code.facebook.graph.sna.applet.DrawnIconVertexDemo.java
public DrawnIconVertexDemo() { // create a simple graph for the demo graph = new DirectedSparseGraph<Integer, Number>(); Integer[] v = createVertices(10); createEdges(v);/*from w ww .j a va2s . c om*/ vv = new VisualizationViewer<Integer, Number>(new FRLayout<Integer, Number>(graph)); vv.getRenderContext().setVertexLabelTransformer(new Transformer<Integer, String>() { public String transform(Integer v) { return "Vertex " + v; } }); vv.getRenderContext().setVertexLabelRenderer(new DefaultVertexLabelRenderer(Color.cyan)); vv.getRenderContext().setEdgeLabelRenderer(new DefaultEdgeLabelRenderer(Color.cyan)); vv.getRenderContext().setVertexIconTransformer(new Transformer<Integer, Icon>() { /* * Implements the Icon interface to draw an Icon with background color and * a text label */ public Icon transform(final Integer v) { return new Icon() { public int getIconHeight() { return 20; } public int getIconWidth() { return 20; } public void paintIcon(Component c, Graphics g, int x, int y) { if (vv.getPickedVertexState().isPicked(v)) { g.setColor(Color.yellow); } else { g.setColor(Color.red); } g.fillOval(x, y, 20, 20); if (vv.getPickedVertexState().isPicked(v)) { g.setColor(Color.black); } else { g.setColor(Color.white); } g.drawString("" + v, x + 6, y + 15); } }; } }); vv.getRenderContext().setVertexFillPaintTransformer( new PickableVertexPaintTransformer<Integer>(vv.getPickedVertexState(), Color.white, Color.yellow)); vv.getRenderContext().setEdgeDrawPaintTransformer( new PickableEdgePaintTransformer<Number>(vv.getPickedEdgeState(), Color.black, Color.lightGray)); vv.setBackground(Color.white); // add my listener for ToolTips vv.setVertexToolTipTransformer(new ToStringLabeller<Integer>()); // create a frome to hold the graph final JFrame frame = new JFrame(); Container content = frame.getContentPane(); final GraphZoomScrollPane panel = new GraphZoomScrollPane(vv); content.add(panel); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); final ModalGraphMouse gm = new DefaultModalGraphMouse<Integer, Number>(); vv.setGraphMouse(gm); final ScalingControl scaler = new CrossoverScalingControl(); JButton plus = new JButton("+"); plus.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { scaler.scale(vv, 1.1f, vv.getCenter()); } }); JButton minus = new JButton("-"); minus.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { scaler.scale(vv, 1 / 1.1f, vv.getCenter()); } }); JPanel controls = new JPanel(); controls.add(plus); controls.add(minus); controls.add(((DefaultModalGraphMouse<Integer, Number>) gm).getModeComboBox()); content.add(controls, BorderLayout.SOUTH); frame.pack(); frame.setVisible(true); }
From source file:edu.uci.ics.jung.samples.DrawnIconVertexDemo.java
@SuppressWarnings("unchecked") public DrawnIconVertexDemo() { // create a simple graph for the demo graph = new DirectedSparseGraph<Integer, Number>(); Integer[] v = createVertices(10); createEdges(v);//from www. j av a 2s . c o m vv = new VisualizationViewer<Integer, Number>(new FRLayout<Integer, Number>(graph)); vv.getRenderContext().setVertexLabelTransformer(new Transformer<Integer, String>() { public String transform(Integer v) { return "Vertex " + v; } }); vv.getRenderContext().setVertexLabelRenderer(new DefaultVertexLabelRenderer(Color.cyan)); vv.getRenderContext().setEdgeLabelRenderer(new DefaultEdgeLabelRenderer(Color.cyan)); vv.getRenderContext().setVertexIconTransformer(new Transformer<Integer, Icon>() { /* * Implements the Icon interface to draw an Icon with background color and * a text label */ public Icon transform(final Integer v) { return new Icon() { public int getIconHeight() { return 20; } public int getIconWidth() { return 20; } public void paintIcon(Component c, Graphics g, int x, int y) { if (vv.getPickedVertexState().isPicked(v)) { g.setColor(Color.yellow); } else { g.setColor(Color.red); } g.fillOval(x, y, 20, 20); if (vv.getPickedVertexState().isPicked(v)) { g.setColor(Color.black); } else { g.setColor(Color.white); } g.drawString("" + v, x + 6, y + 15); } }; } }); vv.getRenderContext().setVertexFillPaintTransformer( new PickableVertexPaintTransformer<Integer>(vv.getPickedVertexState(), Color.white, Color.yellow)); vv.getRenderContext().setEdgeDrawPaintTransformer( new PickableEdgePaintTransformer<Number>(vv.getPickedEdgeState(), Color.black, Color.lightGray)); vv.setBackground(Color.white); // add my listener for ToolTips vv.setVertexToolTipTransformer(new ToStringLabeller<Integer>()); // create a frome to hold the graph final JFrame frame = new JFrame(); Container content = frame.getContentPane(); final GraphZoomScrollPane panel = new GraphZoomScrollPane(vv); content.add(panel); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); final ModalGraphMouse gm = new DefaultModalGraphMouse<Integer, Number>(); vv.setGraphMouse(gm); final ScalingControl scaler = new CrossoverScalingControl(); JButton plus = new JButton("+"); plus.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { scaler.scale(vv, 1.1f, vv.getCenter()); } }); JButton minus = new JButton("-"); minus.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { scaler.scale(vv, 1 / 1.1f, vv.getCenter()); } }); JPanel controls = new JPanel(); controls.add(plus); controls.add(minus); controls.add(((DefaultModalGraphMouse<Integer, Number>) gm).getModeComboBox()); content.add(controls, BorderLayout.SOUTH); frame.pack(); frame.setVisible(true); }
From source file:ColorVariousObjects.java
public void paint(Graphics g) { Color c1 = new Color(255, 100, 100); Color c2 = new Color(100, 255, 100); Color c3 = new Color(100, 100, 255); g.setColor(c1);//from w w w . j a va2 s. com g.drawLine(0, 0, 100, 100); g.drawLine(0, 100, 100, 0); g.setColor(c2); g.drawLine(40, 25, 250, 180); g.drawLine(75, 90, 400, 400); g.setColor(c3); g.drawLine(20, 150, 400, 40); g.drawLine(5, 290, 80, 19); g.setColor(Color.red); g.drawOval(10, 10, 50, 50); g.fillOval(70, 90, 140, 100); g.setColor(Color.blue); g.drawOval(190, 10, 90, 30); g.drawRect(10, 10, 60, 50); g.setColor(Color.cyan); g.fillRect(100, 10, 60, 50); g.drawRoundRect(190, 10, 60, 50, 15, 15); }
From source file:com.cburch.logisim.circuit.appear.AppearancePort.java
@Override public void paint(Graphics g, HandleGesture gesture) { Location location = getLocation(); int x = location.getX(); int y = location.getY(); g.setColor(COLOR);/*from w w w . j a va2s . co m*/ if (isInput()) { int r = INPUT_RADIUS; g.drawRect(x - r, y - r, 2 * r, 2 * r); } else { int r = OUTPUT_RADIUS; g.drawOval(x - r, y - r, 2 * r, 2 * r); } g.fillOval(x - MINOR_RADIUS, y - MINOR_RADIUS, 2 * MINOR_RADIUS, 2 * MINOR_RADIUS); }