1. Member
Join Date
Nov 2012
Posts
3
Rep Power
0

I need a code that draw this graphic ...

Last edited by joker600; 11-23-2012 at 12:48 AM.

This is a forum, not a code factory. Go through the tutorials and try it yourself, then if you have a specific question about your code you can ask it here.

Trail: 2D Graphics (The Java™ Tutorials)
Lesson: Performing Custom Painting (The Java™ Tutorials > Creating a GUI With JFC/Swing)

How to ask questions the smart way

db

3. Member
Join Date
Nov 2012
Posts
3
Rep Power
0

I want to write a code that draw this graphic

The code must be build using the following algorithms

Java Code:
```	void drawLine(Graphics g, int x1, int y1, int x2, int y2) {

int dx = x2 - x1;
int dy = y2 - y1;
putPixel(g, x1, y1);

if (Math.abs(dx) > Math.abs(dy)) {
float m = (float) dy / (float) dx;
float b = y1 - m*x1;
dx = (dx < 0) ? -1 : 1;

while (x1 != x2) {
x1 += dx;
putPixel(g, x1, Math.round(m*x1 + b));
}
} else	if (dy != 0) {
float m = (float) dx / (float) dy;
float b = x1 - m*y1;
dy = (dy < 0) ? -1 : 1;
while (y1 != y1) {
y1 += dy;
putPixel(g, Math.round(m*y1 + b), y1);
}
}

g.setColor(Color.black);
g.drawLine(x1 * pixelSize, y1 * pixelSize, x2 * pixelSize, y2
* pixelSize);

}```
Java Code:
```	void drawCircle(Graphics g,int xCenter , int yCenter , int radius){

int x, y=0, r2;

y = (int) (Math.sqrt(r2 - x*x) + 0.5);
putPixel(g, xCenter + x, yCenter + y);
putPixel(g, xCenter + x, yCenter - y);
}

g.setColor(Color.black);
g.drawOval(xCenter, yCenter, r2, r2);

}```
Honestly I don't know where to start,, any help please!

Please go through the Forum Rules -- especially the second paragraph. Don't start a new thread every time you have a follow-on question.

Moreover, it's rude to ask another question without having first replied to responses on any earlier thread. I've merged the new thread here.

db

5. Member
Join Date
Nov 2012
Posts
3
Rep Power
0

I cannot edit on the first post! so I wanted to remove it (but I can't do that either!) to start new one showing the code I've tried to wrote (because you told me to try something)
Now I'm thinking of leaving the whole forum,, because nothing is work

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•