What's wrong with my buttons, any one can figure out?

I am creating a SleeperFace with Applet, there was a problem that my buttons does not appear normally, just when I point the mouse on, then the two buttons will be appeared.
Here are my codes:
import java.awt.*;
import java.applet.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
public class SleepyFace extends Applet implements ActionListener
int x=0;
public void init()
JButton bAwake=new JButton("Awake");
bAwake.addActionListener(this);
JButton bAsleep=new JButton("Asleep");
bAsleep.addActionListener(this);
add(bAwake);
add(bAsleep);
public void actionPerformed(ActionEvent e)
if(e.getActionCommand()=="Awake")
x=1;
repaint();
else if (e.getActionCommand()=="Asleep")
x=0;
repaint();
public void paint(Graphics g)
setBackground(Color.blue);
g.setColor(Color.yellow);
g.fillOval(50,60,400,400);
g.setColor(Color.black);
if (x==1)
g.fillOval(130,160,50,100);
g.fillOval(312,160,50,100);
g.fillOval(222,250,50,50);
g.fillArc(150,270,200,120,-360,-180);
g.setColor(Color.white);
g.setFont(new Font("SansSerif", Font.BOLD, 24));
g.drawString("Let's make some noise!", 120,520);
else
g.fillRect(100,240,100,4);
g.fillRect(300,240,100,4);
g.fillOval(222,250,50,50);
g.fillRect(150,350,200,4);
g.setColor(Color.white);
g.setFont(new Font("SansSerif", Font.BOLD, 24));
g.drawString("I'm sleeping, please do not disturb!", 50,520);
}

FlowLayout is generally not a good top ContainerLayout.
I am not debating that. I agree BorderLayout is a
better top level LayoutManager (which is why I made
the earlier assumption that Applets also use a
BorderLayout).
I realize that you aren't - in fact, I did not take you to be debatinganything. I added that piece of information merely to explain why I changed the Layout Manager - in order to add the JButtons where I wanted them to be - which is admittedly not where the OP might want them.
I am questioning how using a BorderLayout causes the
children to be painted, even though the paint()
method does not invoke super.paint().
I have not intentionally avoided calling super.paint. As I said, I do not know the real reason. But this has worked before, and I believe it has to do with adding the two JButton Components to another Panel; because if you simply add them BorderLayout.NORTH and BorderLayout.SOUTH it won't help.
See point 5 from the following link.
http://java.sun.com/products/jfc/tsc/articles/painting
/index.html#awt_summary
I see it

