I'm in the process of creating a program that would change a background color by pressing a button. Now, I already have everything set up. The background image is just an image of a rainbow, and when a button is clicked, it would change the whole background color. The thing is, I do not want the buttons at the top...I want the buttons to be in the center (see the images I included...2nd image is what I would like - I just edited it with Windows Paint). Is there an easy way to do this? Thanks.

import javax.swing.*;

import java.awt.*;

public class Buttons extends JPanel{
	public Buttons(){
		setLayout(new FlowLayout());
	public void paint(Graphics g){
		Image a = Toolkit.getDefaultToolkit().getImage("C:\\Documents and Settings\\adamh\\My Documents\\My Pictures\\rainbow.jpg");
		g.drawImage(a,0,0, getSize().width,getSize().height,this);
	public static void main(String[] args){
		JFrame myFrame = new JFrame("Rainbow Color");
		JButton redButton =  new JButton("Red");
		JButton blueButton =  new JButton("Blue");
		JButton yellowButton =  new JButton("Yellow");
		Buttons b = new Buttons();
        //more code to go here for actionPerformed...

Attachments rainbowScreenshot.JPG 26.45 KB rainbowScreenshot2.JPG 26.71 KB
This article has been dead for over six months. Start a new discussion instead.