Trying to draw a 2D shape, but Graphics2D is null, what am I doing wrong?
At this point, I just want a shape to appear. But when I call draw(...), I get a NullPointer. Turns out when I call getGraphics() on the input JFrame (which does show up properly when the rest is commented out), I get nothing. Maybe it's the casting, I don't know enough about this issue to really say. If anyone out there has worked with 2D primitives and can shed some light on the problem, I would appreciate it.
Thanks for any help.
public class BatteryDisplay extends JPanel {
Graphics2D g2d;
Rectangle2D.Double rect1;
JFrame jf;
public BatteryDisplay(JFrame jf)
this.jf = jf;
// Is there another way to get the graphics object?
g2d = (Graphics2D) jf.getGraphics();
createRectangle();
drawRectangle();
public void createRectangle()
rect1 = new Rectangle2D.Double(100,100,200,50);
System.out.println(rect1.height);
// The next line returns the NullPointer, so g2d is NOT initalized
System.out.println(g2d);
public void drawRectangle()
this.g2d.draw(rect1);
}
Your painting functions should be initiated from an overridden paintComponent, not from the constructor. A graphics object will be provided to you there.
[http://java.sun.com/docs/books/tutorial/uiswing/painting/index.html]
Similar Messages
-
I keep getting this error in Dreamweaver when I am trying to upload my website? Can you tell me what I am doing wrong? here is the error message: /html - error occurred - Unable to create remote folder /html. Access denied. The file may not exist, or there could be a permission problem. Make sure you have proper authorization on the server and the server is properly configured. File activity incomplete. 1 file(s) or folder(s) were not completed. Files with errors: 1 /html
Nobody can tell you anything without knowing exact site and server specs, but I would suspect that naming the folder "html" wasn't the brightest of ideas, since that's usually a default (invisible) folder name existing somewhere on the server and the user not having privileges to overwrite it.
Mylenium -
I follow the instructions of swiping up from the bottom for the control panel, but nothing appears. What am I doing wrong or what do I need to be turned on or off?
"If you're on your home screen, where your apps and folders are, you can't."
I can on mine.
For anyone having this issue, take your device out of the case and try it naked before trying a reset, restore or Genius Bar appointment. -
I originally set up my iTunes account on my computer at work, now that I have a home computer and authorized it, i have not been able to sync my apps from my iTouch to my home coumpter, it transferrred my music but nothing else. What am I doing wrong?
Hello John,
It sounds like your music was copied from your iPod Touch but not your installed apps. I want to recommend this article to help you Transfer your Purchases named:
iTunes Store: Transferring purchases from your iOS device or iPod to a computer
http://support.apple.com/kb/ht1848
You can also download your apps using your purchased history in iTunes with this article:
iTunes 11 for Mac: Download previous purchases from the iTunes Store
http://support.apple.com/kb/PH12283
Click iTunes Store near the top of the iTunes window.
Click the Purchased link at the right of the iTunes Store homepage (below Quick Links).
In the page that appears, select a category.iTunes shows you which of your purchases are available for download. You can view all of your past purchases, or just the ones not currently in your iTunes library. Items already in your library aren’t available for download.If you select Music, you can view your purchases by song, artist, or album. If you’re viewing by album, click an album to see which songs on it are available for downloading.To search for an item, type its name or a keyword in the search field, and then press the Return key to view your search results.
To download an item, click its Download button .To download all available items, click Download All.
Thank you for using Apple Support Communities.
All the best,
Sterling -
trying to face time from my macbook to my Ipad butit wont work when i click on my emal address what am i doing wrong?
so are the mac and ipad on the same itunes id and same email account via facetime in settings on ipad if there on the same receve calls from email then when you click on your email adress its like your trying to call to the exact mac does that mac sence
-
Can't send Mail on Mac Mail, but can on Entourage - what am I doing wrong?
Aggg. Help.
I have been using Entourage on my Macs, and have decided to switch to Mac Mail. I have multiple accounts for my websites on my dedicated server. I use standard ports for sending and receiving mail - and, as it is my server, I can dictate all controls.
So... I can receive mail on my Macs, but can not send. I am trying to set-up IMAP accounts - and my server requires i use as outgoing" mail.mywebsite.com
I use a linux server using cPanel.
It works on Entourage. But Mac's Mail will not accept the outgoing mail information. I have tried with and without authentication (which is required). I have overridden the port and tried each individually (25, 465, etc..). I have tired smtp.mywebsite.com rather than the required mail.mywebsite.com, just to see. I have tried every combination of information with no luck. I sort of think I know how to set it all up, but can not understand what I am missing?
Why can I not get Mac Mail to send?
I can match what is in use by Entourage - but it just does not work.
I use MS Office 2008's Entourage - and to make things more fun, Mac Mail will not import my Entourage accounts (says it can not find them). I am using a 3 month old iMac with latest OS. I have been on Macs since 1988 - so I just don't get what is going on. HELP PLEASE. Puuuullleeeeeaze.
thanks!Hello,
If you open the Activity viewer (click on Window in the menubar and choose Activity) and watch when you try to send, what phases if any are indicated are taking place before failure?
What type of authentication is required for this SMTP? When using in Entourage, what are the selections in Advanced sending options, particularly regarding the box beside Use same settings as receiving mail server?
Ernie -
I have bought loads of music off itunes before and loaded to my iphone. I recently bought an album that for love nor money will not load to my iphone although is clearly visible in my itunes account. I have tried removing it and resyncing it, reloading it, syncing and then reloading the whole phone but still to no avail. Any ideas what I might be missing!?
Thankies
SarahHey Sarah!
Have you updated your phone to iOS 5.1.1? I know the most recent update aided to resolving this issue. If you have updated, though, does the album look like its downloading and then stops or "crashes" at the very end? -
I synced my iPod touch to iTunes and am able to watch the movie on mu ipod. tried again in itunes and the program still closes.0
5 different keys? Why?
-
I am trying to watch movies from my macbook pro (2010) on my new vizio tv. I connected the minidisplayport to HDMI cable (bought from the apple store) and switched the input to the right input but nothing happens. What am I doing wrong?
Hi T,
Open Sys Prefs > Displays and check the settings there. -
I purchased a HDMI cable to watch movies and slide shows from my mac book pro to my Sony Bravia TV. I get picture through the TV but no sound. What am I doing wrong?
Go to sounds in system pref and select outputs. When the hdmi cable is plug into the tv it will show as an option under output. Just select that option.
-
Trying to draw a diamond shape from a shape - Please help !!!
Hi,
I am trying to draw a diamond shape from a custom shapes library but having a hard time getting it to shape accurately, the shape I am trying to draw should look like this :
If someone can teach me some photoshop techniques as to how to get all the angles reshaped accurately using some photoshop tools that will be great or if you can do it in my project file that will help too, the project psd file can be downloaded from here : http://tonyalepski.heliohost.org/Diamond.psd
Your help would be really really appreciated.
Thank you very much !!
Tonya.Your diamond looked like it was square to me. So I centered your diamond over your canvas add a vertical guide at 50%. Measured your square to be 190 PX Dragged out a 190 PX square shape no fill 1 px red stroke. Transformed the shape rotating it 45 degrees and moved it up to align with your diamond. Dragged out a horizontal guide to match your diamond cut. Used the Pen tool to add two control points the square shape. and then use the pen tool to delete the top control point then convert control point tool to convert the two added control points.
http://www.mouseprints.net/old/dpr/Diamond.psd -
Hi, I am trying to blur the background in Prem Pro CC I have made a mask using the free draw bezier tool but it does not track forward. What am I doing wrong?
Hi Kevin
I found a YouTube clip explaining how to blur the background with free draw bezier tool and it also said to invert the mask, but it still does not track forward. I really hope there is a solution.
Steph -
I am creating webpages with frontpage and trying to make collapsible lists. The lists collapse and work correctly in "preview" mode, but do not work when accessed through firefox or explorer 8. Does anyone know what I am doing wrong?
Welcome to the 'wonderful' world of HTML5 e-learning.
In my view, from the issues I am seeing everywhere, HTML5 output from rapid e-learning tools such as Captivate is not ready for the kind of mobile device e-learning you want to develop.
Sorry to be pessimistic, but you may need to consider going back to the drawing board and coding it from the ground up. -
Help....I am trying to set up iClould on my pc....the set up was complete....when I try to sign in to set up it says the Apple ID is valid but is not an iCloud account. Please help me and tell me what I am doing wrong. Thx
Hi DesCoop,
You must initiallly activate iCloud from an IOS device or a Mac. You cannot inititally activated from a PC.
Sorry.
GB -
I am trying to burn a cd from my itunes playlist but it keeps canceling my burn and says their is an error 4450. What am I doing wrong?
Could you post your diagnostics for us please?
In iTunes, go "Help > Run Diagnostics". Uncheck the boxes other than DVD/CD tests, as per the following screenshot:
... and click "Next".
When you get through to the final screen:
... click the "Copy to Clipboard" button and paste the diagnostics into a reply here.
Maybe you are looking for
-
Unable to get checkbox working in Apex 3.2.1.00.10
We recently upgraded our production application running on apex to Apex 3.2.1.00.10. Everything works, except for the query that generates the check-box. This used to do so in the previous version 3, but does not work anymore, the code is the same...
-
I bought this iSight used from a friend and the image is too dark. My friend never used it so, he doesn't know anything. When I use iChat, Skype or Photobooth, the image is just too dark. I have looked endelessly for a solution and can't seem to find
-
[SOLVED] USB storage devices do not appear as /dev/ block devices
Hello. I'm experiencing the exact same problem described in this thread and this thread I'm running linux-ck-ivybridge. Both of these threads are marked solved but I don't get their solutions. Could someone help me understand what all this means? I t
-
Why my Mac cant find the update of final cut X ?? I click on the software update but there are no updates Is it cos I have Final cut Pro 7 and the finalcut X is in an other folder ?
-
Verdana Font not printing properly using Vista and Acrobat Pro v8
Has anyone got any ideas as to how I can fix this problem. When I send a word doc to the pdf printer that is all in verdana font it prints out gibberish, however, if in aerial or times new roman thats fine. I'm using Vista and printing via a termin