Similar Messages

  • I bought 120 gold in Haypi dragon on Mar 12 and 15 2012 , but I havenot received them yet.What is wrong with it ,and when i can reveive them ?

    I bought 120 gold in Haypi dragon on Mar 12 and 15 2012 , but I havenot received them yet.What is wrong with it ,and when i can reveive them ?

    For in-app purchases you should contact the developer's customer support, assuming there is one.

  • My iphone 4 keeps flashing black every 5-10 seconds, what is wrong with my iphone ? how can i fix it? helppppp

    my iPhone 4 screen keeps Flashing black and whenever I try to tap an app it will flash 3 times.
    this has been happening since last night .
    whats wrong with my phone?
    how can i fix it?

    Hey there Antoinetter101,
    It sounds like you cannot use any apps on your device without the screen flashing at you, making the phone unusable. I would start by quitting all the apps on the phone:
    iOS: Force an app to close
    http://support.apple.com/kb/ht5137
    Double-click the Home button.
    Swipe left or right until you have located the app you wish to close.
    Swipe the app up to close it.
    When you have done that and restart the phone and test the issue again:
    iOS: Turning off and on (restarting) and resetting
    http://support.apple.com/kb/ht1430
    Thank you for using Apple Support Communities.
    All the best,
    Sterling

  • What's wrong with my Button?

    Hello everyone,
    I been trying to get my Button working, but I don't understand what's wrong. I've tried a bunch of stuff, each with failure. Can any of you guys help me out here? I know that it's a little bit of a mess, but for some reason, it gives me a NullPointerException when I execute it. If I comment out 4 lines of code, about the getContentPane, it works without making a button. Problem is, I want to keep the Button in there. What should I do?
    Thanks
    frame.getContentPane().setLayout(new FlowLayout());
    frame.getContentPane().add(startButton);
    if (frame.getContentPane() instanceof JComponent)
         ((JComponent)frame.getContentPane()).setOpaque(false);
    }

    here is your original code, stripped of all the non-button parts
    you will see that it does not generate a NPE
    you may also note it is easy to read (code tags used)
    suggestion - start again
    start with a small section of code, ***compile/run/test/fix/compile/run/test
    when all OK, add another section of code (repeat ***)
    etc
    etc
    import java.awt.*;
    import javax.swing.*;
    class Graphic2
      public static void main(String[] args)
        new Graphic2().run();
      private JButton startButton;
      public void run()
        JFrame frame = new JFrame();
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);//added
        frame.setLocation(400,300);//added
        startButton = createButton("Start.gif");
        startButton.setLocation(460, 500);
        frame.getContentPane().setLayout(new FlowLayout());
        frame.getContentPane().add(startButton);
        frame.pack();//added
        frame.setVisible(true);//added
      public JButton createButton(String name)
        String imagePath = name;
        ImageIcon iconRollover = new ImageIcon(imagePath);
        int w = iconRollover.getIconWidth();
        int h = iconRollover.getIconHeight();
        Cursor cursor = Cursor.getPredefinedCursor(Cursor.HAND_CURSOR);
        // create the button
        JButton button = new JButton("btn");//added "btn"
        //button.addActionListener(this);
        button.setIgnoreRepaint(true);
        button.setFocusable(false);
        button.setBorder(null);
        button.setContentAreaFilled(false);
        button.setCursor(cursor);
        button.setIcon(iconRollover);
        button.setRolloverIcon(iconRollover);
        button.setPressedIcon(iconRollover);
        return button;
    }

  • What's wrong with this button code

    Dear All,
    I am trying to set up a button handler for many buttons
    rather just one. The
    intention of this code is to say if I press Load1 to Load40
    that button and
    only that button's alpha should change to 50%. This code
    makes them all 50%
    alpha when the frame loads rather than on the onPress event.
    Can someone please help me out with this one?
    i = 0;
    while (i<40) {
    this["Load"+i].onPress = btnEvaluate(this["Load"+i]);
    ++i;
    function btnEvaluate(target_btn:Button) {
    target_btn._alpha = 50;
    Thanks again.
    Alastair MacFarlane

    kglad,
    Thanks again. What would this group do without your help.
    Alastair
    "kglad" <[email protected]> wrote in message
    news:gh0sq0$cbv$[email protected]..
    > :
    >
    >
    >
    > for (var i = 0;i<40;i++) {
    > this["Load"+i].onPress =function(){
    > this._alpha=50;
    > }
    > }

  • Can't gotoAndStop ...what's wrong with this button code?

    Hi,
    I'm totally stumped as to why I can't navigate to another frame.
    I have put 2 days into this simple problem now and I'm ready to give up and go back to AS2.
    Please help!
    I'm using CS4; publish settings AS3, 10.0
    I have a button on frame 2 that should take me to frame 3 when clicked.
    (So far I've tried a hundred different ways but I don't get to frame 3...)
    Different things I tried...
    > Creating the button dynamically from the library...
    > Inserting it statically from the library on frame 2...
    > referencing the mainTimeline through a variable...
    > wrapping the gotoAndStop action in another function...(if placed directly on the timeLine the movie correctly goes straight to frame 3)
    > naming frame 3...
    > using 'nextFrame' instead of 'gotoAndStop'...
    etc..
    In most cases I don't get an error in the output panel and no compiler error either; it just doesn't work!!!
    (Just stays on the same frame after I click the button)
    Here's the code I think should work; but doesn't:
    function moveTo3 (event:MouseEvent):void {
        trace("button_clicked"); // always traces correctly; but movie does not go to frame 3 !!!
        gotoAndStop(3);
    f_btn.addEventListener(MouseEvent.CLICK, moveTo3);
    WHAT AM I MISSING HERE?
    Thanks in advance ...

    Hi Ned,
    I have to run out and don't have the time to deal with it right now but you're RIGHT.
    I do have an 'onEnterFrame' listener on frame 1 !
    It's doing some animation with a symbol and I don't think I removed the listener itself.
    I just set the object to null when it reached [alpha:0].
    THANKS!
    I'll check it out as soon as I can but I really think you got me looking in the right direction now.
    Thanks again,
    Connor
    (I'll post an update when I get back to it)

  • TS2756 I don't know what's wrong with my iphone but I can't join hotspot.. Any idea??

    Please help me :(

    You can try resetting your iPhone by simultaneously pressing and holding the Home and Sleep/Wake buttons until you see the Apple Logo. This can take up to 15 seconds so be patient and don't release the buttons until the logo appears.
    Try again to see if the problem persists.
    If still a problem, try deleting the hotspot (select the ⓘ, then tap Forget this Network) and adding it again.

  • I cannot load my MSN home page on FF4. What is wrong with you people. I can't get any feedback. It's time to move to Chrome

    My [http://my.msn.com/ MSN] home page has unresponsive links and the traffic report map will not load. It works on Safari and Chrome. I have asked this question here and on live chat with no resolution.

    How much memory on your MBP?
    Also, are you using external drives for your media? You could get a huge traffic jam if you have your OSX, your apps, and your video Events all on the same drive.

  • I don't know what's wrong with my Mac but I can't watch Youtube videos. I can watch on other device though. Can someone tell me why the videos are not working? Thank You ^_^

    The Youtube videos is loading slowly on my mac but it loads normally on other device. It always buzzing every single second.

    One of the following steps should help.
    1. Install Adobe Flash Player.
        http://get.adobe.com/flashplayer/
        Quit Safari.
        Restart computer. Relaunch Safari.
    2.  Enable Plug-ins
        Safari > Preferences > Security
        Web Content:  > "Enable Plug-ins".
           or
        Internet Plug-ins >  "Allow all other plug-ins
    3. Check  whether you are currently  in  YouTube HTML 5 trial.
         http://www.youtube.com/html5
        At the bottom  left of the page  uncheck the box for
       "You are currently in the HTML5 trial".
    4. Reset Safari.
        Click Safari in the menu bar.
        From the drop down select "Reset Safari".
        Uncheck the boxes next to all items.
        Check the box next to "Remove all website data".
        Click "Reset".
    5. Turn off Extensions if any.
        Safari > Preferences > Extensions
    Best.

  • Recently my ipod touch (old version ) was not working correctly, so i deleted everything from it---expecting to start fresh, however when i start  it up it continues to stay on the apple screen, what is wrong with my ipod and how can i fix it ?

    my  ipod doesn't allow me to do the thiings it used to. It would change the time and date and everytime i'd turn it to the correct date it would go back when i clicked a new app. it wouldn't load apps corectly because of this date and time problem. So i decided to erase everything and start fresh. But now it won't even load properly it just stays on the apple screen with the loading spin thing stuck. someone please guide me into fixing this problem

    Try:
    - iOS: Not responding or does not turn on
    - If not successful and you can't fully turn the iPod fully off, let the battery fully drain. After charging for an least an hour try the above again.
    - If still not successful that indicates a hardware problem and an appointment at the Genius Bar of an Apple store is in order.

  • TS1372 I have an ipod classic 160gb have already tried all the steps with no success. I have just bought this ipod and have had it for less than a week before this happened. what is wrong with my ipod and how can i fix it?

    brand new ipod classic 160gb will not restore. have tried all steps with no fix. Also tried steps on a different computer with same results. anu help?

    if you own a mac try to re format the disc to journal.
    If you are on a windows like me, try to reformat the disc to NTFS. Then it will display that you need to restore as the ipod is in recovery mode. It restored with success. and voila, brand new working ipod.

  • Any one reliably figure out Podcast syncing ?

    Hello,
    My favourite promised feature for iTunes 11 was iCloud Podcast syncing. I'd have a list of subscriptions in iTunes on my Mac, I'd sync my iPhone once so it knew what my subscriptions were, and from then on my Mac and iPhone would be in sync. That means if a new episode is download on my Mac, it also downloads on my iPhone. If an episode is deleted on my Mac or iPhone, it is deleted everywhere, and very importantly the position is also synced.
    I've now tried several times and several methods to get it to work, and the best I've gotten it to work a mishmash.
    Here is what is in the unplayed section on my Mac :
    DecodeDC - 1 podcast 90% of the way through
    Infinite Longbox - 1 unplayed podcast
    Make Talk - 1 unplayed podcast
    New Distruptor - 1 podcast 65% of the way through
    Nintendo Voice Chat - 60% of the way through
    StarTalk Radio Show - 4 unplayed episodes. 2 90% played. Total of 6
    Under the Influence CBC - 1 episode 98% finished
    8-4 Play - 1 unplayed episode
    Here is what is on my iPhone (This is the closest I've gotten it - it asked if I wanted to sync with other devices). I've tried both the Music app and the Podcast app :
    DecodeDC - 2 unplayed podcast. :: Incorrect count. Incorrect played position.
    Infinite Longbox - not present :: Incorrect
    Make Talk - 1 unplayed podcast :: Correct
    New Distruptor - 1 unplayed podcast :: Incorrect position
    Nintendo Voice Chat - 1 unplayed podcast :: Incorrect played position.
    StarTalk Radio Show - 7 podcasts :: Incorrect count. Correct position !
    Under the Influence CBC - 1 unplayed podcast :: Incorrect position
    No 8-4 - not on list :: Incorrect
    I'm not testing by jumping between my mac and iphone either, I give it a bit of time. I even try to quit iTunes to give it push.
    Any hints or tips ? This would be a tremendous feature if it actually worked.

    FlowLayout is generally not a good top ContainerLayout.
    I am not debating that. I agree BorderLayout is a
    better top level LayoutManager (which is why I made
    the earlier assumption that Applets also use a
    BorderLayout).
    I realize that you aren't - in fact, I did not take you to be debatinganything. I added that piece of information merely to explain why I changed the Layout Manager - in order to add the JButtons where I wanted them to be - which is admittedly not where the OP might want them.
    I am questioning how using a BorderLayout causes the
    children to be painted, even though the paint()
    method does not invoke super.paint().
    I have not intentionally avoided calling super.paint. As I said, I do not know the real reason. But this has worked before, and I believe it has to do with adding the two JButton Components to another Panel; because if you simply add them BorderLayout.NORTH and BorderLayout.SOUTH it won't help.
    See point 5 from the following link.
    http://java.sun.com/products/jfc/tsc/articles/painting
    /index.html#awt_summary
    I see it

  • What's wrong with the server?

    execute me ~what's wrong with the server? I can‘t use the command nohup any longer.Can somebody help me?
    root@shhis1new # nohup
    Segmentation Fault (core dumped)
    root@shhis1new # nohup ls
    Segmentation Fault (core dumped)
    root@shhis1new # nohup /opt/SUNWexplo/bin/explorer -w all &
    [1] 6871
    root@shhis1new #
    [1]+ Segmentation Fault (core dumped) nohup /opt/SUNWexplo/bin/explorer -w all
    root@shhis1new # uname -a
    SunOS shhis1new 5.9 Generic_122300-19 sun4u sparc SUNW,Netra-T12
    System Configuration: Sun Microsystems sun4u Sun Fire E2900
    System clock frequency: 150 MHZ
    Memory size: 49152 Megabytes
    Best Regards
    <email address removed by moderator>
    Edited by: 884082 on 2011-11-22 下午10:00

    Moderator Action:
    You email address has been removed from your post.
    You wouldn't want bad people to send you spam messages for the rest of your life, eh?
    Moderator Advice:
    If this is the same E2900 that you have mentioned in every one of your other forum posts, then it would seem you need to contact Technical Support and open a proper support request. These forums are NOT techsupport and that system seems so poorly configured that it needs deep analysis. Such investigation cannot be done by using an online forum.
    The immediate solution is to log on to the SC of that box and power it down, then boot it back up. At least it will be running after that.

  • HT201559 What is wrong with my ipod?

    Can anyone help me identify what is wrong with my iPod? One day I tried to unlock it, and nothing happened. The screen is semi frozen, i can still use the screen home button (my original home button is broken) but i cant unlock it or turn it off. Basically i cant do anything that requires sliding my finger across the screen. I receive notifications still, the time changes, and I get alerted right as i plug the charger in. As im writing this I have it updating the software. Im sorry I dont remember exactly what iOS it was, i know it was 8. something. And this is an iPod 5 gen.

    Try:                                               
    - iOS: Not responding or does not turn on           
    - Also try DFU mode after try recovery mode
    How to put iPod touch / iPhone into DFU mode « Karthik's scribblings
    - If not successful and you can't fully turn the iOS device fully off, let the battery fully drain. After charging for an least an hour try the above again.
    - Try another cable                                                       
    - Try on another computer                                                       
    - If still not successful that usually indicates a hardware problem and an appointment at the Genius Bar of an Apple store is in order.
    Apple Retail Store - Genius Bar                                     

  • TS1702 What is wrong with Pages after the update?

    What is going on with Pages after the update?

    Hey George.iD, you wrote on 6 Feb 2014, this:
    Re: What is wrong with Pages after the update?in response to TRSPAGES
    What's wrong with it?
    As one thing after more-than a month later on 22 March, Pages _refuses_ to alter the color of text.  How maddening this is:  I select text, I select a crayon, but the text _remains_ black.  < Pages is Incorrigible! :-( >
    [After I vented steam, I feel better  --  until later.  What a cycle!  :-) ]

Maybe you are looking for

  • Organizer Drag and Drop Issue

    In PSE4 I am in Folder Location view working in Folder A. I drag and drop a few files to Folder B. Unfortunately now PSE puts me in Folder B. "I" didn't want to go to Folder B, I just wanted to put some files there. Other programs don't change the fo

  • Strange sound on retina macbook pro

    This has happend twice now. It first happend a few weeks ago and then tonight. I got into the desktop and went to open a browser and there was the strange sound that almost sounded like an quiz show buzzer when you get the answer wrong. It is a deep

  • Bug or feature: BorderPane ignores reflection in sizing

    Just started to explore fx (read: complete newbie here :-), so grabbing code examples and came across one by Walter (below is a minimal extract of the fx app): http://weblogs.java.net/blog/ixmal/archive/2011/06/02/using-javafx-20-inside-swing-applica

  • Looking for a suggestion on the best wifi extender for the MacBook Pro

    What good extenders are there to reach signals that are further away from the laptop.  Looking for something to use on my boat while at anchor and/or in marinas.

  • Better to setup new system from Time Machine or old HD?

    My MacBook Pro went down, but the HD is okay. I've purchased a new MacBook Pro and prior to pulling it out of the box, I'm trying to understand the best way to get everything back that I can on the new system. Physically putting the HD in the new sys