Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.awt.*;
- import java.awt.geom.*;
- import javax.swing.*;
- import java.lang.reflect.*;
- public class Circle extends JFrame {
- public Circle(){
- super("Circle");
- setSize(360, 540);
- setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- CirclePane pane = new CirclePane(90, 90, 100, "blue");
- add(pane);
- setVisible(true);
- }
- public static void main(String[] arguments){
- Circle cir = new Circle();
- }
- }
- class CirclePane extends JPanel {
- int radius, x, y;
- String color;
- Color actualColor;
- public CirclePane(int radius, int x, int y, String color){
- this.radius = radius;
- this.x = x;
- this.y = y;
- this.color = color;
- }
- public void paintComponent(Graphics comp){
- Graphics2D comp2D = (Graphics2D)comp;
- try {
- //actualColor = Color.decode(color);
- Field field = Class.forName("java.awt.Color").getField(color.toLowerCase()); // toLowerCase because the color fields are RED or red, not Red
- actualColor = (Color)field.get(null);
- comp2D.setColor(actualColor);
- Arc2D.Float circle = new Arc2D.Float(x, y, radius*2, radius*2, 0, 360, Arc2D.OPEN);
- comp2D.fill(circle);
- } catch (NumberFormatException|IllegalAccessException|ClassNotFoundException|NoSuchFieldException err){
- System.out.println("Error: " + err.getMessage());
- }
- }
- }
Add Comment
Please, Sign In to add comment