Mastermind Game- Question on Color

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • mira88
    New Member
    • May 2007
    • 10

    Mastermind Game- Question on Color

    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
    Code:
      
    //part of the code where I add an action listener for one color
    // should be possible to do for all colors
    color_one.addActionListener(new AbstractAction() {
    			public void actionPerformed(ActionEvent event) {
    				if (event.getSource() == color_one) {
    					//guess_buttons[0][0].setBackground(red);
    					//
    					
    				}
    			
    
    				
    			}
    		});
    I havent posted my entire code- it's long
  • blazedaces
    Contributor
    • May 2007
    • 284

    #2
    Originally posted by mira88
    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
    Code:
      
    //part of the code where I add an action listener for one color
    // should be possible to do for all colors
    color_one.addActionListener(new AbstractAction() {
    			public void actionPerformed(ActionEvent event) {
    				if (event.getSource() == color_one) {
    					//guess_buttons[0][0].setBackground(red);
    					//
    					
    				}
    			
    
    				
    			}
    		});
    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

    Comment

    • mira88
      New Member
      • May 2007
      • 10

      #3
      Thanks a lot for the tip and for helping

      Comment

      Working...