469,366 Members | 2,254 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,366 developers. It's quick & easy.

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.

Expand|Select|Wrap|Line Numbers
  1. package shapemaker;
  2.  
  3. import java.awt.*;
  4. import javax.swing.*;
  5.  
  6. public class ShapeMaker {
  7.  
  8.     private JFrame win;
  9.     private Container contentPane;
  10.  
  11.     public ShapeMaker (  ) {
  12.         win = new JFrame("Shape Maker");
  13.         win.setSize(400, 300);
  14.         win.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  15.         win.setVisible(true);
  16.         contentPane = win.getContentPane();
  17.         contentPane.setBackground(Color.WHITE);
  18.     }
  19.  
  20.     public static void main(String[] args) {
  21.         ShapeMaker shapeMaker = new ShapeMaker();
  22.         shapeMaker.start();
  23.     }
  24.  
  25.     public void start (  ) {
  26.         Circle circle = new Circle (  );
  27.         getCircleInfo(circle);
  28.         drawCircle(circle);
  29.     }
  30.  
  31.     public void getCircleInfo ( Circle circle ) {
  32.         double radius;
  33.         int x, y;
  34.         radius = Double.parseDouble ( JOptionPane.showInputDialog (win, "Enter Radius") );
  35.         circle.setRadius(radius);
  36.         circle.setFillColor(Color.orange);
  37.         circle.setPenColor(Color.black);
  38.         x = Integer.parseInt( JOptionPane.showInputDialog ( win, "Enter X Cord:" ) );
  39.         circle.setXCord(x);
  40.         y = Integer.parseInt( JOptionPane.showInputDialog ( win, "Enter Y Cord:" ) );
  41.         circle.setYCord(y);
  42.     }
  43.  
  44.     public void drawCircle ( Circle circle ) {
  45.         Graphics g = contentPane.getGraphics();
  46.         circle.draw(g);
  47.     }
  48. }
Feb 21 '09 #1
14 13358
Nepomuk
3,112 Expert 2GB
Could we have a look at that Circle class? Also, when do you get this error?

Greetings,
Nepomuk
Feb 21 '09 #2
The error I get is that no circle comes up when I run this code and I am not sure why.

Circle Class:
Expand|Select|Wrap|Line Numbers
  1. package shapemaker;
  2.  
  3. import java.awt.*;
  4.  
  5. class Circle {
  6.  
  7.     private double Radius;
  8.     private int XCord, YCord;
  9.     private Color penColor, fillColor;
  10.  
  11.     // Constructors
  12.     public Circle ( ) {
  13.         //setRadius(0);
  14.         this(0);
  15.     }
  16.  
  17.     public Circle ( double r ) {
  18.         setRadius(r);
  19.         penColor = Color.BLACK;
  20.         fillColor = Color.WHITE;
  21.         XCord = 0;
  22.         YCord = 0;
  23.     }
  24.  
  25.     // Set Methods
  26.     public void setRadius ( double r ) {
  27.         Radius = 0;
  28.  
  29.         if (r > 0) {
  30.             Radius = r;
  31.         }
  32.     }
  33.  
  34.     public void setXCord ( int x ) {
  35.         XCord = 0;
  36.  
  37.         if (x > 0) {
  38.             XCord = x;
  39.         }
  40.     }
  41.  
  42.     public void setYCord ( int y ) {
  43.         YCord = 0;
  44.  
  45.         if (y > 0) {
  46.             YCord = y;
  47.         }
  48.     }
  49.  
  50.     public void setPenColor ( Color pen ) {
  51.         penColor = pen;
  52.     }
  53.  
  54.     public void setFillColor ( Color fill ) {
  55.         fillColor = fill;
  56.     }
  57.  
  58.     // Get Methods
  59.     public double getArea (  ) {
  60.         return Math.pow( ( Math.PI * Radius ) , 2 );
  61.     }
  62.  
  63.     public double getCircumference (  ) {
  64.         return ( Math.PI * ( Radius * 2 ) );
  65.     }
  66.  
  67.     public void draw ( Graphics g ) {
  68.         int width = (int) (Radius * 2);
  69.         int height = (int) (Radius * 2);
  70.         g.drawString("This", -10, -10);
  71.  
  72.         g.drawOval(XCord, YCord, width, height);
  73.         g.setColor(penColor);
  74.         g.fillOval(XCord, YCord, width, height);
  75.         g.setColor(fillColor);
  76.  
  77.         g.dispose();
  78.     }
  79. }
  80.  
Feb 22 '09 #3
JosAH
11,448 Expert 8TB
@DeadSilent
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
Feb 22 '09 #4
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?
Feb 22 '09 #5
JosAH
11,448 Expert 8TB
@DeadSilent
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.

@DeadSilent
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?
Feb 22 '09 #6
Ohh its still there, I'm just going to research swing more in depth and hope I can get something figured out before tomorrow.
Feb 22 '09 #7
JosAH
11,448 Expert 8TB
@DeadSilent
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
Feb 23 '09 #8
Read my first post, I believe I stated the issue clearly. :\
Feb 23 '09 #9
JosAH
11,448 Expert 8TB
@DeadSilent
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
Feb 23 '09 #10
LOL! Sorry about that, I got confused for a second.
Feb 23 '09 #11
Yarn
1
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.
Mar 4 '09 #12
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.
Mar 27 '09 #13
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.
Mar 27 '09 #14
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(circle);
drawCircle(circle);
}
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).
Mar 27 '09 #15

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

1 post views Thread by Janne Ruuttunen | last post: by
reply views Thread by Mike P | last post: by
1 post views Thread by Mustufa Baig | last post: by
7 posts views Thread by victorsk | last post: by
reply views Thread by =?Utf-8?B?ZGVuIDIwMDU=?= | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.