Getting something on a canvas

Hi,
I'm still battling with this canvas. This code puts the text: "test from the canvas" on the screen on a grey background, OK, but I can't get it to do anything when I push a button. I know the button works. Any help? (ps this is not an applet)
          myCanvas aCanvas = new myCanvas();
          // container      
          Container cp = getContentPane();
          cp.setLayout( new BorderLayout() );
          cp.add( outputScreen, BorderLayout.NORTH );
          cp.add( optionsBox, BorderLayout.CENTER );
          cp.add( lower, BorderLayout.SOUTH );
          lower.add( message );
          lower.add( baseButtons );
          outputScreen.add( aCanvas, BorderLayout.CENTER );
          pack();
          setSize (350, 580);
          setResizable( false );
          setVisible( true );
          outputScreen.repaint();
     }// ends class constructor
        public class myCanvas extends Canvas
          public Graphics g;
          public myCanvas()
          super();
          //setBackground(Color.yellow);
          setForeground(Color.blue);
          public void paint(Graphics g)
               super.paint(g);
               g.setColor(Color.yellow);
               g.drawString( "test from the canvas", 10, 10 ) ;
          }// end method paint()     
     } // end myCanvas;
   /** The class representing the button event
   * listeners
   class ButtonListener implements               ActionListener ////////////////////////////////////
        public Color c;
      /** Class constructor
        * @param c the color for this button
      public ButtonListener( Color c )
         this.c = c;
      /** Respond to the action events
        * @param e The click event
      public void actionPerformed( ActionEvent e )
           myCanvas theCanvas = new myCanvas();
          theCanvas.setBackground( Color.white );
          theCanvas.setForeground( Color.white );
   }// end class ButtonListener()
 

Try this:
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class CanTest extends JFrame implements ActionListener
     myCanvas aCanvas = new myCanvas();
     JButton  jb1     = new JButton("Red");
     JButton  jb2     = new JButton("green");
public CanTest ()
     super();
     setBounds(6,6,550,400);     
     addWindowListener(new WindowAdapter()
    {     public void windowClosing(WindowEvent ev)
               dispose();     
               System.exit(0);
     JPanel sot = new JPanel();
     sot.add(jb1);
     jb1.setForeground(Color.red);
     jb1.addActionListener(this);
     sot.add(jb2);
     jb2.setForeground(Color.green);
     jb2.addActionListener(this);
     getContentPane().add("Center",aCanvas );
     getContentPane().add("South",sot);
     setVisible(true);
public void actionPerformed(ActionEvent a)
     Component co = (Component)a.getSource();
     aCanvas.setForeground(co.getForeground());
     aCanvas.repaint();
public class myCanvas extends Canvas
public myCanvas()
     super();
     setForeground(Color.blue);
     setBackground(Color.pink);
public void paint(Graphics g)     
     super.paint(g);          
     g.setColor(getForeground());     
     g.drawString( "test from the canvas", 20, 20 ) ;     
public void update(Graphics g)     
     paint(g);
public static void main (String[] args)
     new CanTest ();  
}       Noah

Similar Messages

  • I just got iphone 5c and i am not happy with it. It uses to much data and i don't even know how. I can't get the ringtones i want for my contacts.I got it on my free upgrade but i want to take it back and get something else but where i got it they say i c

    I just got iphone 5c and i am not happy with it. It uses to much data and i don't even know how. I can't get the ringtones i want for my contacts.I got it on my free upgrade but i want to take it back and get something else but where i got it they say i can't because i don't have the earbuds and i have serches or them. now i am suck with a phone i don't like at all until my next upgrade. this is very dishearten

    1. If you are this unhappy with that phone, and the lost earbuds is the only thing stopping you from taking it back, why do not just buy some earbuds. That way you can get rid of that phone. It all depend upon how much you want to get rid of that phone.
    2. Yet if you are stuck with that iPhone, here is something might help you to control the data usage. By design, iPhones do turn off WiFi when they go dormant. So if a download is in progress and so forth when the phone goes dormant, it will switch to use cellular data, if this setting is left on. Therefore, from multi-sources I have learned that if you keep your iPhone connected to a power source, then it will stay connected to the available WiFi.

  • Help me Please.. I can log on to the Apple website to manage my account and all the information is correct, but I get "Your Apple ID has been disabled" when I try to get something from App Store on my iPad

    Help me Please.. I can log on to the Apple website to manage my account and all the information is correct, but I get “Your Apple ID has been disabled” when I try to get something from App Store on my iPad3
    I'm from poland.
    Thx
    Balbi

    Contact iTunes Customer Service and request assistance...
    Use this Link  >  Apple  Support  iTunes Store  Contact

  • I can log on to the Apple website to manage my account and all the information is correct, but I get "Your Apple ID has been disabled" when I try to get something from App Store on my iPhone.

    I can log on to the Apple website to manage my account and all the information is correct, but I get “Your Apple ID has been disabled” when I try to get something from App Store on my iPhone.

    You need to contact Apple Support, particularly iTunes Store support team.  Cheers!

  • IMovie has frozen up on me. I've tried rebooting and reinstalling the apps- no help. I can play some of the files- but I can't get into the libraries.Even when I can get something to play the whole system crashes after a few minutes. What can I do?

    I desperately need your help. I was working on iMovie last night when the thing froze up on me. I've tried rebooting. I've tried reinstalling the apps. No change. I can play some of the files- although I can't tell which ones will play until they magically appear. I can't get into the project library or the event library. The bar that lets me scroll through the clips is gone. Even when I can get something to play the whole system crashes after a couple of minutes and generates a "problem report" that says "iMovie Quit Unexpectedly". This all started when I was adding cutaways- and one clip just would not load. After I tried several times everything froze up. Have you ever heard of something like this? Maybe I pushed a button or somehow changed a setting? Maybe some of the video is corrupt? What do you recommend?
    Thanks for any advice you can offer!

    I have tried all the above and nothing seems to work. Any other suggestions?

  • HT204266 My new iPad, when I try to get something from the Apple Store it tells me that My account isnot vlaid for use inthe U.S.store.  And to switch to the Australian store before purchasing, how do I do this?

    My new iPad, when I try to get something from the Apple Store it tells me that My account i snot vlaid for use in the U.S.store.  And to switch to the Australian store before purchasing, how do I do this?  I am in Australia?

    There are instructions on this page for creating an account without a credit card : http://support.apple.com/kb/HT2534
    You can download a copy of the iPad manual from here : http://support.apple.com/manuals/ipad/

  • How can you get something back you've deleted from trash

    I was in the process of formatting my external drive so I could use it as the backup drive for my MacBook Pro.  It wanted to format it, so I took my files from the external drive and saved them to the desktop of my computer.  When it was done formatting, I transferred the files back to my drive and then deleted the files from my desktop and trash.  I went into the folders on my drive today and they are empty.  So I need to find out how to get something back from my trash can that's already been emptied!!

    You can't, without the use off a third-party file rescue app or third-party file rescue service. You can try this:
    http://www.prosofteng.com/

  • Getting something went wrong while trying to open workbook through code?

    hi,
    i am getting something went wrong while  trying to open workbook through code below is m code:
    ES.ExcelService client = new ES.ExcelService();
                    client.Credentials = System.Net.CredentialCache.DefaultCredentials;
                    ES.Status[] status;
                    string sessionId = client.OpenWorkbook("http://servername/Documents/exceles.xlsx", "en-us", "en-us", out status);
    i have also added modify  permission to wpg_wss group but i am still getting the same error.
    any help is appreciated.
    thanks,
    gaurav 

    Hi Gaurav,
    For your issue, you need to make sure the site where your workbook is stored in is a Trusted Location in Excel Service Application:
    http://technet.microsoft.com/en-in/library/ff191194(v=office.14).aspx
    For more information, you can have a look at the blog:
    http://blogs.msdn.com/b/cumgranosalis/archive/2006/03/24/excelserviceshelloworld.aspx
    Best Regards,
    Eric
    Eric Tao
    TechNet Community Support

  • TS1702 Hello! Can I get something like the story of the safari browser, if it was removed?

    Hello! Can I get something like the story of the safari browser, if it was removed?

    NEVER MIND!  I FOUND THE ANSWER! 

  • Why every time i try to get something from itunes store i can't?

    every time i try to get something from itunes store it ask for password and after i tipe it it sais its imposibile to connect to itunes store,but when i try it on pc it works.And now i can't get anything on my ipod.what should i do?

    Can't connect to the iTunes Store

  • TS3899 Whenever I send an email, the person who receives it gets something that says References: and a long list on nonsense to do with Gmail before the actual message appears.

    Whenever I send an email, the person who receives it gets something that says References: and a long list on nonsense to do with Gmail before the actual message appears.
    Here is an example....
    References: <[email protected]> <[email protected]> <[email protected]> <[email protected]> <[email protected]> <[email protected]> <[email protected]> <[email protected]> <[email protected]> <[email protected]> <[email protected]> <[email protected]> <[email protected]> <[email protected]> <[email protected]> <[email protected]> <[email protected]> <[email protected]> <[email protected]> <CAM-_T=[email protected]> <BLU0 ,[email protected]> <CAM-_T=CAUP+9GyYG-_ecOazo=[email protected]> <[email protected]> <[email protected]> <[email protected]> <[email protected]> <[email protected]> <[email protected]>
    > Mime-Version: 1.0 (1.0)
    > In-Reply-To: <[email protected]>
    > Content-Type: multipart/alternative;
    > boundary=Apple-Mail-85351E4C-6385-4256-BE9E-27C10517E136
    > Content-Transfer-Encoding: 7bit

    It seems pretty clear to me.
    When you turn off your primary account the only active account the phone can send via is your Gmail account, and that's what you're seeing.
    The question is why do you need to turn off the primary account.. which you answer:
    When that is set up as the primary server and turned on I get a message that says "the recipient was rejected by the server
    That's because your ISP (megalink) is using access controls to manage who sends mail through their mail server. The first thing they're probably doing is using IP address restrictions - essentially saying they'll only relay mail from any machine on their network (including dialup/DSL/etc. customers), but you're not on their network, you're on an AT&T (or Verizon) 3G connection which isn't in their IP address range, and therefore not valid as far as their mail server is concerned.
    The typical solution to this is authentication - by authenticating to their server (via username and password) you identify yourself as a customer and they should relay your messages. So check your phone to ensure that you have authentication enabled for your primary mail account.
    If that fails (e.g. they don't support authenticated SMTP) the next option would be to relay the message through your cell provider's mail server - as an AT&T wireless customer you should be able to relay through AT&T's mail server... likewise for Verizon (or whatever national carrier your iPhone is on). You'll need to check with your carrier's site for the specifics of the mail server address to use.

  • When I type for example "Apple Store" I am getting something completely different, like the MBP is anticipating, any ideas, When I type for example "Apple Store" I am getting something completely different, like the MBP is anticipating, any ideas

    When I type for example "Apple Store" I am getting something completely different, like the MBP is anticipating, any ideas, When I type for example "Apple Store" I am getting something completely different, like the MBP is anticipating, any ideas

    what do you expect from this code out.print(lecture); ?
    lecture is an Element, toString() is not implemented, so print correctly displays some fuzzy pointer information, nothing more...

  • Keep getting "Something went wrong and we can't sign you in right now. Please try again later."

    I try to download some items. I keep getting "Something went wrong and we can't sign you in right now. Please try again later."
    I was logged in to Live, but somehow it is getting lost.  I have tried both Chrome and IE.  Is there something wrong at MS or with my account?  Also, it took me 15 minutes to find anywhere to submit a problem or question...very frustrating. 
    It kept sending me to self help where none of the options were relevant. 
    The address where it pukes
    //login.live.com/login.srf?wa=wsignin1.0&wtrealm=social.msdn.microsoft.com&wreply=https%3a%2f%2fsocial.msdn.microsoft.com%2fForums%2fsqlserver%2fen-US%2fhome%3fstoAI%3d10&wp=MBI_FED_SSL&wlcxt=microsoft%24microsoft%24microsoft

    Hello Mike,
    I am sorry to hear you are getting an error message when attempting to download items. This forum is actually for Registration related inquiries for Windows Store and Phone developers. I would suggest reaching out to the Answers
    Forums for additional support, or submitting a request for technical
    assistance.
    Thank you,
    -Jonathan
    Windows and Windows Phone Dev Center Support
    Office Store Developer Support
    Send us your feedback about the Windows Platform

  • I have an phone 5 and i put a passcode lock on it. i left my phone in my room to get something to eat and i went back to check it and the passcode was different and it has locked me out of my phone, is their any way without restoring my phone i can fix th

    I have an phone 5 and i put a passcode lock on it. i left my phone in my room to get something to eat and i went back to check it and the passcode was different and it has locked me out of my phone, is their any way without restoring my phone i can fix this?

    ask the person who changed the passcode what they changed it to. no other way to fix it without restoring it.

  • TS4124 how long does it take to get something in waiting status to get uploaded

    how long does it take to get something in waiting status to get uploaded

    Hello mofins,
    Welcome to the Apple Support Communities. If you are having issues with the song not uploading and is still in the waiting status, click Store > Update iTunes Match. The following article is helpful for troubleshooting iTunes Match.
    iTunes Store: Troubleshooting iTunes Match
    http://support.apple.com/kb/ts4054
    Regards,
    -Norm G.

Maybe you are looking for