exporting non-public type through public api

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • DeadSilent
    New Member
    • Feb 2009
    • 8

    exporting non-public type through public api

    I have this code and for some reason I keep getting an error where it says "exporting non-public type through public api ".. I'm not sure why this keeps happening but it does so for getCircleInfo / drawCircle. Thanks for your help.

    - Me.

    [code=java]
    package shapemaker;

    import java.awt.*;
    import javax.swing.*;

    public class ShapeMaker {

    private JFrame win;
    private Container contentPane;

    public ShapeMaker ( ) {
    win = new JFrame("Shape Maker");
    win.setSize(400 , 300);
    win.setDefaultC loseOperation(J Frame.EXIT_ON_C LOSE);
    win.setVisible( true);
    contentPane = win.getContentP ane();
    contentPane.set Background(Colo r.WHITE);
    }

    public static void main(String[] args) {
    ShapeMaker shapeMaker = new ShapeMaker();
    shapeMaker.star t();
    }

    public void start ( ) {
    Circle circle = new Circle ( );
    getCircleInfo(c ircle);
    drawCircle(circ le);
    }

    public void getCircleInfo ( Circle circle ) {
    double radius;
    int x, y;
    radius = Double.parseDou ble ( JOptionPane.sho wInputDialog (win, "Enter Radius") );
    circle.setRadiu s(radius);
    circle.setFillC olor(Color.oran ge);
    circle.setPenCo lor(Color.black );
    x = Integer.parseIn t( JOptionPane.sho wInputDialog ( win, "Enter X Cord:" ) );
    circle.setXCord (x);
    y = Integer.parseIn t( JOptionPane.sho wInputDialog ( win, "Enter Y Cord:" ) );
    circle.setYCord (y);
    }

    public void drawCircle ( Circle circle ) {
    Graphics g = contentPane.get Graphics();
    circle.draw(g);
    }
    }[/code]
    Last edited by Nepomuk; Feb 21 '09, 09:10 PM. Reason: Please use [CODE] tags
  • Nepomuk
    Recognized Expert Specialist
    • Aug 2007
    • 3111

    #2
    Could we have a look at that Circle class? Also, when do you get this error?

    Greetings,
    Nepomuk

    Comment

    • DeadSilent
      New Member
      • Feb 2009
      • 8

      #3
      The error I get is that no circle comes up when I run this code and I am not sure why.

      Circle Class:
      Code:
      package shapemaker;
      
      import java.awt.*;
      
      class Circle {
      
          private double Radius;
          private int XCord, YCord;
          private Color penColor, fillColor;
      
          // Constructors
          public Circle ( ) {
              //setRadius(0);
              this(0);
          }
      
          public Circle ( double r ) {
              setRadius(r);
              penColor = Color.BLACK;
              fillColor = Color.WHITE;
              XCord = 0;
              YCord = 0;
          }
      
          // Set Methods
          public void setRadius ( double r ) {
              Radius = 0;
      
              if (r > 0) {
                  Radius = r;
              }
          }
      
          public void setXCord ( int x ) {
              XCord = 0;
      
              if (x > 0) {
                  XCord = x;
              }
          }
      
          public void setYCord ( int y ) {
              YCord = 0;
      
              if (y > 0) {
                  YCord = y;
              }
          }
      
          public void setPenColor ( Color pen ) {
              penColor = pen;
          }
      
          public void setFillColor ( Color fill ) {
              fillColor = fill;
          }
      
          // Get Methods
          public double getArea (  ) {
              return Math.pow( ( Math.PI * Radius ) , 2 );
          }
      
          public double getCircumference (  ) {
              return ( Math.PI * ( Radius * 2 ) );
          }
      
          public void draw ( Graphics g ) {
              int width = (int) (Radius * 2);
              int height = (int) (Radius * 2);
              g.drawString("This", -10, -10);
      
              g.drawOval(XCord, YCord, width, height);
              g.setColor(penColor);
              g.fillOval(XCord, YCord, width, height);
              g.setColor(fillColor);
              
              g.dispose();
          }
      }

      Comment

      • JosAH
        Recognized Expert MVP
        • Mar 2007
        • 11453

        #4
        Originally posted by DeadSilent
        The error I get is that no circle comes up when I run this code and I am not sure why.
        So the error you mentioned in your original posting automagically disappeared? btw, I expected to see a paintComponent( Graphics g) method for drawing purposes. Where is it?

        kind regards,

        Jos

        Comment

        • DeadSilent
          New Member
          • Feb 2009
          • 8

          #5
          This was for a project and paintComponent( ) was not required to run the program in NetBeans, I'm just starting to learn Java so the graphics / drawing class functions I'm starting to learn. What exactly would I use the paintComponent( ) for?

          Comment

          • JosAH
            Recognized Expert MVP
            • Mar 2007
            • 11453

            #6
            Originally posted by DeadSilent
            This was for a project and paintComponent( ) was not required to run the program in NetBeans,
            I don't believe that; there's always a paintComponent( ) method under the hood somewhere. NetBeans is not a magic wizard that solves it all for you.

            Originally posted by DeadSilent
            I'm just starting to learn Java so the graphics / drawing class functions I'm starting to learn. What exactly would I use the paintComponent( ) for?
            Please check the "Read This First" article; it's the first article in this group; it contains a link to the tutorials; one of them is the Swing tutorial. At least read that one before you attempt to draw anything at all.

            kind regards,

            Jos

            ps. how come that mysterious error message you mentioned before disappeared automagically?

            Comment

            • DeadSilent
              New Member
              • Feb 2009
              • 8

              #7
              Ohh its still there, I'm just going to research swing more in depth and hope I can get something figured out before tomorrow.

              Comment

              • JosAH
                Recognized Expert MVP
                • Mar 2007
                • 11453

                #8
                Originally posted by DeadSilent
                Ohh its still there, I'm just going to research swing more in depth and hope I can get something figured out before tomorrow.
                You can't expect a program to run correctly (or run at all) when such error messages are printed. What exactly issued that message? The compiler? The Java virtual machine itself? Something else?

                kind regards,

                Jos

                Comment

                • DeadSilent
                  New Member
                  • Feb 2009
                  • 8

                  #9
                  Read my first post, I believe I stated the issue clearly. :\

                  Comment

                  • JosAH
                    Recognized Expert MVP
                    • Mar 2007
                    • 11453

                    #10
                    Originally posted by DeadSilent
                    Read my first post, I believe I stated the issue clearly. :\
                    Yes you did and you immediately forgot all about it and mentioned another problem (Swing related); that's why I kept asking about it. Don't add more problems to the problem pool but first solve the original problem(s).

                    kind regards,

                    Jos

                    Comment

                    • DeadSilent
                      New Member
                      • Feb 2009
                      • 8

                      #11
                      LOL! Sorry about that, I got confused for a second.

                      Comment

                      • Yarn
                        New Member
                        • Mar 2009
                        • 1

                        #12
                        For the exporting non-public type through public API thing, try making the method headings just void getCircleInfo ( Circle circle ) and void drawCircle ( Circle circle ). Take away the publics. Because every class in the program is part of one package, all the classes should be able to access the methods and fields from all other classes in the package even if the methods and fields have no public-private declaration. So this should work, because it gets rid of the public API, but still allows all classes access. I'm not sure exactly why all this happens, but I get the same thing with NetBeans when I try to use certain classes as parameters. I've found that this usually makes the IDE shut up. I've used other compilers/editors (i.e.) JCreator and this seems to be a problem specific to NetBeans. As for the paintComponent( ) method, chances are that it is in one of those collapsed sections of uneditable text that are generated by the design panel.

                        Comment

                        • ZRJavelin
                          New Member
                          • Mar 2009
                          • 3

                          #13
                          it's the Circle Class

                          The warning is coming from your line five (5): the class Circle has no designation [i.e. public, private, etc];

                          Make it public and warning will disappear.
                          Last edited by ZRJavelin; Mar 27 '09, 03:36 PM. Reason: make more complete

                          Comment

                          • ZRJavelin
                            New Member
                            • Mar 2009
                            • 3

                            #14
                            As to your other issues, only Classes should be capitalized; for the sake of future debugging efforts, change your variables [like Radius to 'radius'] to lower-case, so in-code references do not imply it is a reference to a static Class.

                            Comment

                            • ZRJavelin
                              New Member
                              • Mar 2009
                              • 3

                              #15
                              You are getting a Circle...

                              Based on your codes:
                              // Constructors
                              public Circle ( ) {
                              //setRadius(0);
                              this(0);
                              }

                              public Circle ( double r ) {
                              setRadius(r);
                              penColor = Color.BLACK;
                              fillColor = Color.WHITE;
                              XCord = 0;
                              YCord = 0;
                              }
                              and from shapemaker

                              public void start ( ) {
                              Circle circle = new Circle ( );
                              getCircleInfo(c ircle);
                              drawCircle(circ le);
                              }
                              Your constructor for a Circle requires a radius parameter; your default is 0 and no other value is passed; I contend you ARE drawing a circle, though one of radius = 0, at coords (0,0).

                              Comment

                              Working...