Draw circles in swing..

hello.
I'm making a program that draws circles in a frame and has some buttons in another program.
However, there are some stack overflow errors..
help please~
[error messages]
Exception in thread "main" java.lang.StackOverflowError
at java.util.Hashtable.get(Hashtable.java:336)
at javax.swing.UIDefaults.getFromHashtable(UIDefaults.java:142)
at javax.swing.UIDefaults.get(UIDefaults.java:130)
at javax.swing.MultiUIDefaults.get(MultiUIDefaults.java:44)
at javax.swing.UIDefaults.getColor(UIDefaults.java:380)
at javax.swing.UIManager.getColor(UIManager.java:590)
at javax.swing.LookAndFeel.installColors(LookAndFeel.java:58)
at javax.swing.LookAndFeel.installColorsAndFont(LookAndFeel.java:92)
at javax.swing.plaf.basic.BasicPanelUI.installDefaults(BasicPanelUI.java:49)
at javax.swing.plaf.basic.BasicPanelUI.installUI(BasicPanelUI.java:39)
at javax.swing.JComponent.setUI(JComponent.java:652)
at javax.swing.JPanel.setUI(JPanel.java:131)
at javax.swing.JPanel.updateUI(JPanel.java:104)
at javax.swing.JPanel.<init>(JPanel.java:64)
at javax.swing.JPanel.<init>(JPanel.java:87)
at javax.swing.JPanel.<init>(JPanel.java:95)
at DrawCircle.<init>(DrawCircle.java:7)
at DrawCircle.<init>(DrawCircle.java:6)
import java.awt.event.*;
import javax.swing.*;
import java.awt.*;
public class GUI{
     DrawCircle circle = new DrawCircle(100,100,50);
     private JButton UpButton, DownButton, LeftButton, RightButton, IncreaseButton, DecreaseButton, InputButton;
     public void drawframe(){
                final JFrame CircleFrame = new JFrame("Frame for Circle");
                CircleFrame.getContentPane().add(circle);
                CircleFrame.setSize(200,200);
          CircleFrame.setVisible(true);
          UpButton = new JButton("UP");
          UpButton.addActionListener(new ActionListener()     {
               public void actionPerformed(ActionEvent e){
                            circle.up();
                                if(circle.getY() - circle.getR() <= 0) {
                                    JOptionPane.showMessageDialog( CircleFrame, "Out of window");
                                    circle.setY(circle.getY() +10);
          RightButton = new JButton("RIGHT");
          RightButton.addActionListener(new ActionListener()     {
               public void actionPerformed(ActionEvent e)     {
                            circle.right();
                                if(circle.getX() + circle.getR() >= 500) {
                                    JOptionPane.showMessageDialog( CircleFrame, "Out of window");
                                    circle.setX(circle.getX() -10);
          LeftButton = new JButton("LEFT");
          LeftButton.addActionListener(new ActionListener(){
               public void actionPerformed(ActionEvent e){
                            circle.left();
                                if(circle.getX() - circle.getR() <= 0) {
                                    JOptionPane.showMessageDialog( CircleFrame, "Out of window");
                                    circle.setX(circle.getX() +10);
          DownButton = new JButton("DOWN");
          DownButton.addActionListener(new ActionListener(){
               public void actionPerformed(ActionEvent e){
                            circle.down();
                                System.out.println(circle.getY());
                                if(circle.getY() + circle.getR() >= 500) {
                                    JOptionPane.showMessageDialog( CircleFrame, "Out of window");
                                    circle.setY(circle.getY() -10);
          IncreaseButton = new JButton("INCREASE");
          IncreaseButton.addActionListener(new ActionListener()     {
               public void actionPerformed(ActionEvent e)     {
                            circle.increase();
                                if(circle.getY() + circle.getR() >= 500) {
                                    JOptionPane.showMessageDialog( CircleFrame, "Out of window");
                                    circle.setR(circle.getR() -10);     
                                } else if(circle.getX() + circle.getR() >= 500) {
                                    JOptionPane.showMessageDialog( CircleFrame, "Out of window");
          DecreaseButton = new JButton("decrease");
                    DecreaseButton.addActionListener(new ActionListener(){
                            public void actionPerformed(ActionEvent e)     {           
                                circle.decrease();
          JPanel ButtonPanel = new JPanel();
          ButtonPanel.add(IncreaseButton);
          ButtonPanel.add(DecreaseButton);
          ButtonPanel.add(DownButton);
          ButtonPanel.add(LeftButton);
          ButtonPanel.add(RightButton);
          ButtonPanel.add(UpButton);
          ButtonPanel.setLayout(new BoxLayout(ButtonPanel, BoxLayout.Y_AXIS));
                JFrame mainFrame = new JFrame("GUI for Circle Drawing");
          mainFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE );
                mainFrame.add(ButtonPanel);
                mainFrame.pack();
          mainFrame.setVisible(true);
     public static void main(String [] args)     {
          GUI intf = new GUI();
          intf.drawframe();
}and the DrawCircle Class is
import java.awt.*;
import javax.swing.*;
public class DrawCircle extends JPanel{
     private int x, y, r;
        DrawCircle circle = new DrawCircle(100, 100, 50);
     public DrawCircle( int x , int y , int r){
          this.x = x;
          this.y = y;
          this.r = r;
     public int getR(){
          return r;
     public int getX(){
          return x;
     public int getY(){
          return y;
     public void setX(int x)     {
          this.x = x;
                repaint();
     public void setY(int y)     {
          this.y = y;
                repaint();
     public void setR(int r)     {
          this.r = r;
                repaint();
     public void paint(Graphics g){
          g.clearRect(0,0,400,400);
                g.drawOval(x-r, y-r, r*2, r*2);
        public void up() {
          circle.setY(circle.getY() -10);
        public void down() {
                circle.setY(circle.getY() +10);
        public void right() {
                circle.setX(circle.getX() +10);
        public void left() {
                circle.setX(circle.getX() -10);
        public void increase() {
                circle.setR(circle.getR() +10);     
        public void decrease() {
                circle.setR(circle.getR() -10);     
          

The problem is that you're constructing a new DrawCircle each time you construct a new DrawCircle, resulting in infinite recursion causing a stack overflow.
This line:DrawCircle circle = new DrawCircle(100, 100, 50);in your DrawCircle class is causing the problem, do you need it? Remove it and replace references to 'circle' in the class with 'this'.

Similar Messages

  • Can only draw circle and square in Illustrator CS5 and Photoshop CS5

    I am experiencing a strange bug that seems to be affecting both Photoshop CS5 and Illustrator CS5. In Illustrator, when I try to draw a rectangle or ellipse I can only draw circles and squares. Also I can't change the color of selected objects. When I try to change its fill nothing happens. I can also only drag objects on the 0, 45 and 90 degree angles. Also I can no longer select off an object by clicking on the artboard. When I click on the artboard nothing happens.
    Similarly in Photoshop I can only draw straight lines using the brush tool. The  marquee tool is also not functioning properly. When I try to use the marquee tool the marching ants form a square but when I release the mouse it selects a rectangular portion. Strangely if I use the marquee tool and make selection I can press the shift key and add to it but this second selection's marching ants are not square but are properly rectangular.
    Since the problem seems to be affecting both Illustrator and Photoshop I'm thinking it's probably some kind of system conflict or perhaps an application running in the background is affecting it. Also if I restart my mac the problem goes away. Unfortunately the problem eventually returns.
    Anyway I'm pretty sure most of the suggested fixes involve systematically going through all the programs running in the background and trying to determine which if any might be affecting Illustrator and Photoshop but I just thought I'd post something in case someone else had the problem or knew of any fixes.
    I'm running CS5 on a MBP.
    Thanks!

    Ok I figured out the problem. It was another application called teleport which lets you control 2 macs with one mouse. It requires a hot key and in my case that was the shift key. Even though it was running it was still affecting me. Had to quit it and restart. If you're having a similar problem I'd check to see you're not running any other applications that can be activated with a hot key.

  • Draw Circles

    Hi Guys,
    I need to display one field within circle(means i need to display one filed that field always has the value 'Y' or 'N')in sapscript and in report output also means both normal and alv reports.How can i do this? Is it possible in sap to draw circles? Is there any function module to achieve this? please help me.

    Hi Sai,
    For SAP Scripts you can try :
    SE71--> form name > change> window--> text element > Insert(Mnubar)> charcters--> SAP sybbols --> search for SYM_CIRCLE.
    Hope this may help you.
    Lanka

  • Draw circles,images in flex

    How can we draw circles,images in flex? (ex as in
    ms-paint)

    http://livedocs.adobe.com/flex/3/html/help.html?content=Drawing_Vector_Graphics_1.html

  • How to draw circle if I have two points info and radius of the circle?

    Hi,
    I am trying to draw circle.
    Inputs I have is 1. Two points of the circle and
    2. Radius of the circle.
    Please let me know if u have solution using Shape, Graphics2D apis.
    Thanks in advance..
    Cheers,
    Somasekhar

    As far as the drawing is concerned, you would use Graphics# drawOval. There's no API method to draw a circle using the parameters of two points and a radius.
    You need to solve the problem on paper and work out the maths involved, then translate that math into working Java code.
    btw, you do realize that the information will give you zero to two valid circles, don't you?
    db

  • Hi i would like help with:  When I draw circle and add stroke I can not see stroke  I use Photoshop CS 5

    Hi i would like help with:
    When I draw circle and add stroke I can not see stroke
    I use Photoshop CS 5

    Make sure the stroke is set to a color and not to the symbol that appears here for Fill

  • Photoshop CS4 Brush Draws Circles

    Hi. This wasn't happening but now, all of my brushes draws circles like that. Is it supposed to happen? If answer is no, how can I solve it? Thanks.

    Today I've installed the latest Forceware Drivers 180.60 from http://www.laptopvideo2go.com/ to test the bug behaviour.
    The brush cursor now seems to be able to handle big brush sizes but the performance is reduced noticable.When painting inside a new document the rendering of the brush path is done after painting over the area, even when using small brush sizes.
    So let's wait until Nvidia/Lenovo roll out a new driver.
    Message Edited by mikey on 11-24-2008 07:57 AM

  • JMF - How to draw Circles over Video (JMF / Java2D / Swing)

    Hi there!
    I want to draw polygons over a playing video-panel, but they keep vanishing behind the video... Is there a way to bring them on top of the video canvas? The application which I'm going to develop should indicate ROIs on a playing video... This thread was inspiring, but didn't help at all...
    http://forum.java.sun.com/thread.jspa?forumID=28&threadID=612055

    Hi there!
    I want to draw polygons over a playing video-panel, but they keep vanishing behind the video... Is there a way to bring them on top of the video canvas? The application which I'm going to develop should indicate ROIs on a playing video... This thread was inspiring, but didn't help at all...
    http://forum.java.sun.com/thread.jspa?forumID=28&threadID=612055

  • Hi, odd error in my code with a draw circle method

    Hey, I am a first year computer science student who uses java in class.
    We have recently been playing with guis
    I have created code that when it runs it draws random circles with random gradiants.
    However, the code will sometimes draw a random square, any ideas.
    import java.io.*;
    import java.util.*;
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    import java.awt.image.*;
    import javax.imageio.*;
    * Class for animations, if I dont finish this lab I will have egg on my face
    public class AnimationStation {
         private JFrame frame; //the jframe
         private IView viewer; //the viewer
         * Constructor
         public AnimationStation() {
              frame = new JFrame(); //makes jframe
              viewer = new IView(); //makes iview
              frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); //window closes
              frame.setSize(300, 500); //biggie or smallie
              frame.getContentPane().add(BorderLayout.CENTER,viewer); //place it
              frame.setVisible(true);
         * Main Method
         public static void main(String[] args) {
              AnimationStation cutie = new AnimationStation();
         * The IView inner class
         class IView extends JPanel {
              int x = 0; //x pos
              int y = 0; //w pos
              int d = 0; //diameter
              Color randomColor1; //random color     
              Color randomColor2; // random color
              private boolean imageOn = true; //do we care about the background, or are we looking for that square?
              * Default constructor
              public IView() {
              //wonders... is this neccessary.... ::thinks:: well it works so lets not mess with it
              * Builds our pretty pictures
              public void paintComponent(Graphics g) {
                         g.setColor(Color.white); //make background
                         g.fillRect(0,0,this.getWidth(),this.getHeight()); //background
                   for(int x = 0; x < 10; x++) { //no? draw ovals
                             drawOval(g);
              * Method to make ovals
              *(and apparently a random square, although I think its good luck if you do! So its a feature, not a bug)
              public void drawOval(Graphics g) {
                   d = (int)((Math.random() * 10) + (this.getWidth() / 5)); //set diameter
                   x = (int)(Math.random() * (this.getWidth() - d)); //set x dont let it off the screen
                   y = (int)(Math.random() * (this.getHeight() - d)); //set y dont let it off the screen
                   randomColor1 = randomColor(); //set random color one
                   randomColor2 = randomColor(); //set random color two
                   Graphics2D g2d = (Graphics2D) g; //make a graphics 2d object, helps with gradiants
                   GradientPaint gradient; //make gradiant
                   gradient = new GradientPaint(x, y, randomColor1, x+d, y+d, randomColor2); //set gradiant
                   g2d.setPaint(gradient); //set paint
                   g2d.fillOval(x,y,d,d); //make that oval
              * Method which makes a random color
              public Color randomColor() {
                   Color a = new Color((int)(Math.random() * 255), (int)(Math.random() * 255), (int)(Math.random() * 255));
                   return a;
              * Checks to see if a file is an image file (I REALLY hope this is not how other programs do it,
              *  becuase technically I can make this a graphic "mv ImageViewer.java fake.gif")
              public boolean isImageFile(String filename) {
                   String ending = "" + filename.charAt(filename.length() - 4) + filename.charAt(filename.length() - 3) + filename.charAt(filename.length() - 2) +
                        filename.charAt(filename.length() - 1); //make a string with the last four letters
                   if(ending.equalsIgnoreCase(".jpg") || ending.equalsIgnoreCase(".gif") || ending.equalsIgnoreCase(".bmp")) { //is it an image?
                        return true; //yes
                   } else {
                        return false; //no
    }thanks,
    Bachmann

    well, let me explain some more. Its more of an irritation, then a crippling error....
    The squares are quite clear. I mean, its not like a small circle that looks squareish, I have seen a square appear and it could be larger than the circles that I see.
    It is also very rare, so yeah, it could have something to do with the random aspects.
    It just kinda bothers me since nither me, my classmates, or my professor can figure out why this happens and no one else has mentioned this problem.

  • Draw circle, intersects Ellipse2D need help

    looks like have a few error... i have no idea how to fix it now. help plz.
    Circle class file.
    import java.awt.Color;
    import java.awt.Graphics;
    import java.awt.Graphics2D;
    import java.awt.geom.Ellipse2D;
    import javax.swing.JOptionPane;
    public class Circle
         private double radius;
         private int centerX, centerY;
         private Color fillColor;
         public Circle()
              radius=0;
              centerX=0;
              centerY=0;
         public double getRadius()
              return radius;
         public void setRadius(double newRadius)
              radius=newRadius;
         public int getCenterX()
              return centerX;
         public int getCenterY()
              return centerY;
         public void setCenterX(int newCenterX)
              centerX=newCenterX;
         public void setCenterY(int newCenterY)
              centerY=newCenterY;
         public void setFillColor(Color newColor)
              fillColor=newColor;
         public Color getFillColor()
              return fillColor;
         public void draw(Graphics g)
              Graphics2D g2= (Graphics2D) g;
              radii=this.getRadius()
              if( radius>=0 )
                   g2.fill( Ellipse2D.Double(radii*2,radii*2,this.centerX-radii,this.centerY-radii));
              else
                   g2.fill( Ellipse2D.Double(0,0,centerX,centerY));
         public boolean intersects(Circle circle2)
              double radiusLength1 = this.getRadius();
              double radiusLength2 = circle2.getRadius();
              double totalRadius = radiusLength1+radiusLength2;
              double distance = Math.sqrt(
                   (Math.pow(this.centerX-circle2.centerX,2))+
                   (Math.pow(this.centerY-circle2.centerY,2))
              return boolean totalRadius >= distance;
    CircleComponent class code
    import java.awt.Color;
    import java.util.Random;
    import java.awt.Graphics;
    import java.awt.Graphics2D;
    import java.awt.geom.Ellipse2D;
    import javax.swing.JOptionPane;
    import javax.swing.JComponent;
    public class CircleComponent extends JComponent
         public static void CircleComponent (String[] args)
              double radius;
              Circle circle1,circle2;x
              circle1=new Circle();
              circle2=new Circle();
              circle1.setCenterX(200);
              circle1.setCenterY(100);
              circle2.setCenterX(100);
              circle2.setCenterY(200);
              Random generator= new Random();
              Color color1 = new Color (generator.nextInt(256), generator.nextInt(256), generator.nextInt(256));
              circle1.setFillColor(color1);
              Color color2 = new Color (generator.nextInt(256), generator.nextInt(256), generator.nextInt(256));
              circle2.setFillColor(color2);
              String input=JOptionPane.showInputDialog("Set the circle1's radius ");
              radius = Integer.parseInt(input);
              circle1.setRadius(radius);
              input=JOptionPane.showInputDialog("Set the circle2's radius ");
              radius = Integer.parseInt(input);
              circle2.setRadius(radius);
         public void paintComponent (Graphics g)
              Graphics2D g2= (Graphics2D) g;
              g2.setColor(color1);
              g2.draw(circle1);
              g2.setColor(circle2.getFillColor());
              g2.draw(circle2);
              //draw String intersectsResult
              g2.setColor(Color.BLACK);
              String intersectsResult;
              if (circle1.intersects(circle2))
                   intersectsResult="Two circles intersected";
              else
                   intersectsResult="Two circles not intersected";
              g2.drawString(intersectsResult,20,380);
    }

    looks like have a few error... i have no idea howto fix it now. help plz.
    what are the errors?
    copy and paste themI think the code simply "does not work" as expected ;)

  • Problem drawing circles and ellipses

    I want my program to draw an ellipse and circle. As we all know, theyre different.
    I used the drawOval() method in java.awt.Graphics to do this.
    Here is the crucial lines of the code:
    public void paintComponent(Graphics g)
              super.paintComponent(g);
              if(currentShape!=null)
                   if (currentShape.shapeType()==RECTANGLE)
                        g.drawRect(currentShape.getStartingX(),currentShape.getStartingY(),currentShape.getLength(),currentShape.getWidth());
                   else if (currentShape.shapeType()==ELLIPSE)
                        g.drawOval(currentShape.getStartingX(),currentShape.getStartingY(),currentShape.getLength(),currentShape.getWidth());
                   else if (currentShape.shapeType()==CIRCLE)
                        g.drawOval(currentShape.getStartingX(),currentShape.getStartingY(),currentShape.getLength(),currentShape.getLength());
              if (shapeCount>0)
                   for (int c=0;c<shapeCount;c++)
                        if (myShapes[c].shapeType()==RECTANGLE)
                             g.drawRect(myShapes[c].getStartingX(),myShapes[c].getStartingY(),myShapes[c].getLength(),myShapes[c].getWidth());     
                        else if (myShapes[c].shapeType()==ELLIPSE)
                             g.drawOval(myShapes[c].getStartingX(),myShapes[c].getStartingY(),myShapes[c].getLength(),myShapes[c].getWidth());     
                        else if (myShapes[c].shapeType()==CIRCLE)
                             g.drawOval(myShapes[c].getStartingX(),myShapes[c].getStartingY(),myShapes[c].getLength(),myShapes[c].getLength());     
         }I am bemused because, it doesn't work. When I try to draw the circle, it doesn't draw a circle but an ellipse but as you can see I set the length and height parameters of the cricle to the length!
    here are my other codes, see for yourself.
    import javax.swing.JFrame;
    import javax.swing.JButton;
    import javax.swing.JComboBox;
    import javax.swing.JCheckBox;
    import javax.swing.JPanel;
    import javax.swing.JLabel;
    import java.awt.BorderLayout;
    import java.awt.FlowLayout;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    public class DrawFrame extends JFrame
         JButton undo, clear;
         JComboBox colors, shapes;
         JCheckBox isFilled;
         JPanel top,bottom;
         JLabel statusBar;
         DrawPanel canvas;
         String shapeList[] = {"Rectangle","Ellipse","Circle","Triangle"};
         String colorList[] = {"Red","Orange","Yellow","Green","Blue","Violet"};
         public DrawFrame()
              super("Java Drawings");
              setLayout(new BorderLayout());
              top = new JPanel();
              top.setLayout(new FlowLayout());
              undo = new JButton("Undo");
              clear = new JButton("Clear");
              shapes = new JComboBox(shapeList);
              colors = new JComboBox(colorList);
              isFilled = new JCheckBox("Filled",true);     
              top.add(undo);
              top.add(clear);
              top.add(shapes);
              top.add(colors);
              top.add(isFilled);
              add(top,BorderLayout.NORTH);
              statusBar = new JLabel("Program Started");
              canvas = new DrawPanel(statusBar);
              add(canvas,BorderLayout.CENTER);
              bottom = new JPanel();
              statusBar = canvas.getStatusLabel();
              bottom.setLayout(new FlowLayout(FlowLayout.LEFT));
              bottom.add(statusBar);
              add(bottom,BorderLayout.SOUTH);
              //default settings
              canvas.setShapeType(0);
              eventHandler handler = new eventHandler();
              shapes.addActionListener(handler);
         private class eventHandler implements ActionListener
              public void actionPerformed(ActionEvent e)
                   if(e.getSource()==shapes)
                        canvas.setShapeType(shapes.getSelectedIndex());
                        //System.out.println("Selected Index"+shapes.getSelectedIndex());
         public static void main(String args[])
              DrawFrame app = new DrawFrame();
              app.setSize(500,300);
              app.setVisible(true);
    import javax.swing.JLabel;
    import javax.swing.JPanel;
    import java.awt.Graphics;
    import java.awt.Color;
    import java.awt.event.MouseEvent;
    import java.awt.event.MouseMotionListener;
    import java.awt.event.MouseListener;
    public class DrawPanel extends JPanel
         private int shapeCount;
         private int shapeType;
         private int currentColor;
         private boolean filledShape;
         public JLabel statusLabel;
         private Shape myShapes[]=new Shape[100];
         private Shape currentShape;
         private final int RECTANGLE=0,ELLIPSE=1,CIRCLE=2,TRIANGLE=3;
         private boolean draw=false;
         public DrawPanel(JLabel statusBar)
              shapeCount=0;
              statusLabel = statusBar;
              mausHandler mouseEventsHandler = new mausHandler();
              addMouseListener(mouseEventsHandler);
              addMouseMotionListener(mouseEventsHandler);
              setBackground(Color.white);
              setVisible(true);
         public void setShapeType(int shapeType)
              this.shapeType=shapeType;
         public void setCurrentColor()
         public void isFilledShape()
         public void clearLastShape()
              shapeCount--;
              repaint();
         public void clearDrawing()
              shapeCount=0;
              repaint();
         public JLabel getStatusLabel()
              return statusLabel;
         public void paintComponent(Graphics g)
              super.paintComponent(g);
              if(currentShape!=null)
                   if (currentShape.shapeType()==RECTANGLE)
                        g.drawRect(currentShape.getStartingX(),currentShape.getStartingY(),currentShape.getLength(),currentShape.getWidth());
                   else if (currentShape.shapeType()==ELLIPSE)
                        g.drawOval(currentShape.getStartingX(),currentShape.getStartingY(),currentShape.getLength(),currentShape.getWidth());
                   else if (currentShape.shapeType()==CIRCLE)
                        g.drawOval(currentShape.getStartingX(),currentShape.getStartingY(),currentShape.getLength(),currentShape.getLength());
              if (shapeCount>0)
                   for (int c=0;c<shapeCount;c++)
                        if (myShapes[c].shapeType()==RECTANGLE)
                             g.drawRect(myShapes[c].getStartingX(),myShapes[c].getStartingY(),myShapes[c].getLength(),myShapes[c].getWidth());     
                        else if (myShapes[c].shapeType()==ELLIPSE)
                             g.drawOval(myShapes[c].getStartingX(),myShapes[c].getStartingY(),myShapes[c].getLength(),myShapes[c].getWidth());     
                        else if (myShapes[c].shapeType()==CIRCLE)
                             g.drawOval(myShapes[c].getStartingX(),myShapes[c].getStartingY(),myShapes[c].getLength(),myShapes[c].getLength());     
         private class mausHandler implements MouseListener, MouseMotionListener
              public void mouseClicked(MouseEvent e)
              public void mouseEntered(MouseEvent e)
              public void mouseExited(MouseEvent e)
              public void mousePressed(MouseEvent e)
                   statusLabel.setText("Pressed at ("+e.getX()+","+e.getY()+")");
                   if (shapeType==RECTANGLE)
                        currentShape = new Square(e.getX(),e.getY());     
                   else if (shapeType==ELLIPSE)
                        currentShape = new Circle(e.getX(),e.getY());     
                        System.out.println("Oval");
                   else if (shapeType==CIRCLE)
                        currentShape = new Circle(e.getX(),e.getY());     
                        System.out.println("Circle");
              public void mouseDragged(MouseEvent e)
                   statusLabel.setText("Dragged at ("+e.getX()+","+e.getY()+")");
                   currentShape.setDimensions(e.getX() - currentShape.getStartingX(),e.getY() - currentShape.getStartingY());
                   repaint();
              public void mouseReleased(MouseEvent e)
                   statusLabel.setText("Released at ("+e.getX()+","+e.getY()+")");
                   currentShape.setDimensions(e.getX() - currentShape.getStartingX(),e.getY() - currentShape.getStartingY());
                   myShapes[shapeCount] = currentShape;
                   shapeCount++;
                   currentShape=null;
                   repaint();
              public void mouseMoved(MouseEvent e)
                   statusLabel.setText("("+e.getX()+","+e.getY()+")");
    }

    Here are my other classes btw:
    import java.awt.Graphics;
    public interface Shape
         public abstract double getArea();
         public abstract double getVolume();
         public abstract String getShape();
         public abstract int getLength();
         public abstract int getWidth();
         public abstract double getRadius();
         public abstract double getHeight();
         public abstract void setDimensions(int length, int width);
         public abstract String toString();
         public abstract int shapeType();
         public abstract int getStartingX();
         public abstract int getStartingY();
    import java.awt.Graphics;
    public class Square extends TwoDimShape
         public Square(int x,int y)
              super("Square",x,y);
         public void setDimensions(int length,int width)
              super.length = length;
              super.width = width;
         public double getArea()
              return super.getArea() + (super.getLength()*super.getWidth());
         public String toString()
              return String.format(super.toString()+"\nOrigin: ("+getStartingX()+","+getStartingY()+")"+"\nArea: "+getArea()+"\nLength: "+getLength()+"\nWidth: "+getWidth());
         public int shapeType()
              return 0;
    import java.awt.Graphics;
    public class TwoDimShape implements Shape
         protected String shape;
         protected int length;
         protected int width;
         protected double radius;
         protected int x;
         protected int y;
         public TwoDimShape(String shape, int x, int y)
              this.shape = shape;
              this.x=x;
              this.y=y;          
         public TwoDimShape(String shape, double radius)
              this.shape=shape;
              this.radius=radius;
         public void setDimensions(int length, int width)
              this.length=length;
              this.width=width;
         public int getStartingX()
              return x;
         public int getStartingY()
              return y;
         public String getShape()
              return shape;
         public int getLength()
              return length;
         public int getWidth()
              return width;
         public double getRadius()
              return radius;
         public double getHeight()
              return 0.0;
         public double getArea()
              return 0.0;
         public double getVolume()
              return 0.0;
         public String toString()
              return String.format(shape +" ,2D shape with Area: ");
         public int shapeType()
              return -1;
    import java.awt.Graphics;
    public class Circle extends TwoDimShape
         public Circle(int x,int y)
              super("Square",x,y);
         public void setDimensions(int length,int width)
              super.length = length;
              super.width = width;
         public double getArea()
              return super.getArea() + (super.getLength()/2)*(super.getWidth()/2)*Math.PI;
         public String toString()
              return String.format(super.toString()+"\nOrigin: ("+getStartingX()+","+getStartingY()+")"+"\nArea: "+getArea()+"\nLength: "+getLength()+"\nWidth: "+getWidth());
         public int shapeType()
              return 1;
    }

  • Drawing in the Swing

    Hi all ...
    really i am new to Swing and would like to know what is the best way to draw in a JFrame for example ? and is it like the awt or there are diffrences , thanks .

    http://www.google.com/search?q=JProgressBar+%2Bexamples&ie=utf-8
    First link returned is this:
    http://java.sun.com/docs/books/tutorial/uiswing/components/progress.html

  • Simple line drawing project in swing

    hi folks,
    i want to write a simple line drawing project. it has a JPanel, a JFrame and JButton.
    JPanel and JButton are on JFrame. When Button is clicked,
    a line will be added to JPanel but previous lines which have been added are not removed on JPanel.
    Could you please help me?

    i wrote below codes but it adds first line but when click button �n order to add line, it is not adding line. Please help and thanxs...
    import java.awt.BasicStroke;
    import java.awt.BorderLayout;
    import java.awt.Color;
    import java.awt.Graphics;
    import java.awt.Graphics2D;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import java.awt.geom.Line2D;
    import java.util.Enumeration;
    import java.util.Vector;
    import javax.swing.JButton;
    import javax.swing.JComponent;
    import javax.swing.WindowConstants;
    import javax.swing.SwingUtilities;
    public class NewJFrame extends javax.swing.JFrame implements ActionListener {
         private JButton addButton;
         MainPanel mainPane ;
         public Vector lines ;
         * Auto-generated main method to display this JFrame
         public static void main(String[] args) {
              SwingUtilities.invokeLater(new Runnable() {
                   public void run() {
                        NewJFrame inst = new NewJFrame();
                        inst.getContentPane().add(new MainPanel(inst.lines));
                        inst.setLocationRelativeTo(null);
                        inst.setVisible(true);
         public NewJFrame() {
              super();
              initGUI();
              lines = new Vector();
              lines.add(0, 30);
              addButton.addActionListener(this);
         private void initGUI() {
              try {
                   setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
                        addButton = new JButton();
                        getContentPane().add(addButton, BorderLayout.SOUTH);
                        addButton.setText("ADD");
                        addButton.setPreferredSize(new java.awt.Dimension(71, 21));
                   pack();
                   setSize(400, 300);
              } catch (Exception e) {
                   e.printStackTrace();
         @Override
         public void actionPerformed(ActionEvent e) {
              if(e.getSource() == addButton){
                   lines.addElement(Integer.parseInt(lines.get(0).toString())+30);
                   mainPane.repaint();
    class MainPanel extends JComponent {
         Vector tempLines ;
         MainPanel(Vector lines){
              tempLines = lines;
              setBackground(Color.white);
         public void paintComponent(Graphics g) {
              Enumeration enumeration = tempLines.elements();
              while(enumeration.hasMoreElements()) {
                   Integer point = Integer.parseInt(enumeration.nextElement().toString());
                   Line2D line = new Line2D.Double(30, point, 200, point);
         Graphics2D g2d = (Graphics2D)g;
         g2d.setStroke(new BasicStroke(5));
         g2d.draw(line);
    }

  • Cannot Draw Circles or Squares in Captivate (Holding down SHIFT doesn't work.)

    Hi,
    I am trying to add squares and circle shapes to a Captivate 8 project.
    Before I click to draw the shape, I hold down the SHIFT button to constrain the proportions. Captivate draws me an oval or a rectangle all the same.
    Error testing I have tried:
    Trying to add a square in PowerPoint by holding SHIFT work (so not a hardware issue?)
    Resizing my dratted rectangles & ovals by holding SHIFT in Captivate does constrain the proportions, but not to a shape I require!
    Resizing images while holding SHIFT also constrains proportions.
    The same error also occurs in my copy of Captivate 7?!
    I'm completely puzzled. I know it's basic function, but it's vital for me to be able to create a smart-looking layout. Is it simply not possible to draw "perfect" squares and circles in Captivate?
    Seth

    Don't know if it is an oversight, I'm always logging that lack of use of SHIFT, think it is just not considered important enough. My mind tells it is very important, but I'm just a user.
    That is what I told you... in CP8 you need a lot more clicks and mouse movements to get to everything (sighing).
    The screenshot you are showing me is the Properties panel for a shape, tab 'Style', not 'Options'.You have to click on 'Options' to see the former Transform accordion. Splitting up the too long Properties panel of CP7 in two panels and tabs causes incrementing the number of clicks. And it didn't avoid scrolling, as you can see in this Style part. Will stop ranting, even after so many months, do not succeed in liking the UI shift.

  • Draw Circle Using Array

    Hi,
    I have a sizeable array which has an N by N size. How can I draw a circle in my array using digits, 0 or 255, in U8 representation?
    I have a Flatten Pixmap.vi and Draw Flatten Pixmap.vi to assist in the drawing.
    So hope someone out there can help to enlighten me in the logic.
    Thanks and Regards,
    Jack

    There is a function for the 2D picture control that draws real nice circles. You can then turn that picture into whatever you want.
    What is it that you are trying to accomplish?
    Mike...
    Certified Professional Instructor
    Certified LabVIEW Architect
    LabVIEW Champion
    "... after all, He's not a tame lion..."
    Be thinking ahead and mark your dance card for NI Week 2015 now: TS 6139 - Object Oriented First Steps

Maybe you are looking for

  • Multiple Subtotal in ALV

    Hello Experts,        We are working on a report in which we are supposed to display few fields regarding customer and most of them are time fields. My issue is at the end of every customer i need to display the AVERAGE time as a subtotal. I am havin

  • Fastest way to removeAll

    I need to remove quite a few entries from a cache that match a certain criteria. There is cache.putAll(Map) for en-masse cache loading, but there is no equivalent cache.removeAll(Set keys). What is the fastest way to achieve this? I am thinking this:

  • Namespace declaration inconsistencies

    It has occurred to me that there is an inconsistency in the BPEL input message depending on where it is called from... If I test the BPEL process from the BPEL console using the test-form, the namespace of the input message is included. However, when

  • TS1424 I have several incomplete songs after purchase from Itunes.  I sent out an email to find out how do I correct this problem? Follow-Up: 219141808

    I have 6-7 incomplete songs after purchase from Itunes.  I sent out an email to find out how do I correct this problem? Follow-up 219141808

  • PSE 12 crashes randomly and frequently

    OS: Win 8.1 x64. I downloaded PSE 12 trial (I currently use PSE 11 and it behaves the same). I created a new library (did not convert old one) and imported around 10,000 pictures. When trying to do almost anything in Organizer it sometimes crashes wi