g.setColor(Color.lightGray); } else { g.setColor(getBackground()); g.fillOval(0, 0, getSize().width-1, getSize().height-1); !shape.getBounds().equals(getBounds())) { shape = new Ellipse2D.Float(0, 0, getWidth(), getHeight()); JFrame frame = new JFrame(); frame.getContentPane().setBackground(Color.yellow); frame.getContentPane().add(button); frame.getContentPane().setLayout(new FlowLayout()); frame.setSize(150, 150); frame.setVisible(true);
JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setLayout(new BorderLayout()); frame.add(new TestPane()); frame.pack(); Graphics2D g2d = buffer.createGraphics(); Ellipse2D circle = new Ellipse2D.Float(0, 0, radius, radius); Shape clip = g2d.getClip(); g2d.setClip(circle); AffineTransform at = g2d.getTransform(); g2d.setTransform(AffineTransform.getRotateInstance(Math.toRadians(33), radius / 2, radius / 2)); int gap = getWidth() / 10; g2d.draw(circle); g2d.dispose(); g.drawImage(buffer, x, y, this);
JFrame frame = new JFrame("Testing"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.add(new TestPane()); frame.pack(); frame.setLocationRelativeTo(null); frame.setVisible(true); repaint(); addMouseMotionListener(ma); addMouseListener(ma); protected void paintComponent(Graphics g) { super.paintComponent(g); Graphics2D g2d = (Graphics2D) g.create(); g2d.setColor(Color.RED); for (List<Point> group : points) { Point previous = null; g2d.fill(new Ellipse2D.Float(p.x - 2, p.y - 2, 4, 4)); if (previous != null) { g2d.draw(new Line2D.Float(previous, p)); g2d.dispose();
g.setColor(FILL_COLOR); g.fillRect(ins.left, ins.top, getWidth() - ins.left - ins.right, getHeight() - ins.top - ins.bottom); g.setColor(ColorUtil.setBrightness(FILL_COLOR,0.85f)); g.drawRect(ins.left, ins.top, getWidth() - ins.left - ins.right - 1, g2.setRenderingHint(KEY_ANTIALIASING, VALUE_ANTIALIAS_ON); g2.setColor(Color.LIGHT_GRAY); final int DIAM = Math.min(getWidth(), getHeight()); final int inset = 3; g2.fill(new Ellipse2D.Float(inset, inset, DIAM-2*inset, DIAM-2*inset)); g2.setColor(FILL_COLOR); final int border = 1; g2.fill(new Ellipse2D.Float(inset+border, inset+border, DIAM-2*inset-2*border, DIAM-2*inset-2*border)); } finally { g2.dispose();
public void actionPerformed(ActionEvent e) { number = (int) (Math.round((Math.random() * 5) + 1)); repaint(); g2d.setColor(Color.WHITE); g2d.fillRect(0, 0, width, height); g2d.setColor(Color.BLACK); g2d.drawRoundRect(10, 10, width - 20, height - 20, 50, 50); int x = (width - 20) / 2; int y = (height - 20) / 2; dots.add(new Ellipse2D.Float(x, y, 20, 20)); dots.add(new Ellipse2D.Float(x, y, 20, 20)); dots.add(new Ellipse2D.Float(x + (width / 2), y + (height / 2), 20, 20)); dots.add(new Ellipse2D.Float(x, y, 20, 20)); dots.add(new Ellipse2D.Float(x - (width / 2), y + (height / 2), 20, 20)); dots.add(new Ellipse2D.Float(x, y, 20, 20)); dots.add(new Ellipse2D.Float(x + (width / 2), y, 20, 20)); g2d.fill(dot);
JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setLayout(new BorderLayout()); frame.add(new TestPane()); frame.pack(); frame.setLocationRelativeTo(null); frame.setVisible(true); rh.put(RenderingHints.KEY_DITHERING,RenderingHints.VALUE_DITHER_ENABLE); rh.put(RenderingHints.KEY_COLOR_RENDERING,RenderingHints.VALUE_COLOR_RENDER_QUALITY); g2d.setRenderingHints(rh); Ellipse2D circle = new Ellipse2D.Float(0, 0, radius,radius); Shape clip = g2d.getClip(); g2d.setClip(circle); AffineTransform at = g2d.getTransform(); g2d.setTransform(AffineTransform.getRotateInstance(Math.toRadians(45),radius / 2, radius / 2)); g2d.setColor(Color.WHITE); g2d.fill(circle);
backgroundPane.setLayout(new BorderLayout()); backgroundPane.add(new TranslucentPane()); int x = (width - bg.getWidth()) / 2; int y = (height - bg.getHeight()) / 2; g.drawImage(bg, x, y, this); super.paintComponent(g); Rectangle fill = new Rectangle(getWidth(), getHeight()); Graphics2D g2d = (Graphics2D) g.create(); int y = (height - radius) / 2; Ellipse2D hole = new Ellipse2D.Float(x, y, radius, radius); g2d.setColor(getBackground()); g2d.fill(area); g2d.setColor(Color.RED); g2d.setComposite(AlphaComposite.SrcOver.derive(0.25f)); g2d.fill(hole); g2d.dispose();
JFrame frame = new JFrame("Testing"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setLayout(new BorderLayout()); frame.add(new TestPane()); frame.pack(); frame.setLocationRelativeTo(null); frame.setVisible(true); addMouseMotionListener(new MouseAdapter() { @Override public void mouseMoved(MouseEvent e) { mousePoint = e.getPoint(); repaint(); int y = (getHeight() - img.getHeight()) / 2; g2d.drawImage(img, x, y, this); Ellipse2D spot = new Ellipse2D.Float( (float) x - (RADIUS / 2f), (float) y - (RADIUS / 2f), area.subtract(new Area(spot)); g2d.setColor(Color.BLACK); g2d.fill(area);
JFrame frame = new JFrame("Test"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setLayout(new BorderLayout()); frame.add(new TestPane()); frame.pack(); frame.setLocationRelativeTo(null); frame.setVisible(true); protected void paintComponent(Graphics g) { super.paintComponent(g); Graphics2D g2d = (Graphics2D) g.create(); g2d.setRenderingHint(RenderingHints.KEY_ALPHA_INTERPOLATION, RenderingHints.VALUE_ALPHA_INTERPOLATION_QUALITY); g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g2d.setRenderingHint(RenderingHints.KEY_COLOR_RENDERING, RenderingHints.VALUE_COLOR_RENDER_QUALITY); g2d.setRenderingHint(RenderingHints.KEY_DITHERING, RenderingHints.VALUE_DITHER_ENABLE); g2d.setRenderingHint(RenderingHints.KEY_FRACTIONALMETRICS, RenderingHints.VALUE_FRACTIONALMETRICS_ON); alpha = 255 - Math.round(range * progress); Color color = new Color(0, 0, 0, alpha); g2d.setColor(color); int y = (getHeight() - radius) / 2; g2d.draw(new Ellipse2D.Float(x, y, radius, radius)); g2d.dispose();
frame = new JFrame(); frame.setBounds(100, 100, 512, 399); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); panel.setLayout(new BorderLayout()); panel.add(grafik); public void actionPerformed(ActionEvent arg0) { grafik.setEllipseVisible(true); panel.repaint(); btnPanel.add(btnNes); panel.add(btnPanel, BorderLayout.SOUTH); frame.setContentPane(panel); if (isEllipseVisible()) { Graphics2D g2 = (Graphics2D) g; g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); Ellipse2D circ = new Ellipse2D.Float(x, y, r, r); g2.setColor(Color.RED); g2.draw(circ);
JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setLayout(new BorderLayout()); frame.add(new TestPane()); frame.pack(); frame.setLocationRelativeTo(null); frame.setVisible(true); Ellipse2D circle = new Ellipse2D.Float(0, 0, radius, radius); Area lines = new Area(); g2d.setTransform(AffineTransform.getRotateInstance(Math.toRadians(45), radius / 2, radius / 2)); g2d.setRenderingHints(rh); g2d.setColor(Color.ORANGE); g2d.fill(linesCutToCircle); g2d.setColor(Color.RED); g2d.fill(circleNoLines); g2d.dispose(); g.drawImage(buffer, 0, 0, this);
setSize(300, 300); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setLocationRelativeTo(null); getContentPane().add(new DrawingPanel()); setVisible(true); saveComponentAsJPEG(this, "C:/test.jpg"); Dimension size = myComponent.getSize(); BufferedImage myImage = new BufferedImage(size.width, size.height, BufferedImage.TYPE_INT_RGB); Graphics2D g2 = myImage.createGraphics(); myComponent.paint(g2); try { OutputStream out = new FileOutputStream(filename); Graphics2D g2d = (Graphics2D) grphcs; RenderingHints rhints = g2d.getRenderingHints(); boolean antialiasOn = rhints.containsValue(RenderingHints.VALUE_ANTIALIAS_ON); g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); Shape circle = new Ellipse2D.Float(100.0f, 100.0f, 100.0f, 100.0f); g2d.setColor(Color.RED); g2d.draw(circle); g2d.fill(circle);
private final Shape secondShape = new Ellipse2D.Float(30, 30, 90, 50); private Shape selected = null; addMouseMotionListener(new MouseMotionAdapter() { @Override public void mouseDragged (MouseEvent event) { selectShapeUnder(event.getX(), event.getY()); addMouseListener(new MouseAdapter() { @Override public void mousePressed (MouseEvent event) { selectShapeUnder(event.getX(), event.getY()); graphics.setColor((selected == firstShape) ? Color.YELLOW : Color.RED); graphics.fill(firstShape); graphics.setColor((selected == secondShape) ? Color.YELLOW : Color.GREEN); graphics.fill(secondShape); selected = null; if (selected != oldSelected) repaint(); SwingUtilities.invokeLater(new Runnable() { @Override public void run () { JFrame frame = new JFrame("Shape Select"); frame.getContentPane().add(new ShapeSelect(), BorderLayout.CENTER); frame.pack(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setLocationRelativeTo(null); frame.setVisible(true);
this.img = image; setLayout(new GridBagLayout()); add(new JButton(new StartAction("Start", KeyEvent.VK_S))); Shape shape = new Ellipse2D.Float(0, 0, w, h); AWTUtilities.setWindowShape(window, shape); AWTUtilities.setWindowOpaque(window, false); super.paintComponent(g); if (img != null) { g.drawImage(img, 0, 0, this); if (isPreferredSizeSet() || img == null) { return super.getPreferredSize(); window.dispose(); JFrame frame = new JFrame(); frame.setUndecorated(true); URL imgUrl = MainPanelOvalFrame.class.getResource(RESOURCE_PATH); MainPanelOvalFrame mainPanel = new MainPanelOvalFrame(frame, image);
JFrame frame = new JFrame("Testing"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.add(new FishBowel()); frame.pack(); frame.setLocationRelativeTo(null); frame.setVisible(true); protected void paintComponent(Graphics g) { super.paintComponent(g); Graphics2D g2d = (Graphics2D) g.create(); for (Fish fish : fishes) { fish.paint(g2d); g2d.dispose(); fish = new Ellipse2D.Float(bounds.x, bounds.y, bounds.width, bounds.height); g2d.setColor(getColor()); g2d.fill(fish);
JFrame f = new JFrame("Test"); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.add(new JPanel() { private static final int N = 8; private final Ellipse2D ellipse = new Ellipse2D.Float(); super.paintComponent(g); Graphics2D g2d = (Graphics2D) g; g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g2d.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, RenderingHints.VALUE_STROKE_PURE); g2d.setStroke(new BasicStroke(N)); ellipse.setFrame(N, N, getWidth() - 2 * N, getHeight() - 2 * N); g2d.draw(ellipse); f.pack(); f.setLocationRelativeTo(null); f.setVisible(true);
JFrame frame = new JFrame("FlatteningPathIterator test"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); Shape s=new Ellipse2D.Float(10,10,200,100); PaintPanel app = new PaintPanel(s); JScrollPane scroll = new JScrollPane(app); frame.getContentPane().add(scroll); frame.setSize(400, 300); frame.setLocationRelativeTo(null); frame.setVisible(true); index=0; repaint(); super.paintComponent(g); g.setColor(Color.blue); Point p=points.get(index); g.fillOval(p.x, p.y, 5,5);
super(label); setSize(width, height); public void actionPerformed(ActionEvent e) { System.out.println("klick"); setSize(new Dimension(width--, height--)); System.out.println(width + " " + height); g.setColor(Color.RED); } else { g.setColor(Color.yellow); g.fillOval(0, 0, getSize().width - 1, getSize().height - 1); if (shape == null || !shape.getBounds().equals(getBounds())) { shape = new Ellipse2D.Float(0, 0, getWidth(), getHeight()); f = new JFrame(); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.setLocationRelativeTo(null); f.setSize(200, 200); f.add(new test2("label")); f.setLayout(new BorderLayout()); f.setVisible(true);
this.setSize(300, 300); this.setDefaultCloseOperation(EXIT_ON_CLOSE); this.add(new CirclePanel(diameter)); this.setVisible(true); public void paintComponent(Graphics g) { int panelWidth = this.getSize().width; int panelHeight = this.getSize().height; comp2D.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); comp2D.setStroke(new BasicStroke(1f)); comp2D.setPaint(Color.white); Ellipse2D.Float e1 = new Ellipse2D.Float((panelWidth / 2) - (diameter / 2), (panelHeight / 2) - (diameter / 2), diameter, diameter); comp2D.draw(e1);
protected void paintComponent(Graphics g) { super.paintComponent(g); circle = new Ellipse2D.Float(100, 20, width, height); Graphics2D graphics = (Graphics2D)g.create(); graphics.draw(circle); JSlider slider = (JSlider)e.getSource(); width = slider.getValue(); drawPane.repaint(); JSlider slider = (JSlider)e.getSource(); height = slider.getValue(); drawPane.repaint(); content.add(widthSlider, BorderLayout.NORTH); content.add(drawPane, BorderLayout.CENTER); content.add(heightSlider, BorderLayout.WEST); JFrame frame = new JFrame("Demo"); frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); frame.setContentPane(content); frame.pack(); frame.setLocationRelativeTo(null); frame.setVisible(true);