Results 1 to 2 of 2
  1. #1
    pcman is offline Member
    Join Date
    Mar 2008
    Posts
    2
    Rep Power
    0

    Question when muse pressed the background change

    i build a applet .
    the applet need to change background when i click on him,
    but it`s dosent work...

    code:
    Java Code:
    import java.applet.*;
    import java.awt.*;
    import java.awt.event.*;
    
    public class ok extends Applet
    {
    
    	public void mousePressed( MouseEvent e ) {
    		setBackground(Color.black );
    	}
    	
    	public void paint( Graphics s)
    	{
    		s.setColor( Color.black );
    		s.drawString(  "Groovy!", 50, 150 );
    	}
      
    }
    thanks

  2. #2
    hardwired's Avatar
    hardwired is offline Senior Member
    Join Date
    Jul 2007
    Posts
    1,576
    Rep Power
    9

    Default

    Java Code:
    //  <applet code="OkApplet" width="400" height="400"></applet>
    import java.applet.*;
    import java.awt.*;
    import java.awt.event.*;
    
    public class OkApplet extends Applet
    {
        public void init()
        {
            addMouseListener(ma);
        }
    
        public void paint( Graphics s)
        {
            super.paint(s);
            s.setColor( Color.black );
            s.drawString(  "Groovy!", 50, 150 );
        }
    
        private MouseListener ma = new MouseAdapter()
        {
            Color[] colors = { Color.red, Color.blue, Color.orange };
            int index = 0;
    
            public void mousePressed( MouseEvent e )
            {
                index++;
                if(index > colors.length-1)
                    index = 0;
                setBackground(colors[index] );
                repaint();
            }
        };        
    }

Similar Threads

  1. Center background image
    By Floetic in forum AWT / Swing
    Replies: 1
    Last Post: 04-24-2008, 06:50 PM
  2. Replies: 2
    Last Post: 03-30-2008, 09:38 PM
  3. key pressed event
    By kavithas in forum New To Java
    Replies: 7
    Last Post: 12-10-2007, 03:01 PM
  4. Set the background in Java
    By barney in forum New To Java
    Replies: 1
    Last Post: 08-07-2007, 08:13 AM
  5. Background image in java
    By toby in forum AWT / Swing
    Replies: 1
    Last Post: 07-29-2007, 08:15 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
  •