The fillOval
fits an oval inside a rectangle, with width=r, height = r
you get a circle. If you want fillOval(x,y,r,r)
to draw a circle with the center at (x,y) you will have to displace the rectangle by half its width and half its height.
public void drawCenteredCircle(Graphics2D g, int x, int y, int r) { x = x-(r/2); y = y-(r/2); g.fillOval(x,y,r,r); }
This will draw a circle with center at x,y
Related Posts:
- Java Exception in thread “AWT-EventQueue-0” java.lang.NullPointerException
- How do I draw a triangle?
- How do I draw a triangle?
- How to add an image to a JPanel?
- How to repaint a JPanel after have drawn on it?
- addMouseListener for a JPanel
- How does addNotify() and requestFocus() work in Java with JPanel?
- Adding JPanel to JFrame
- What does .pack() do?
- How does paintComponent work?
- How change the color arrowIcon to JMenu when it is selected
- Getting a HeadlessException: No X11 DISPLAY variable was set
- error upon assigning Layout: BoxLayout can’t be shared
- Java: Rotating Images
- JOptionPane YES NO OPTION
- Java: Difference between the setPreferredSize() and setSize() methods in components
- What does “AL lib: alc_cleanup: 1 device not closed” mean?
- Java GUI: about getContentPane( ) method and content
- How to center the text in a JLabel?
- Implementing an actionlistener to a JTextField
- How to Set JPanel’s Width and Height?
- Swing/Java: How to use the getText and setText string properly
- What does super.paintComponent(g) do?
- How to Set the Background Color of a JButton on the Mac OS
- Popup Message boxes
- Exception in thread “AWT-EventQueue-0”?
- make a JLabel wrap it’s text by setting a max width
- Keylistener not working for JPanel
- setMnemonic() and call a method by pressing the key
- the getSource() and getActionCommand()
- How to programmatically close a JFrame
- DTO and DAO concepts and MVC
- Adding image to JFrame
- How to Retrieve value from JTextField in Java Swing?
- Setting background color for a JFrame
- Setting background images in JFrame
- Java Swing revalidate() vs repaint()
- How can I set size of a button?
- Java Swing setting JPanel Size
- JOptionPane Yes or No window
- How to format strings in Java
- What exactly is Apache Camel?
- What is an instance variable in Java?
- Cannot make a static reference to the non-static method fxn(int) from the type Two
- How to implement a tree data-structure in Java?
- Difference between StringBuilder and StringBuffer
- How can I use pointers in Java?
- A long bigger than Long.MAX_VALUE
- How to remove single character from a String
- Unsupported major.minor version 52.0 [duplicate]
- How do I limit the number of decimals printed for a double?
- Unfortunately MyApp has stopped. How can I solve this?
- exception in thread ‘main’ java.lang.NoClassDefFoundError:
- java.io.FileNotFoundException: the system cannot find the file specified
- :: (double colon) operator in Java 8
- What does ‘0’ do in Java?
- Service will not start: error 1067: the process terminated unexpectedly
- Explain the use of a bit vector for determining if all characters are unique
- Convert java.util.Date to String
- How do I do a deep copy of a 2d array in Java?
- Returning an empty array
- What does “?” mean in Java? [duplicate]
- What is the difference between a local variable, an instance field, an input parameter, and a class field?
- Error: Selection does not contain a main type
- Java, “Variable name” cannot be resolved to a variable
- JRE 1.7 – java version – returns: java/lang/NoClassDefFoundError: java/lang/Object
- Good Hash Function for Strings
- Error – Illegal static declaration in inner class
- Bubble Sort Manually a Linked List in Java
- Checking Password Code
- java – how to create and manipulate a bit array with length of 10 million bits
- What is the difference between object-oriented languages and non object-oriented languages?
- Installing jdk8 on ubuntu- “unable to locate package” update doesn’t fix
- Java – Access is denied java.io.FileNotFoundException
- Static Block in Java
- What does Scanner input = new Scanner(System.in) actually mean?
- Class ‘Room’ is abstract; cannot be instantiated
- mongoDB, connection refused
- Displaying Image in Java
- How to check the input is an integer or not in Java?
- How to read and write XML files?
- Why am i getting ” Duplicate modifier for the type Test” and how to fix it
- How to make PopUp window in java
- Picked up _JAVA_OPTIONS: -Xmx256M
- When to use static methods
- How to serialize an object into a string
- Printing array elements with a for loop
- How to implement a most-recently-used cache
- Cannot be resolved to a variable error in Eclipse
- JAVA_HOME is set to an invalid directory:
- Using JavaFX in JRE 8, “Access restriction” error
- Get Mouse Position
- What is object serialization?
- How do I use StringUtils in Java?
- Error :- java runtime environment JRE or java development kit must be available in order to run eclipse
- How to set menu to Toolbar in Android
- How to implement Java “Scanner” in C++?
- Occurrences of substring in a string
- Maven dependency update on commandline
- The import javax.servlet can’t be resolved