package net.havercan.geometry2D; import javax.swing.*; import java.awt.*; import java.awt.geom.*; public class ShowCircle extends JApplet { private DrawCanvas canvas; private Graphics2D g; private Ellipse2D.Double circle; public ShowCircle() {canvas = new DrawCanvas(); canvas.setPreferredSize(new Dimension(600, 400)); this.setContentPane(canvas); circle = new Ellipse2D.Double(); } private class DrawCanvas extends JPanel {@Override public void paint(Graphics g0) {double circle_r = 128.0; double circle_x = 0.5*this.getWidth(); double circle_y = 0.5*this.getHeight(); g = (Graphics2D)g0; super.paintComponent(g); circle.setFrame(circle_x-circle_r, circle_y-circle_r, 2.0*circle_r, 2.0*circle_r); setBackground(Color.WHITE); g.setColor(Color.BLUE); g.fill(circle); } } public static void main(String[] args) {SwingUtilities.invokeLater (new Runnable() {@Override public void run() {JApplet ja = new ShowCircle(); JFrame jf = new JFrame(); jf.add(ja); jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); jf.setTitle("Java Swing 2d Circle demonstration"); jf.pack(); jf.setVisible(true); } } ); } public void init() {try {javax.swing.SwingUtilities.invokeAndWait(new Runnable() {public void run() {new ShowCircle();}});} catch(Exception e) {System.err.println("ShowCircle applet did not initialize: "+e.getMessage());} } }