Solved

How would I set the height and width of my Arc?

Posted on 2006-11-17
4
212 Views
Last Modified: 2012-05-05
I understand how I sized the Ovel,, >> int width = getSize().width - 100;, I have tried all different combonations to get getSize() to talk to Arc as well, but no go.


class Circle extends JPanel {
     public void paintComponent(Graphics g) {
            Graphics cir = (Graphics) g;
            cir.setColor(Color.red);
            Graphics cira = (Graphics) g;
            
              //cir.fillOval(Color.blue)
             //cir.setColor(Color.blue);
    FlowLayout bar = new FlowLayout();
          int x = 55;
          int y = 55;
               int xa = 55;
          int ya = 55;
             
          int width = getSize().width - 100;
          int height = getSize().height - 100;
             
               int diameter = Math.min(width, height);
            //cira.fillArc(xa, ya, width, height);
            
          //int diameter = Math.min(width, height);
         cir.fillOval(x, y,diameter,diameter);
             
              cira.setColor(Color.blue);
               cira.fillArc (100, 110, 50, 75, 45, 215);
             
0
Comment
Question by:charliebaby
  • 2
  • 2
4 Comments
 
LVL 10

Expert Comment

by:ADSLMark
Comment Utility
Look at this page:

http://java.sun.com/j2se/1.4.2/docs/api/java/awt/Graphics.html
(more info at: http://java.sun.com/j2se/1.4.2/docs/api/java/awt/Graphics.html#fillArc(int,%20int,%20int,%20int,%20int,%20int) )

It tells you how to call fillArc on a Graphics object:

fillArc(int x, int y, int width, int height, int startAngle, int arcAngle);

You have to supply 2 extra parameters for the visible part of the arc (since an arc is a part of a oval)

Mark
0
 

Author Comment

by:charliebaby
Comment Utility
I tried the new entries also in different combos, (lower case, uppercase),but no go. I am probably makeing it more complicated then it is, Filling the arc is no problem ,setting the size has me confused

class Circle extends JPanel {
     public void paintComponent(Graphics g) {
            Graphics cir = (Graphics) g;
            cir.setColor(Color.red);
            Graphics cira = (Graphics) g;
            
              //cir.fillOval(Color.blue)
             //cir.setColor(Color.blue);
    FlowLayout bar = new FlowLayout();
          int x = 55;
          int y = 55;
               int xa = 55;
          int ya = 55;
             
          int width = getSize().width - 100;
          int height = getSize().height - 100;
             
              int Arcwidth=getSize().Arcwidth - 100;
           int Archeight=getSize().Archeight - 100;
               
               int diameter = Math.min(Arcwidth,Archeight);
               int diameter = Math.min(width, height);
            //cira.fillArc(xa, ya, width, height);
            
          //int diameter = Math.min(width, height);
         cir.fillOval(x, y,diameter,diameter);
             
              cira.setColor(Color.blue);
               cira.fillArc (100, 110, 50, 75, 45, 215);
             
     }
}
}
0
 
LVL 10

Accepted Solution

by:
ADSLMark earned 500 total points
Comment Utility
Ok, you are messing things up now. I have no idea what you are trying to achieve, but here comes some corrected code (with comments):

//Class declaration
class Circle extends JPanel {
     
     //Paint method
     //g is a variable pointing to a graphics object
     //this is a variable pointing to the current object
     public void paintComponent(Graphics g) {
          //set offset position
          int x = 55;
          int y = 55;

          //get size of the panel and substract 100
          int width = this.getWidth() - 100;
          int height = this.getHeight() - 100;
             
          //take smallest size as diameter
          int diameter = Math.min(width, height);

          //paint red oval
          g.setColor(Color.RED);
          g.fillOval(x, y, diameter, diameter);

          //paint blue arc          
          g.setColor(Color.BLUE);
          g.fillArc (x, y, diameter, diameter, 45, 215);
     }
}
}

This should work (did not test, though). You might have to comment the painting of one of the two shapes to make the other visible, since they overlap.

Good luck.
Mark
0
 

Author Comment

by:charliebaby
Comment Utility
Mark thank you that helped a lot,  it works now, thank you again, Charlie.
0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
strCount chalenge 3 50
strCopies  challenge 17 73
Non-recursive backtracking, using a stack 1 45
github account with ecipse 1 15
Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now