Results 1 to 2 of 2
  1. #1
    javanoobita is offline Member
    Join Date
    Feb 2009
    Posts
    6
    Rep Power
    0

    Default its not changing bgcolor

    hi new to java, i try making my own applet but it doesn't change color, no error though when compiling...



    import java.applet.*;
    import java.awt.*;
    import java.awt.event.*;

    public class ColorChange extends Applet implements ActionListener
    {
    Button a,b,c;
    Color bgcolor;
    public void init()
    {
    Button a = new Button("Blue");
    Button b = new Button("Red");
    Button c = new Button("Green");
    add(a);
    add(b);
    add(c);
    a.addActionListener(this);
    b.addActionListener(this);
    c.addActionListener(this);
    bgcolor=Color.white;
    }

    public void paint(Graphics g){
    setBackground(bgcolor);
    }


    public void actionPerformed(ActionEvent e)
    {
    if(e.getSource()==a){
    bgcolor=Color.blue;
    }else if(e.getSource()==b){
    bgcolor=Color.red;
    }else if(e.getSource()==c){
    bgcolor=Color.green;
    }
    repaint();
    }

    }
    what is wrong? :confused:

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

Similar Threads

  1. Change bgcolor newbea question
    By casid in forum New To Java
    Replies: 10
    Last Post: 12-04-2008, 12:11 AM
  2. Changing the Jframe
    By Nemo1959 in forum New To Java
    Replies: 13
    Last Post: 09-19-2008, 04:58 PM
  3. Changing Active Window
    By jmHoekst in forum New To Java
    Replies: 1
    Last Post: 06-14-2008, 01:21 AM
  4. Dynamically changing the display
    By abhiN in forum JavaServer Pages (JSP) and JSTL
    Replies: 1
    Last Post: 01-23-2008, 12:19 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •