Adding backgroundcolor to snake applet - Printable Version +- BP Forums (https://bpforums.info) +-- Forum: Programming Discussion (https://bpforums.info/forumdisplay.php?fid=34) +--- Forum: Java (https://bpforums.info/forumdisplay.php?fid=41) +--- Thread: Adding backgroundcolor to snake applet (/showthread.php?tid=907) |
Adding backgroundcolor to snake applet - Kevin - 08-28-2015 Hi guys, first, i'm not the best english speaker and -writer. Therefore i ask you to apologize my language mistakes 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; 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 Yours sincerley Kevin Edit: Kevin is only a nickname RE: Adding backgroundcolor to snake applet - brandonio21 - 09-01-2015 Kevin, Welcome to BP Forums! So I think that your issue regarding changing the color of the snake game's background comes down to the way you are attempting to do so. Basically, it looks like you are trying to add two new panels, each with a black background. Then, you add the SnakeCanvas on top of the two panels. The background of the SnakeCanvas is white, so the black JPanels get covered up. Since SnakeCanvas extends Java's Canvas, it can have it's background color set. I think that what you may want to do is alter the code of the SnakeCanvas class to have a Black background. If that doesn't work, you can always alter the Draw function of the SnakeCanvas class to first draw a black rectangle. Then, you will need to change the colors for everything else in SnakeCanvas's draw method. |