• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

really need help with increasing the coordinates of this oval

 
prince albet
Greenhorn
Posts: 1
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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
Posts: 5116
11
Java Netbeans IDE Opera
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Darryl Burke
Bartender
Posts: 5116
11
Java Netbeans IDE Opera
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 5116
11
Java Netbeans IDE Opera
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic