0

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...

}
Attachments rainbowScreenshot.JPG 26.45 KB rainbowScreenshot2.JPG 26.71 KB
2
Contributors
2
Replies
3
Views
6 Years
Discussion Span
Last Post by jabanista
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.