473,378 Members | 1,555 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

Mastermind Game- Question on Color

10
Hi,
I have to program the Mastermind game( dont' know if anyone knows it). Anyway I've got my GUI looking quite pretty :), but I want to know something on working with Colors. I' ve got 6 colors to choose from and I have given differernt rgb values for these colors. I want to know how, when I click on one color eg red, the first button( I used buttons) , turns to red- I ve tried with setBackground but I don't think its right . I've thought about using a getColor Method that would return red for example. I need some guidance . Thanks
Expand|Select|Wrap|Line Numbers
  1.  
  2. //part of the code where I add an action listener for one color
  3. // should be possible to do for all colors
  4. color_one.addActionListener(new AbstractAction() {
  5.             public void actionPerformed(ActionEvent event) {
  6.                 if (event.getSource() == color_one) {
  7.                     //guess_buttons[0][0].setBackground(red);
  8.                     //
  9.  
  10.                 }
  11.  
  12.  
  13.  
  14.             }
  15.         });   
I havent posted my entire code- it's long
Jun 20 '07 #1
2 1599
blazedaces
284 100+
Hi,
I have to program the Mastermind game( dont' know if anyone knows it). Anyway I've got my GUI looking quite pretty :), but I want to know something on working with Colors. I' ve got 6 colors to choose from and I have given differernt rgb values for these colors. I want to know how, when I click on one color eg red, the first button( I used buttons) , turns to red- I ve tried with setBackground but I don't think its right . I've thought about using a getColor Method that would return red for example. I need some guidance . Thanks
Expand|Select|Wrap|Line Numbers
  1.  
  2. //part of the code where I add an action listener for one color
  3. // should be possible to do for all colors
  4. color_one.addActionListener(new AbstractAction() {
  5.             public void actionPerformed(ActionEvent event) {
  6.                 if (event.getSource() == color_one) {
  7.                     //guess_buttons[0][0].setBackground(red);
  8.                     //
  9.  
  10.                 }
  11.  
  12.  
  13.  
  14.             }
  15.         });   
I havent posted my entire code- it's long
I believe you need to utilize your paintComponent method and after you change the background call the repaint() method. This is the only way for any color/paint changes to occur. Look at some tutorials or search for example code that shows how to update changes in paint on any GUI to learn more...

good luck,
-blazed
Jun 20 '07 #2
mira88
10
Thanks a lot for the tip and for helping
Jun 27 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

21
by: BlackHawke | last post by:
My name is Nick Soutter, I own a small game development company (www.aepoxgames.net) making our first game (www.andromedaonline.net) in java. I am writing because we are having a very...
138
by: theodp | last post by:
--> From http://www.techdirt.com/articles/20040406/1349225.shtml Microsoft Patents Saving The Name Of A Game Contributed by Mike on Tuesday, April 6th, 2004 @ 01:49PM from the...
1
by: Jerry Fleming | last post by:
Hi, I have wrote a game with python curses. The problem is that I want to confirm before quitting, while my implementation doesn't seem to work. Anyone can help me? #!/usr/bin/python # #...
7
by: Gasten | last post by:
Hello. The last weeks I've been coding a roguelike (you know, like nethack) in python using the nCurses library. Some week ago I ran into a problem: When I made the object for messagebar-output, I...
5
by: Kraken | last post by:
Hi, i have a bit of a problem here. I have an assignment to do an animal guessing game using an original database and updating it as the user enters new animals in it. The program enters the file...
2
Butterflybis
by: Butterflybis | last post by:
Hi all, I’m newbie in java code development, I have written a mastermind play, and I would like to include a time limitation (for example 3 minutes) which appears like a coloured and vertical...
2
by: ImmortalFire | last post by:
/* * Mastermind * * Author: Gerald Cruz * * Date: June 21, 2008 * */ #include<iostream>
2
by: LilMeechc20 | last post by:
Hello, I have a group assignment that I have to do. We have to write a Tic Tac Toe game. One person in my group has managed to write the code for a multiplayer (human -vs- human) game and I...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.