Can't getGraphics from JPanel

Hi,
I want to get the graphics context from a JPanel so I can draw on it. In the example below, theStage ends up null, causing a null pointer exception - where am I going wrong??
class win extends JFrame{
      Container c;
      win(){
            stage stage = new stage();
            c = getContentPane();
            c.add(stage);
            setSize(400,400);
            setResizable(false);
            setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            setVisible(true);
      class stage extends JPanel {
                  stage(){
                     Graphics2D theStage = (Graphics2D)getGraphics();
                     theStage.drawLine(0,0,100,100);
}big thanks for any help,
Des

Swing questions should go in the Swing forum.
And the "drawLine" call should go in the paintComponent method. You need to override the JPanel's paintComponent method to do your drawing.
The Graphics is null because the JPanel isn't visible yet.

Similar Messages

  • I am sharing a apple id acount with my family but when i synced my phone to the computer it erased all of my imformation and put the other phone's imformation on it. I was wondering how I can prevent this from happening?

    I am sharing a apple id acount with my family but when I synced my iphone to the computer it erased all of my imformation and put the other phone's imformation on it. I was wondering how I can prevent this from happening?

    If the ringtones are on the old device just plug it in and do a transfer of purchases then they will be on the computer to sync to the new device.

  • I have a game but it only for one apple id and one divece but someone i dont know id play that game and using my apple id and i want to know if u can block them from using ur apple id and also erase all the games they downlode with the apple id

    I have a game but it only for one apple id and one divece but someone i dont know id play that game and using my apple id and i want to know if u can block them from using ur apple id and also erase all the games they downlode with the apple id

    There probably is, but it requires that you be able to use punctuation and write in sentences so that we can understand exactly what you want.
    You can block others from using your Apple ID by changing your password.  There is no way to erase what was already downloaded on to someone else's device, for obvious reasons,

  • MFP M127fn connected, test printing OK, can't print from applications

    Hello Everyone!
    I have just set up my M127fn via USB on a Windows 8 system. The set up went fine. I have a small stack of test pages from the HP software, but it won't print anything from any applications like MSOffice. The HP diagnostic software (Print and Scan Doctor 4.6)  can communicate with the printer and everything checks out OK.
    Any suggestions?
    Thanks in advance.

    Hello! 
    I have replied twice to your last posting, but have heard no response. Unless a solution can be presented quickly, I fell I must return the product. LPug and play was introduced with Windows 95 and this HP product has not lived up to that 20 year old technological standard. My previous replies are copied below.
    Please respond soon.__________________________________________
    Re: MFP M127fn connected, test printing OK, can't print from applications
    Options 
    ‎01-31-2015 08:06 AM
    Hello again!
    I haven't heard a response to my most recent reply. Is there anything you can suggest before I give up and return this HP product to the store? I would like a quick resolution to this. As an update to my previous email (copied below), printing is no longer working through Adobe Reader.
    Thanks,
    Chris
    Re: MFP M127fn connected, test printing OK, can't print from applications
    Options 
    ‎01-28-2015 01:08 PM
    Hi,
    Thanks for getting back to me. I have tried a variety of different programs:
    Mozilla Thinderbird (email) - no results
    MS Word - no
    ms excel - no
    Finale (music software) - no
    Adobe Reader - yes!
    Google Chrome - yes!
    NotePad - yes!
    perplexing!

  • Windows Easy Transfer (WET) Issues with External Hard Drive - "Can't read from the source file or disk"

    I work for Office Depot, in the tech department. Basically, one of our associates was supposed to do a data backup, and re-install Windows 7, then transfer the files back. He used Windows Easy Transfer and compacted everything into a 163 GB file. 
    Now comes the hard part. When we try to put it back on his computer ((drag-and-drop to the desktop) which has been wiped back to factory settings using the recovery partition), it stops at 79.5 GB remaining (you know how it doesn't give you a % of completion,
    it just shows how many GB are remaining) and then says "Can't read from the source file or disk" and gives you an option to try again, or cancel. It gets hung up on the same point each time.
    Normally, this wouldn't be a huge issue, but the contents on the drive are his wife's architect blueprints and interior design stuff, along with wedding photos, etc, which are the only copies they have. On top of those, they have court documents and other
    important files that we are unable to access now.
    I wasn't involved with this transfer, so I'm trying to clean up the mess as best I can. I remembered that the customer's wife was Russian, and had some files typed with a Russian keyboard, so on and so forth. I wonder if that's the issue? If not, I really
    have no idea how to manually extract things from a ".mig" file, or how to diagnose what area is potentially corrupted.
    In light of this situation, we tried using "Recuva" to recover the files post-wipe, but everything was corrupted or unable to be opened, and it also extracted and recovered all of the "useless" photos, such as the skype logos, up and
    down arrows for browsers, etc (it was 160,000+ photos).
    Trying to avoid a potential lawsuit, unhappy customer, and costing the company lots of money to see if professionals can get into this external hard drive.
    Other relevant information:
    We used a Toshiba 500 GB (465 GB) external hard drive.
    Customer's computer is an HP Pavilion P6000 Series (Model No. p6520y) running Windows 7 Home Premium 64-bit Service Pack 1.
    Any other information that is needed can be provided, thanks in advance, and hopefully we can find a solution to this issue quickly!
    -John

    I think there's a lack of understanding somewhere.
    "If you even can't start the process, please unplug it from your new PC. Then head back to your new computer and plug
    the external drive back in to your new computer. "
    Unplug from new, head back to new, plug it back in? That doesn't make much sense! Haha.
    I knew what you meant though, somewhat. When I search through the drives after clicking yes (Has windows easy transfer
    already saved your files blah blah blah) I click on the transfer file and it says "Windows Easy Transfer could not open the file".
    Rather than drag-and-drop the file to the desktop, I now tried to double-click on the file itself while it was plugged
    into the computer. It opened, and it started transferring until it was about 70% completed, and then an error popped up saying "WET can't open the easy transfer file, make sure your USB device is plugged in or check your internet connection". 
    I checked, and the USB hard drive's light wasn't on. Now, I unplug it and plug it back in, and the light comes back on,
    so I click Retry, and it resets the bar back to nothing and says "Transfer time: 1 minute".
    Rather than continue trying, I clicked "Cancel" instead of Retry, and it says "Your transfer did not complete successfully."
    It says to click "view report" for more information, but there's no "view report button".
    At the moment, I am scanning the External Drive for bad sectors using the check disk tool in properties. It's frozen
    at "0 USN bytes processed".

  • Can not select from SAPTOOLS.DB6PMCF

    We use third-party tool to monitor our SAP systems. We receive an error
    Can not select from SAPTOOLS.DB6PMCF
    when we monitor DB2 database.
    Function DB6PMCF is registered in SAPSID schema. Can I register it also in SAPTOOLS schema? What is a correct procedure for this?

    Hi Milan,
    I think you have to issue the following command for the affected user.
    db2 "grant execute on function saptools.db6pmcf to <user>"
    regards, Javier Rocha

  • Can not print from preview after Lion Update

         I can't print from preview since I updated to Lion. After I hit command P or select print from the file tab preview totally freezes up and gives me the spinning wheel of death until I force quit preview. I have no issues printing from anything else, such as word, excel, web pages.  So I don't think it's a printer/driver error.  Help?

    I would still mention what printer you have and make sure you have the latest printer driver.

  • Can not cast from object to int

    Hi All,
    I have the following bunch of code
    Session session;
              session = getSessionFactory().openSession();
              Query query;
              int MaxPageId = 0;
              List list;
              try{
                   query = session.createQuery("select max(emp.id) from EmpBean emp");
                   list = query.list();
                   MaxPageId = (int) list.get(0);
                   return MaxPageId;
              catch(Exception e){
                   System.out.println(e.getMessage());
              return MaxPageId;
    The query executed successfully but when i get the max id in a integer variable by the following statement
    MaxPageId = (int) list.get(0);
    I get the following error "can not cast from object to int"
    Please suggest for the same.
    -Thanks

    Cast to an Integer, not an int, and let autoboxing turn the Integer into an int.
    int maxPageId;
    maxPageId = (Integer) list.get(0);You can't cast objects into primitives.
    Autoboxing isn't casting.
    And use Java naming conventions. Local variables start with a lower-case letter.

  • Can I Select from table skipping extents linked with lost datafiles?

    Hi~,
    I need your help to recover my database.
    I'm using oracle 9.2.0.8 at Fedora 3 with no-archive mode.
    and I don't have any backup.
    Last night, I experenced hard disk failure.
    I tried OS-level recovery, but I lost some datafiles of tablespace.
    anyway, I wanted to recover my database without data of lost datafiles.
    so, I issued "alter database datafile offline drop" and
    start oracle instance.
    But, datafiles were not removed from dba_data_files view and
    extents linked with lost datafiles were not removed from dba_extents view!
    Selecting query of some table containing extents linked with lost data files,
    I got "ORA-00376: file xxx cannot be read at this time" message.
    So, my question is that..
    HOW CAN I SELECT FROM THAT TABLE WITHOUT SCANNING EXTENTS LINKED WITH LOST DATA FILES?
    Thanks.

    Hi,
    Without being in archivelog and without backup, one can't do any sort of recovery. That's why backups and archivelog are so so important.
    The offline data file command never does actually drop the datafile. It merely indicates to the control file that now the said tablespace will also be dropped. This won't update any view that the files are not supposed to be used or shown to you anymore.
    This is what documentation says about the recovery of the database in the NoARch mode,
    http://download.oracle.com/docs/cd/B19306_01/backup.102/b14191/osrecov.htm#i1007937
    You do need a backup in order to get those tables being read. Oracle doesn't have any feature which can offline/skip the missing extents for you and let you read the data without them.
    HTH
    Aman....

  • Unable to print from my desktop but I can print wirelessly from my tablet

    I have an HP Officejet 4620 all-in-one wireless printer that worked fine until I switched from a Verizon to an Xfinity router. The printer is not communicating with my desktop [a Gateway], which is using Windows 7, however I can send things from my tablet [ipad] to the printer wirelessly and it prints no problem. I tried to troubleshoot but kept getting pop-ups and I just don't trust saying "Yes" to any of that crap, I've had so many problems with viruses through the years. can you help me please?

    We switched from Verizon to Comcast and in the process of switching we lost the ability for my desktop to communicate with my wireless printer [HP 4620]. I could still print from my Ipad, but that was it. In my quest for help I went to the HP help center. I downloaded new drivers for both of my laptops and they were able to print wirelessly. I thought I would do the same for my desktop. But did not need to. I tried printing a document I was working on, and was very surprised when my printer responded. All is well! Thanks for the Forum. It's great to know this type of support is available.

  • I cannot send email - error message as follows : 'The sender address (my email address) was rejected by the server smtp.tiscali.co.uk.' I can send email from other apple devices, and the email settings are identical. Any ideas?

    For some reason I cannot send email - all was working fine, but now I get the following error message when I try to send email:
    'The sender address (my email address) was rejected by the server smtp.tiscali.co.uk'
    I can receive incoming mail ok and I can send email from other Apple devices. The problem seems confined to my Mac Book Pro.
    Ant ideas?

    Hello there, Pablo639.
    The following Knowledge Base article offers up some great steps for troubleshooting mail issues on your Mac:
    OS X Mail: Troubleshooting sending and receiving email messages
    http://support.apple.com/kb/TS3276
    Thanks for reaching out to Apple Support Communities.
    Cheers,
    Pedro.

  • TS3276 I can receive emails, but I cannot send emails. This just started happening. I have an iPhone and I can send emails from my phone fine. It's just not working on my Macbook. Every time I try to send an email it goes straight to my outbox. Can anyone

    I can receive emails, but I cannot send emails. This just started happening. I have an iPhone and I can send emails from my phone fine. It's just not working on my Macbook. Every time I try to send an email it goes straight to my outbox. Can anyone help?

    Thank you for heading me in the right direction.  I reset my Mail account for Outgoing Mail Server to outbound.att.net:(customer ID)@att.net (instead of smtp.att.yahoo.com, per Apple's online troubleshooting information).   I'm not sure what "(Offline)" means when it appears at the end of my Outgoing Mail Server (SMTP)??  In the Advanced box I clicked on "Use custom port:  465" and checked "Use Secure Sockets Layer."  Authentication:  Password; I have correct User Name and Password put in.  After doing all this, when I try to send emails again today, they go directly to the Outbox and sit there. 
    What's curious is that my first sent email this morning did go out using the Outgoing Mail Server, smtp.att.yahoo.com: (customer ID)@att.net(Offline) but subsequent emails I tried to send with this server were rejected with the message:  "Cannot send message using the server smtp.att.yahoo.com (etc.).  The SMTP server doesn't support TLS(SSL) on port 587.  Verify your account settings and try again."  That's when I tried resetting my Outgoing Mail Server to outbound.att.net (etc.), as mentioned above, and was unsuccessful in sending out any further emails.  I guess my next step is to contact my email service provider, AT&T, and see if they can help me.  Thanks, again, for taking the time to respond and for giving me your input!  Much appreciated!

  • TS3276 I cannot connect to my outgoing email server on my macBook pro, yet I can, for the same email account on my iPad. Also I can send emails from the other email account I have on my MacBook...really confused can anyone help?

    I cannot connect to my outgoing email server on my macBook pro, yet I can, for the same email account on my iPad. Also I can send emails from the other email account I have on my MacBook...really confused can anyone help?

    Sometimes deleting the account and then re-creating it can solve this issue
    Write down all the information in accounts before doing this
    Highlight the account on the left and click the minus button
    Then click the plus button to add the new account and follow the prompts

  • TS3899 I have set up two email accounts on my iphone4, one with tiscali, my ISP, and the other on gmail. I am able to receive emails on both accounts, and can send emails from my gmail account, but am "Unable to Send Email" from my tiscali (talktalk) acco

    I have set up two email accounts on my iphone4, one with tiscali, my ISP, and the other on gmail. I am able to receive emails on both accounts, and can send emails from my gmail account, but am "Unable to Send Email" from my tiscali (talktalk) account. I get the error message "A copy has been placed in your Outbox. The sender address "name"@tiscali.co.uk was rejected by the server".

    Hi apmichael,
    If you are having issues sending email from one of your mail accounts on your iPhone, you may find the following article helpful:
    iOS: Troubleshooting Mail
    http://support.apple.com/kb/ts3899
    Regards,
    - Brenden

  • How to log in with my old Apple account? I forgot my pass and I did change my apple ID before canceling first?? I am from Croatia so did folow al the discussion and the to resolve the problem but no luck. Can not call from Croatia the Apple help desk

    How to log in with my old Apple account? I forgot my pass and I did change my apple ID before canceling first?? I am from Croatia so did folow al the discussion and the to resolve the problem but no luck. Can not call from Croatia the Apple help desk.i did try all the options but I can not find the phone number to call from Croatia,
    I can not change my Apple ID to the old mail (not possible!)
    The old mail don't accept the new password..
    I can not delete the Icloud all the time asking my the password of the old mail!
    I realy need help

    You can not merge accounts.
    Apps are tied to the Apple ID used to download them, you can not transfer them.

Maybe you are looking for

  • Shared photos/videos not appearing in streams on originating imac, only icloud icon

    I share pictures and photos to icloud from Aperture 3.5.1. The photos and videos are available on other devices that share the same icloud stream, but in Aperture on the originating imac, when I look in the "icloud" section at the photo streams, I se

  • Connect to hd tv

    hello, i usually use to burn quicktime movies onto dvd which i play on ordinary dvd player. but what do i need or have to do in order to play the quicktimemovie i edited in fce 4.01 1920x1080i50 directly on to my hd philips tv. what kind of cables, q

  • HIERARCHIAL QUERY

    TBL_REPORTS REPORT_ID REPORT_NAME TBL_RPT_CATEGORIES RPTCAT_ID RPTCAT_NAME REPORT_ID RPTCAT_PID RPTCAT_NAME TBL_RPT_CATEG_CONTRPTCONTENT_ID REPORT_ID RPTCAT_ID DESCRIPTION Notes:- 1. REPORTS  RPT_CATEGORIES  RPT_CATEG_CONT One to many relationship

  • GROSS MARGIN 100%

    Hello I have a sales BOM assembly type, when I book an invoice the gross margin calculation is 100% as the base price is empty. It does not copy the component cost price. But the GL account is correct cost of goods is equal to the componentn cost of

  • Why is new adjustment layer hue/saturation grayed out?

    I am working on this text tutorial and when I get to step 19, my options are grayed out.