Nothing come out from Canvas, pls help!

No error but nothing come out. Please help!
import java.applet.*;
import java.awt.*;
import java.awt.event.*;
public class StGeorgeFlag extends Applet implements ActionListener{ //, MouseListener, MouseMotionListener{
     Panel p;
     MyCanvas mycanvas;
     PlayButton play;
     ConfirmButton confirm;     
     SolutionButton solution;
     Dimension d;
     Graphics g;
     public void init(){
          int width = getSize().width;
          int height= getSize().height;
          p = new Panel();               
          setBackground(Color.lightGray);
          MyCanvas mycanvas = new MyCanvas();  // create the canvas          
          mycanvas.setSize(width-4, height-4);
          play = new PlayButton(this);
          confirm = new ConfirmButton(this);
          solution = new SolutionButton(this);
          add(play);
          add(confirm);
          add(solution);
          p.setLayout(new GridLayout(1,4,3,3));
          p.add(play);
          p.add(confirm);
          p.add(solution);
          setLayout(new BorderLayout(3,3));       // button border
          add("Center",mycanvas);             // add canvas and controls to the applet
          add("South",p);
     public void actionPerformed(ActionEvent e){
         if (e.getSource() == play) mycanvas.rectangle();                       
              else if (e.getSource() == confirm) mycanvas.rectangle();
               else if (e.getSource() == solution) mycanvas.solution();
     public void mousePressed(MouseEvent me){}
     public void mouseDragged(MouseEvent evt) {}
     public void mouseReleased(MouseEvent me){}
     public void mouseClicked(MouseEvent me){}  
     public void mouseEntered(MouseEvent me){}       
     public void mouseExited(MouseEvent me) {}
}  // end Class StGeorgFlag
class MyCanvas extends Canvas {
     Dimension d;
     public void paint (Graphics g){
           rectangle();
     public void rectangle() {
          Graphics g = getGraphics();
          Dimension d = getSize();
          int width = d.width;
          int height = d.height;
          g.setColor(Color.red);
          g.fillRect(2,2,width-4,height-4);
          int y = 2;          // width
          for (int row=0; row<2; row++){                         
               int x = 2;     // height               
               for (int col=0; col<2; col++){     
                    g.setColor(Color.white);
                    g.fillRect(x,y, width/5, height/5);                              
                    x = (x + width-(width/5+4));               
               y = y+height-(height/5+4);                                        
     } // end method rectangle
     public void solution() {
               Graphics g = getGraphics();
               int width = d.width;
               int height = d.height;
               g.setColor(Color.red);
               g.fillRect(2,2,width-4,height-4);
               int y = 2;          // width
               for (int row=0; row<2; row++){                         
                    int x = 2;     // height               
                    for (int col=0; col<2; col++){     
                         g.setColor(Color.white);
                         g.fillRect(x,y, width/8*3, height/3);                              
                         x = (x + (width/8*5)+4);               
                    y = y+(height/3*2+4);                                        
               g.setColor(Color.black);
               g.drawString("Solution" , width/5,height/3);
               g.drawString("========"      , width/5,height/3+20);
               g.drawString("- find the length diagonal (from corner to corner)" , width/5,(height/3)+40);
               g.drawString("- divide diagonal by 2 to find the mid point" , width/5,(height/3)+60);
               g.drawString("- find a quarter of the area of the flag " , width/5,(height/3)+80);
               g.drawString("- So, the white are is: [(3m/8*2)*(2m/3)]*4 = 6 (half of flag area)", width/5,(height/3)+100);
     }// end method solution
} // end class MyCanvas
class PlayButton extends Button {
     PlayButton(StGeorgeFlag sgf) {
          super("Play/Reset");
          addActionListener(sgf);
} // end Class PlayButton
class ConfirmButton extends Button {     
     ConfirmButton(StGeorgeFlag sgf) { 
          super("Confirm");
          addActionListener(sgf);
} // end class ResetButton
class SolutionButton extends Button {
     SolutionButton(StGeorgeFlag sgf) { 
          super("Solution");
          addActionListener(sgf);
} // end class SolutionButton

NewJava wrote:
No error Not sure that I agree with this. I get an NPE when I try to run this.
but nothing come out. Please help!You're declaring your MyCanvas object twice, once in the class, and once in the init method, and only construct the second of the two. Declare this object only once -- in the class, and construct this same object once, and you're program will be closer to completion:
Change this:
    MyCanvas mycanvas;
    public void init()
        int width = getSize().width;
        int height = getSize().height;
        p = new Panel();
        setBackground(Color.lightGray);
        MyCanvas mycanvas = new MyCanvas(); // create the canvas to this:
    MyCanvas mycanvas;
    public void init()
        int width = getSize().width;
        int height = getSize().height;
        p = new Panel();
        setBackground(Color.lightGray);
        //MyCanvas mycanvas = new MyCanvas(); // create the canvas
        mycanvas = new MyCanvas(); // create the canvas

Similar Messages

  • I have an iPod 80gb which charges and looks to play tunes though nothing comes out of head phones docking stations etc. Can you point me in the right direction please?

    I have an 80GB iPod which charges and looks to play tunes though nothing comes out of ear phones,speakers or docking stations. Can you please help me fix this?

    Hello lowe-m1,
    Thanks for using Apple Support Communities.
    For more information, take a look at:
    iPod troubleshooting basics and service FAQ
    http://support.apple.com/kb/ts1382?viewlocale=nl_nl
    The headphones don't work
    If your iPod's headphones don't work or have static or garbled audio, try connecting them to any other 3.5 mm stereo headphone jack, like the one on your computer. If the issue with the headphones persists, replace them. For an iPod under warranty, you can order a replacement online. Otherwise, check out the cool headphones at theApple Online Store. If the issue appears to be with the iPod, try resetting it. If that doesn't work, then restore iPod with the latest iPod software using iTunes 7 or later.
    Have a nice day,
    Mario

  • My iPod touch is having a little issue with the volume. When I plug in my headphones the volume works fine. When there aren't any headphones plugged in, no sound comes out from my iPod. When I go to turn up the volume, it still says headphones. Any tips?

    My iPod touch is having a little issue with the volume. When I plug in my headphones the volume works fine. When there aren't any headphones plugged in, no sound comes out from my iPod. When I go to turn up the volume, it still says headphones. I tried restarting it a few times, nothing worked. I looked up many tutorials, and still nothing did the trick. Any tips?

    - Try cleaning out/blowing out the headphone jack. Try inserting/removing the plug a dozen times or so.
    Try the following to rule out a software problem
    - Reset the iPod. Nothing will be lost
    Reset iPod touch: Hold down the On/Off button and the Home button at the same time for at
    least ten seconds, until the Apple logo appears.
    - Reset all settings
    Go to Settings > General > Reset and tap Reset All Settings.
    All your preferences and settings are reset. Information (such as contacts and calendars) and media (such as songs and videos) aren’t affected.
    - Restore from backup
    - Restore to factory settings/new iPod.
    - Make an appointment at the Genius Bar of an Apple store. Seems you have a bad headphone jack.
    Apple Retail Store - Genius Bar
    Apple will exchange your iPod for a refurbished one for this price. They do not fix yours.
    Apple - iPod Repair price                  
    A third-party place like the following will replace the jack for less. Google for more.
    iPhone Repair, Service & Parts: iPod Touch, iPad, MacBook Pro Screens
    Replace the jack yourself
    iPod Touch Repair – iFixit

  • Cannot open photoshop, illustrator, indesign. when I try to open them, nothing come out, the adobe application manager will automatically pop out.

    cannot open photoshop, illustrator, indesign. when I try to open them, nothing come out, the adobe application manager will automatically pop out. 

    go to the installation directory (not a shortcut) and confirm they're installed and try to start from the install directory.

  • With 20DB boost, mic input comes out from speaker - SB X-Fi XtremeMusic

    If? +20DB boost is turned on, michrophone input or my voice comes out from the speakers even "Listen to this device" is unchecked on the Sound setting. If I start playing music by WMP under this condition and raise tthe speaker volume above certain level the system starts oscillation or noise dominates the speaker output. I wonder if I am not using the +20DB boost correctly. I have just gotten this sound card and am not yet familliar with [email protected]

    Hi Catherina,
    I do not have a Logitech webcam and have never owned one. The problem with REAR channels being reversed was resolved after uninstallation of the X-Fi and subsequent reinstallation. I use the CD that came with the card and install the normal package plus the Volume Panel. After that, I install the latest drivers from the Creative website. (not the BETA drivers)
    Oddly, when I uninstalled it the first time and then reinstalled it using the CD (before installing the latest web release), the REAR channel was mapped correctly to the REAR speakers only even with the digital connection in place. The problem came back after I installed the web release.
    However, the problem of the REAR channel being heard from FRONT speakers still persists even after I have uninstalled the X-Fi and reinstalled it from scratch multiple times. (with or without installing the web release)
    SmithyJMessage Edited by smithyj on 07-5-2006 09:48 AMMessage Edited by smithyj on 07-7-2006 02:59 AM

  • When Lion officially comes out from the Mac App Store, I understand that I can just buy it from there. However, will the laptops have Lion automatically? Or does it come with Snow leopard still.

    When Lion officially comes out from the Mac App Store, I understand that I can just buy it from there. However, will the laptops have Lion automatically? Or does it come with Snow leopard still.

    The ones sold that day will come with Snow Leopard most likely but they will be able to get a free upgrade to LIon if they apply within 30 days. Hardware coming through the supply chain from the day of the announcement will have Lion installed so it depends what stock people have to move before buyers see those.

  • Sound effects can't come out from SoundSticks after upgrade to 10.4.4

    After upgrading to 10.4.4, the sound effects of OS X, such as emptying trash, iChat effects, etc, doesn't come out from the SoundSticks (first generation, connected via USB), even though I've turned it (effects) to the highest level, and selected to have it come out of the SoundSticks.
    The effects are fine if I select Built-in Audio as sound output.

    After upgrading to 10.4.4, the sound effects of OS X, such as emptying trash, iChat effects, etc, doesn't come out from the SoundSticks (first generation, connected via USB), even though I've turned it (effects) to the highest level, and selected to have it come out of the SoundSticks.
    The effects are fine if I select Built-in Audio as sound output.

  • Getting 34208 Events in IIS server after come out from Maintenance mode

    Hi Experts,
    We are monitoring .Net application(APM) in our environment(SCOM 2012 SP1).  We are putting all the servers in Maintenance mode on every sunday(Weekly Maintenance), after come out from MMode  getting 34208 events in OPSMGR Logs, particularly from
    IIS servers(APM). 
    Do we have any fix for that like cumulative update?
    Can we put IIS server into Maintenance mode? If we put in MMode, Will it affect monitoring??
    Expecting your reply.. Thanks in advance!!!
    Regards
    Karthick

    Thanks for reply Agrawal!
    I know that we won't get alerts if the servers are in Maintenance mode.  But we are getting 34208 events particularly from IIS servers(.Net Application Performance Monitoring - APM) as the result we are receiving warning alerts in SCOM console stating
    that " Restart IIS service" which will affect other monitoring in the servers.
    Is anyone getting this issue in your environment?  Generally we will get 34208 events while we adding new application in to IIS server.  But here we are getting this events after the server come out from MMode.
    Kindly provide your valuable suggestions.  Thanks!
    Regards
    Karthick

  • After the OS 6 update my speaker does not work. My music plays but no sound comes out. Can someone help me with this issue? I currently have the 4S.

    After the OS 6 update my speaker does not work. Volume control on the side does not adjust the volume either. My music plays but no sound comes out. Can someone help me with this issue? I've tried rebooting my phone but still no sound comes out. I currently have the 4S.

    try to activate and desactivate the airplne switch a couple of time

  • Some time no sound comes out from laptop

    some time no sound comes out from laptop and after restarting ,the lapi sound come back......

    Hi,
    Try the following.
    Right click the speaker icon in the Taskbar and select Playback Devices.  Right click 'Speakers and Headphones' ( or Speakers/HP ) and select Properties.  Select the Advanced tab and then remove the tick from the box next to 'Allow applications to take exclusive control of this device'.  Click Apply and Ok to save this change.
    Restart the notebook.
    Regards,
    DP-K
    ****Click the White thumb to say thanks****
    ****Please mark Accept As Solution if it solves your problem****
    ****I don't work for HP****
    Microsoft MVP - Windows Experience

  • [solved] ctxfi -- Sound comes out from one speaker, sometimes...

    Hi
    I have a Creative X-Fi.
    I installed kernel26 from the testing repository in order that I could use the card with Arch Linux, and therefore alsamixer detects my card.
    I am able to play a sound file, however: sound only comes out from my front-right speaker. I have surround sound, and at the very least music should play from my front-left speaker, too.
    I opened Amarok earlier on and inside the preferences where you can pick the audio device, there are lots of different devices, and when selecting some of them I was able to get the sound to come out from either the back two speakers, the front-right speaker, or the front-center speaker. As of yet, I've not been able to get the front-left speaker to work, and I am not sure how to get this all to work outside of fiddling about on a amarok preferences page.
    Does anybody have any tips?
    Last edited by Bedtimes (2009-09-28 11:03:54)

    Have u ran alsamixer? That isnt for card detection alsamixer is to adjust sound levels.. alsaconf is whats used for detection. If you havent gone in there do it or if you have a graphical setup download the alsamixer gui version. Another thing is considering your sound card it might be installing as hda not legacy.. run dmesg and look for any troubles with in there involving sound card.. usually its a codec issue and you need to use the correct module in the alsa module conf file.. alsa comes with  a text file containing all sound card model types with their respective codecs.

  • Why my new iPad App Store nothing come out on featured and charts ?

    Why my iPad App Store nothing come out on featured and charts?

    Saw this on another post.
    Applecare Senior Advisor Txx Bxxx (I have his contact info in an email he just sent) just confirmed with me that the problem people are having with the App Store not loading is an apple issue with there servers, ITS NOT YOUR IPAD so don't go restoring it!   It's not happening to everyone however but they are looking into it, its really hit or miss.
    In the meantime ...........
    The Complete Guide to Using the iTunes Store
    http://www.ilounge.com/index.php/articles/comments/the-complete-guide-to-using-t he-itunes-store/
    Can't connect to the iTunes Store
    http://support.apple.com/kb/TS1368
    iTunes: Advanced iTunes Store troubleshooting
    http://support.apple.com/kb/TS3297
    Best Fixes for ‘Cannot Connect to iTunes Store’ Errors
    http://ipadinsight.com/ipad-tips-tricks/best-fixes-for-cannot-connect-to-itunes- store-errors/
    Try this first - Reset the iPad by holding down on the sleep and home buttons at the same time for about 10-15 seconds until the Apple Logo appears - ignore the red slider - let go of the buttons.
    This works for some users. Not sure why.
    Go to Settings>General>Date and Time> Set Automatically>Off. Set the date ahead by about a year.Then see if you can connect to the store.
     Cheers, Tom

  • Some burning smell comes out from laptop

    hi , i have purchased new hp pavilion 15 p210tx notebook in INDIA
    after 15 day of use, there's weired burning like smell comes out from my laptop when i oped it every time.
    it comes on battery power and also while charging.
    another problem i noticed that continuous crackling sound comes from right speaker of laptop everytime. 
    all the things looks working nicely, but don't know where this smell comes from...either from speaker or something else?

    Hello ashish15188, 
    Well it might be a hardware issue, and I would strongly recommend to get in touch with HP support, if you bought it recently (less than 1 year), even if you feel safe enough to go deeper and open your laptop to check the hardware. 
    Sorry for not providing any troubleshooting, but it really seems to be something that you can't resolve via software or something
    Cheers, 
    BasicallyIDoWrk
    Cheers,
    BasicallyIDoWrk

  • I have an iPhone 5 16gb white color and i did not get any of the services from apple pls help[ me out

    I have one iphone 5 16 gb white colour with me and its in still under warranty and my phone was fallen down by chance and it got turned off totally and not even switched on also then i went to apple authorised service center for regarding the same . then service center people said that sir you need to submit your phone , after that i left my phone to service center and after two days i have got one call from service center that sir your phone is under phisical damaged condition so u will not be abel to get warranty from apple this will cover under paid replacement and you need to talk to apple customer care also regarding this .same .
    Then i called up to apple customer care and they said sir  we have got some images from the service center regarding your phone and we found that your logic board is damaged from inside and you would not be abel to get the paid replacement also you need to buy a new phone on stock price i was shocked on that time why would i pay 40 to 50 thouasnd again on iphone if its not that much stronger to take bit of imapcts like this
    I had talked numbers of time to service center also but they all are denied against the complainst
    if any body is there how can help me out regarding this so pls register my complaint and help me out from this highly dissatisfied service from apple .
    Thnaks
    karan

    Warranties do not cover damage

  • No sound come out from my i pod!!

    after i convert 1 of my music videos.. i tranfser it into my ipod.. when i play it ..... it come out without sounds but my others songs got!!! pls help me guys!!!

    The problem with the video sound going out started with the last Ipod update. The videos played fine until then. I called the Technical Help Line and they said they are aware of this problem from the update, but there is nothing they can do. They suggested that if maybe more people posted the problem on the discussion boards that maybe Apple would do something. I don't understand how the Technical Help Line can't let them know they need to fix this problem. They need to do another update correcting the problem and so far nothing has been done.
    Apple, please do another update to correct the problem with the video sound or at least let us know that you are aware of and are currently working on the problem. Please do not continue to ignore the issue.

Maybe you are looking for

  • IPhone 3GS will not fully sync with iTunes 9.2

    Just installed iTunes 9.2 (twice) and I cannot complete a sync of my iPhone 3GS. It seemingly stalls at Contacts or Calendar (varies on each attempt). Prior to this, my syncs would be speedy fast (less than 5 minutes. Any ideas of what I can do to fi

  • VAT in Purchase Pricing Procedure

    Hi All, How can i use MWST condition type in my pricing. Like scenario is as below. CIF- 100.00 Duty- 50.00 Vat (110*x CIF+ Duty) * 15% - 24.75 here i need to maintain this VAT, but i cannot with tax code through TAX Procedure because freight, insura

  • Device package error for switch Cat2960

    Hi,, We are installing device package for switch Cat2960. But we get below error message when trying to install the same. WARNING :  Cat2960(6.1):Consistency check failed for base package SharedDcmaIOS When trying to updgrade the SharedDcmaIOS to hig

  • Transaction programming - Making screen fields 'output only'

    Hi all, I have a problem concerning a screen - it is so that the screen is used by several transactions - Create 'plan', Display 'plan' and Change 'plan'. When it's called from the 'Display' transaction I want the screen to be output-only. So I wrote

  • Dynamic Alert Configuration

    Hi Experts, I need to configure alerts dnamically for all types of errors, must to intimated to the registered users via email. Please suggest how this could be done. Regards, Sushama