Java Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingJava Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old April 24th, 2008, 08:00 PM
Head_FI Head_FI is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Apr 2008
Posts: 1 Head_FI User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 51 m 36 sec
Reputation Power: 0
Adding up color values??

Hey anyone, I have this code exercise where i have a 10 X 10 grid of Jbuttons that produces a random color when clicked. Then there is 1 row on the bottom and 1 column on the right that gives the average value of the colors from the buttons that were clicked. Basically the only part I'm confused on is how to get colors to add together. Here is what I've gotten so far. I have not found much in my book to help me .
Code:



public class Buttons extends JFrame {
	JButton[][] buttonColor = new JButton[ 10][10];
	Color[][] randColor = new Color[10][10];	
	public Buttons() {
		setSize(800, 600);
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		getContentPane().setLayout(new GridLayout(10, 10));		
		for(int i = 0; i < buttonColor.length; i++) {
			for( int o = 0; o < buttonColor[i].length; o++) {
				buttonColor[i][o] = new JButton();
				buttonColor[i][o].addMouseListener(new click());
			
				getContentPane().add(buttonColor[i][o]);
			}
		}
		setVisible(true);
	}

	
	private class click extends MouseAdapter {
		public void mouseClicked(MouseEvent e) {
		 JButton pressed = (JButton)e.getSource(); 
		 pressed.setBackground(randColor());
                 /This part doesnt work, but is just a hypothetical on my part.
                 if(ButtonIsclicked) {
                    int average = red + green + blue;
		}
	}

	public Color randColor() {
		int red = (int)(Math.random()*256);
		int blue = (int)(Math.random()* 256);
		int green = (int)(Math.random()*256);
		
		return new Color(red, green, blue);
	}
		
	
	public static void main(String[] args) {
		new Buttons();
	}
}
	


Thanks for any Help

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingJava Development > Adding up color values??


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway
Stay green...Green IT