aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes really need help with increasing the coordinates of this oval Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "really need help with increasing the coordinates of this oval" Watch "really need help with increasing the coordinates of this oval" New topic
Author

really need help with increasing the coordinates of this oval

prince albet
Greenhorn

Joined: Feb 09, 2012
Posts: 1

import java.awt.*;
import javax.swing.*;

public class BigBlueDrawPanel extends JPanel {

JFrame frame;

public static void main(String[] args) {
BigBlueDrawPanel g = new BigBlueDrawPanel();
g.setUpScreen();

}

public void setUpScreen() {

frame = new JFrame();
frame.setVisible(true);
frame.setSize(500, 500);
frame.add(this);
}

public void paintComponent(Graphics g) {
g.setColor(Color.blue);
g.fillOval(225, 225, 50, 50);

}

}

Each time the paintComponent() method is run the coordinates (50, 50)
should increase by 2 so that the oval gradually increases in size.

and how to use Thread.sleep to slow the growth of the oval
Darryl Burke
Bartender

Joined: May 03, 2008
Posts: 4642
    
    5

Each time the paintComponent() method is run the coordinates (50, 50)
should increase by 2 so that the oval gradually increases in size.

That's not what you want. You have absolutely no control over how often or how many times a painting method is executed.

... and how to use Thread.sleep to slow the growth of the oval

That's not what you want either, and it won't do what you seem to expect.

Read the API for javax.swing.Timer and follow the link to the Swing tutorial on How to Use Timers. From there, find the section on Performing Custom Painting.


luck, db
There are no new questions, but there may be new answers.
Darryl Burke
Bartender

Joined: May 03, 2008
Posts: 4642
    
    5

Please BeForthrightWhenCrossPostingToOtherSites. You abandoned this thread more than 2 weeks ago.
http://www.java-forums.org/new-java/54431-increase-oval-size-2-every-time-program-run-coordinates-50-50-a.html
Darryl Burke
Bartender

Joined: May 03, 2008
Posts: 4642
    
    5

The poster on the other forum has denied cross posting. Based on whatever evidence I can access, I have to believe that both posters copied the posted code from the same source, possibly some homework assignment online or otherwise in soft copy. That might account for the 3 extraneous newlines in the same position in both the identical codes, quoted here for record.
prince albet wrote:
import java.awt.*;
import javax.swing.*;

public class BigBlueDrawPanel extends JPanel {

JFrame frame;

public static void main(String[] args) {
BigBlueDrawPanel g = new BigBlueDrawPanel();
g.setUpScreen();

}

public void setUpScreen() {

frame = new JFrame();
frame.setVisible(true);
frame.setSize(500, 500);
frame.add(this);
}

public void paintComponent(Graphics g) {
g.setColor(Color.blue);
g.fillOval(225, 225, 50, 50);

}

}
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: really need help with increasing the coordinates of this oval