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(){
		setOpaque(false);
		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);
		super.paint(g);
	}
	
	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();
		b.add(redButton);
		b.add(blueButton);
		b.add(yellowButton);
		myFrame.add(b);
		myFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		myFrame.setSize(350,700);
		myFrame.setVisible(true);
	}
	
        //more code to go here for actionPerformed...

}

Recommended Answers

All 2 Replies

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.