|
|
Welcome to the Java Forums.
You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:
- have access to post topics
- communicate privately with other members (PM)
- not see advertisements between posts
- have the possibility to earn one of our surprises if you are an active member
- access many other special features that will be introduced later.
Registration is fast, simple and absolutely free so please, join our community today!
If you have any problems with the registration process or your account login, please contact us.
|
|

04-18-2008, 04:04 AM
|
|
Member
|
|
Join Date: Apr 2008
Posts: 15
|
|
|
Need help
I am new to Java...I am trying to draw several images in one drawing panel, but i can,t able to do..here are the details
The overall drawing panel is size 500 x 350. Its background color
is cyan. The rectangular area behind each grid of circles is green, and the background of the circles is yellow.
The rectangles and circles are outlined in black. Each grid also has a pair of lines drawn across it in an "X"
pattern. The six figures on your drawing panel should have the following properties.
Description (x, y) position size of subfigure circles per subfigure rows/cols
top-left (0, 0) 100 x 100 10 N / A
top-middle (160, 0) 60 x 60 6 N / A
top-right (250, 30) 100 x 100 5 N / A
bottom-left (10, 170) 48 x 48 4 3 x 3
bottom-middle (180, 190) 24 x 24 3 5 x 5
bottom-right (340, 170) 72 x 72 9 2 x 2
The 100x100 subfigure has 10 circles, and each circle has a gap of 5 pixels from any others (a total of 20 gaps for both directions...the thing is I have to use only parameters and for loops..could any one help me for this .
|
|

04-18-2008, 06:22 AM
|
 |
Senior Member
|
|
Join Date: Jan 2008
Location: Cebu City, Philippines
Posts: 527
|
|
|
And what is your question?
What have you done so far?
regards,
sukatoa
|
|

04-18-2008, 06:53 AM
|
|
Member
|
|
Join Date: Apr 2008
Posts: 15
|
|
|
need help
import java.awt.*;
public class Circles {
public static void main(String[] args) {
DrawingPanel panel = new DrawingPanel(500, 350);
panel.setBackground(Color.CYAN);
Graphics g = panel.getGraphics();
g.setColor(Color.YELLOW);
for(int i=0; i<10; i++) {
g.fillCircle(i*5, i*5, 100-i*5, 100-i*5);
g.setColor(Color.BLACK);
g.drawOval(0, 0, 100-i*5, 100-i*5);
}
}
}
i just tried to draw the first fig but not able to.....
|
|

04-18-2008, 07:05 AM
|
 |
Moderator
|
|
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 4,376
|
|
|
Hi fluffy,
First of all, welcome to the Java Forums.
I have one question to ask from you. Are use any Java IDE for your coding? Or just work on a text editor like Notepad?
__________________
Use an appropriate Subject. "Help, urgent!" isn't one. To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Has someone helped you? Then you can To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts. their helpful post.
Want to make your IDE the best? To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
|
|

04-18-2008, 07:20 AM
|
|
Member
|
|
Join Date: Apr 2008
Posts: 15
|
|
|
i have written the code on jGrasp
|
|

04-18-2008, 07:07 PM
|
|
Member
|
|
Join Date: Apr 2008
Posts: 15
|
|
|
Hey
could any one can help me to solve this problem....please
|
|

04-18-2008, 07:17 PM
|
|
Member
|
|
Join Date: Apr 2008
Posts: 28
|
|
Originally Posted by sukatoa
And what is your question?
What have you done so far?
regards,
sukatoa
ask those question too many times, without answer the question the askers ask.
|
|

04-18-2008, 07:22 PM
|
|
Member
|
|
Join Date: Apr 2008
Posts: 28
|
|
Originally Posted by fluffy
import java.awt.*;
public class Circles {
public static void main(String[] args) {
DrawingPanel panel = new DrawingPanel(500, 350);
panel.setBackground(Color.CYAN);
Graphics g = panel.getGraphics();
g.setColor(Color.YELLOW);
for(int i=0; i<10; i++) {
g.fillCircle(i*5, i*5, 100-i*5, 100-i*5);
g.setColor(Color.BLACK);
g.drawOval(0, 0, 100-i*5, 100-i*5);
}
}
}
i just tried to draw the first fig but not able to.....
I think the class have to extends JFrame and setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE);
and then add(panel);
let me know if I answer your questions.
|
|

04-18-2008, 07:25 PM
|
|
Member
|
|
Join Date: Apr 2008
Posts: 28
|
|
|
Here is one of the example I done:
import javax.swing.JFrame;
import java.awt.*;
public class BallApp extends JFrame {
private BallPanel _ballP, _ball2;
public BallApp(String title)
{super(title);
setSize(510,510);
setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE);
_ballP = new BallPanel();
add(_ballP);
setVisible(true);}
public static void main(String[] args){
BallApp app = new BallApp("Color Chaning Ball");
}
}
note that ballPanel is a panel class you have to add panel in to the Frame
|
|

04-18-2008, 09:54 PM
|
|
Member
|
|
Join Date: Apr 2008
Posts: 15
|
|
|
i need to write the code in import java.awt.*
by using for loops and parameters...
i don't understand this import javax.swing.JFrame;
|
|

04-19-2008, 04:19 AM
|
|
Member
|
|
Join Date: Apr 2008
Posts: 28
|
|
Originally Posted by fluffy
i need to write the code in import java.awt.*
by using for loops and parameters...
i don't understand this import javax.swing.JFrame;
I know you have to write in awt, but in order to display it you have to display it in JFrame , JFrame is like a board that you can put the panel on. import is just importing the classes in java. for example import java.awt.* is like import the class in awt that you will use like the panels and many other. so import javax.swing.JFrame is like importing the JFrame class so you can use it.
|
|

04-19-2008, 04:21 AM
|
|
Member
|
|
Join Date: Apr 2008
Posts: 28
|
|
|
Here is modifield version check if works:
import java.awt.*;
import javax.swing.JFrame;
public class Circles extends JFrame{
public static void main(String[] args) {
DrawingPanel panel = new DrawingPanel(500, 350);
add(panel);
setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE);
panel.setBackground(Color.CYAN);
Graphics g = panel.getGraphics();
g.setColor(Color.YELLOW);
for(int i=0; i<10; i++) {
g.fillCircle(i*5, i*5, 100-i*5, 100-i*5);
g.setColor(Color.BLACK);
g.drawOval(0, 0, 100-i*5, 100-i*5);
}
}
}
|
|

04-19-2008, 05:25 AM
|
|
Member
|
|
Join Date: Apr 2008
Posts: 15
|
|
|
Thanks fireball2008 for the response....
i tried to compile that code but it is showing the errors
Circles.java:11: cannot find symbol
symbol : method fillCircle(int,int,int,int)
location: class java.awt.Graphics
g.fillCircle(i*5, i*5, 100-i*5, 100-i*5);
^
1 error
i wrote fillOval instead of circle then it compiled but the thing is the output was not the same i am trying to get....i need to fill the circles with yellow color and the outline of the circle should be black..but the thing is here i am getting the circles filled with both yellow and black..i need only outline of the circle should be black
|
|

04-20-2008, 03:57 AM
|
|
Member
|
|
Join Date: Apr 2008
Posts: 28
|
|
|
well, I didn't know about drawing the outline black, but I am confused with
"the circles filled with both yellow and black" what do u mean by that, it should only fill with one color, try delete the line
"g.setColor(Color.BLACK);" and see what happens.
|
|
| Thread Tools |
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|