Registration

Dear SAP Community Member,
In order to fully benefit from what the SAP Community has to offer, please register at:
http://scn.sap.com
Thank you,
The SAP Community team.
The SAP Community wiki will be closed to new content submissions from December 7 6:00 p.m. CET to December 11 6:00 p.m. CET.
All content created during this period will not be available/restorable after December 11.
We apologize for the inconvenience, but we need to take this action to improve and maintain the SAP Community wiki performance.
Please plan your tasks accordingly.
Skip to end of metadata
Go to start of metadata
package com.hcl.java.tutor;
//tutorial
/*
* The Java Graphics class draws a circle with drawOval(),
* It uses a point at the top left of an imaginary
* bounding rectangle and the width and height.
* The programme below shows how can we draw circle using
* a center point and a radius instead of the the standard
* parameters of drawOval()
*/
import java.awt.*;
import javax.swing.*;
public class Circle extends JFrame{
CirclePanel drawing = new CirclePanel();
Circle() {
//--- Get content pane, set layout, add components
Container content = this.getContentPane();
content.setLayout(new BorderLayout());
content.add(drawing, BorderLayout.CENTER); // Note 2
this.setTitle("Circles");
this.pack(); // finalize the layout
}//
public static void main(String[] args) {
JFrame myWindow = new Circle();
myWindow.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
myWindow.setVisible(true);
}
}
class CirclePanel extends JPanel {
//=========================================== constructor
public CirclePanel() {
setPreferredSize(new Dimension(100, 100));
setBackground(Color.white);
}//end constructor
//=========================================== paintComponent
public void paintComponent(Graphics g) {
super.paintComponent(g);
drawCircle(g, 30, 30, 20); // center (30,30) r=20
}
// Convenience method to draw from center with radius
public void drawCircle(Graphics cg, int xCenter, int yCenter, int r) {
cg.drawOval(xCenter-r, yCenter-r, 2*r, 2*r);
}//end drawCircle
}