Right i managed to get a simple example going that will draw a simple shape to a jpanel, but in the main it calls Shape and draws everything in paint. so i just get 3 shapes on top of each other. How would i be able to call in main say draw circle and have it draw only a circle. Then maybe draw circle leave appropiate gap draw square on jpanel?
Hey, Thanks for your help so far. Ok ive gone a new direction. I found an example and edited it, it displays a circle, square and line all one after another. Ill post code to shoe ye;
and also main to run the JPanel
So thats all good, but the thing is i cant seem to apply any BorderLayout to the shapes, i want to display them one after another on new lines. eg Circle Square line In that kind of order, opposed to left to right. Can someone tell me how this can be done thanks. Mark
Na im afraid im still stuck. i created a class which creates shapes and stuff. In my main class if i run the shapes are displayed, but if i add a label it does not appear when i try to use gridlayoutmanager, absolute positioning. it either display blank frame or just the shapes. I tried layout manager but its not accurate enough im afraid. I just need a way to declare a label in main and specify where to put it on a frame that contains the shapes i created in my class? So i suppose is there a way to use the same frame created in my class in my main without creating a new one? Im not sure really what to do .
If you really want to use components and add them to a parent container which has graphics on it you can do it. Another option is to do all graphics. Here you would draw the label with the drawString method. You can get/create a Rectangle around the string and fill/draw it with color(s) for decoration. Here's a taste of each:
I am having an issue that seems to be a bit similar to this, although I haven't read the above posts overly thoroughly. I can't get an image to display in a JFrame. If someone could take a look at my code and tell me what my mistakes are, that would be fantastic and i would be extremely grateful.
NOTE: This code does not give me any errors, it just fails to display the image in the JFrame. Also, I have used "10" as my int for most of it, so if this is an issue could someone please tell me how to fix it? As far as I have been able to decipher from the API, the ints here mainly control size and positioning.
Nick LiMuti wrote:I am having an issue that seems to be a bit similar to this, although I haven't read the above posts overly thoroughly.
Then I suggest you start by reading the above posts. The solution has definitely been discussed. In short, you should not use getGraphics().
I said it was similar to this, not exactly the same. I do not want to draw a shape to the screen, I want to add an image to the JFrame. However, I have found another way to do this, although it would be great if someone could please tell me a different way, as this doesn't seem like the correct way to do it. Unless it is, in which case never mind. Also, if using an image is the same as using a Graphics object then I will definitely look further into it. My teacher said that it isn't though (although she may be incorrect).
If you would have read this thread you would have found out that the proper solution was to create a JPanel subclass, override paintComponent, and paint the image inside that method. The image should be loaded outside of the paintComponent: