Welcome to Dream.In.Code
Become a Java Expert!

Join 149,519 Java Programmers for FREE! Get instant access to thousands of Java experts, tutorials, code snippets, and more! There are 1,371 people online right now. Registration is fast and FREE... Join Now!




Help with poygons and labeling

 
Reply to this topicStart new topic

Help with poygons and labeling

snugglesmocha
7 Jul, 2007 - 09:11 AM
Post #1

New D.I.C Head
*

Joined: 14 Apr, 2007
Posts: 28


My Contributions


Two questions-

1. -I now know how to move my polygons horizontallly but how do I move them veritically???

2. Also I need to label my graphics--not sure how to do that. I attempted one of the graphics but got no result. I need to label ---square, rounded square, polygon, circle, oval, filled rectaangle and filled circle.

Here is my code

import java.applet.*;
import java.awt.*;
public class Project3Applet extends Applet
{

public void paint(Graphics gr)
{
Label grapicName = new Label("square");
Font bigFont = new Font("Helvetica", Font.BOLD,12);
gr.setFont(bigFont);
gr.setColor(Color.blue);
setBackground(Color.white);
gr.drawRoundRect(20,20,80,80,0,0);


gr.drawRoundRect(20,20,80,80,0,0);
gr.setColor(Color.magenta);
setBackground(Color.white);

gr.drawRoundRect(220,20,80,80,40,40);
gr.setColor(Color.cyan);
setBackground(Color.white);

gr.drawRoundRect(20,180,80,80,80,80);
gr.setColor(Color.green);
setBackground(Color.white);
gr.drawOval(190,190,120,60);

gr.setColor(Color.red);
setBackground(Color.white);
gr.drawRoundRect(20,320,75,75,80,80);

gr.setColor(Color.orange);
setBackground(Color.white);
gr.fillRect(200,330,120,60);

int xPoints[] = {162,172,192,172,180,160,135,148,129,152,162};
int yPoints[] = {158,180,188,200,235,205,222,195,178,180,158};
gr.setColor(Color.black);
gr.drawPolygon(xPoints, yPoints, xPoints.length);
}
}


Thanks for the help

















User is offlineProfile CardPM
+Quote Post

1lacca
RE: Help With Poygons And Labeling
7 Jul, 2007 - 02:36 PM
Post #2

code.rascal
Group Icon

Joined: 11 Aug, 2005
Posts: 3,822



Thanked: 12 times
My Contributions
1) which part of this code moves them horizontally?
2) Graphics.drawString(String label, int x, int y)
User is offlineProfile CardPM
+Quote Post

snugglesmocha
RE: Help With Poygons And Labeling
8 Jul, 2007 - 05:23 AM
Post #3

New D.I.C Head
*

Joined: 14 Apr, 2007
Posts: 28


My Contributions
Well, I have been moving it horizonatally by adding 10 to each x and y value.

QUOTE(snugglesmocha @ 7 Jul, 2007 - 10:11 AM) *

Two questions-

1. -I now know how to move my polygons horizontallly but how do I move them veritically???

2. Also I need to label my graphics--not sure how to do that. I attempted one of the graphics but got no result. I need to label ---square, rounded square, polygon, circle, oval, filled rectaangle and filled circle.

Here is my code

import java.applet.*;
import java.awt.*;
public class Project3Applet extends Applet
{

public void paint(Graphics gr)
{
Label grapicName = new Label("square");
Font bigFont = new Font("Helvetica", Font.BOLD,12);
gr.setFont(bigFont);
gr.setColor(Color.blue);
setBackground(Color.white);
gr.drawRoundRect(20,20,80,80,0,0);


gr.drawRoundRect(20,20,80,80,0,0);
gr.setColor(Color.magenta);
setBackground(Color.white);

gr.drawRoundRect(220,20,80,80,40,40);
gr.setColor(Color.cyan);
setBackground(Color.white);

gr.drawRoundRect(20,180,80,80,80,80);
gr.setColor(Color.green);
setBackground(Color.white);
gr.drawOval(190,190,120,60);

gr.setColor(Color.red);
setBackground(Color.white);
gr.drawRoundRect(20,320,75,75,80,80);

gr.setColor(Color.orange);
setBackground(Color.white);
gr.fillRect(200,330,120,60);

int xPoints[] = {162,172,192,172,180,160,135,148,129,152,162};
int yPoints[] = {158,180,188,200,235,205,222,195,178,180,158};
gr.setColor(Color.black);
gr.drawPolygon(xPoints, yPoints, xPoints.length);
}
}


Thanks for the help


User is offlineProfile CardPM
+Quote Post

1lacca
RE: Help With Poygons And Labeling
8 Jul, 2007 - 07:03 AM
Post #4

code.rascal
Group Icon

Joined: 11 Aug, 2005
Posts: 3,822



Thanked: 12 times
My Contributions
QUOTE
Well, I have been moving it horizonatally by adding 10 to each x and y value.

Does it move it horizontally?
I would assume that it moves things diagonally....
Anyway, theoretically modifying the y coordinates should move your shape vertically. Are you sure that you are setting the y coordinates? Doublecheck the API and the function arguments, I was looking lost a couple of times while using the 2D graphics classes myself, but at the end it turned out to that I was assuming that the arguments were in a different order.
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 1/7/09 08:16PM

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter

Live Java Help!

Java Tutorials

Reference Sheets

Java Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month