Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Adding backgroundcolor to snake applet
#1
Hi guys,

first, i'm not the best english speaker and -writer. Therefore i ask you to apologize my language mistakes Smile

Problably in your eyes, i have a very simply problem, but i cant add the background function to Brandonio's Snake Project. I want to have a black background in the applet. After this, i want to change the color of the grid to white.

I try to add two JPanel's to snakeApplet.java. But is it still not working. Every time i started the Applet, the background is white.



Code:
import java.applet.Applet;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;

import javax.swing.JPanel;

public class snakeApplet extends Applet{

    private snakeCanvas c;
    JPanel jp1 = new JPanel();
    JPanel jp2 = new JPanel();
    
    public void init()
    {
        jp1.setBackground(Color.BLACK);
        add(jp1);
        
        jp2.setBackground(Color.BLACK);
        add(jp2, BorderLayout.SOUTH);
        
        c = new snakeCanvas();
        c.setSize(new Dimension(640, 480));
        c.setPreferredSize(new Dimension(640, 480));
        c.setVisible(true);
        c.setFocusable(true);
        this.add(c);
        this.setVisible(true);
        this.setSize(new Dimension(640, 480));
        
    }
    
    public void paint(Graphics g)
    {
        this.setSize(new Dimension(640, 480));
    }
}
In addition, i want to add music to the applet. The music should instantly playing if the applet is open.
If the idea of the black background and white grid is not to be a looker, than i would to add a picture in the background of the grid.
But i dont know how i can code it.
I hope someone can help me please Smile
Yours sincerley
Kevin

Edit: Kevin is only a nickname Big Grin
Reply


Messages In This Thread
Adding backgroundcolor to snake applet - by Kevin - 08-28-2015, 08:51 AM

Forum Jump:


Users browsing this thread: 1 Guest(s)