Google Answers Logo
View Question
 
Q: Java applett coe problem ( No Answer,   0 Comments )
Question  
Subject: Java applett coe problem
Category: Computers > Programming
Asked by: purplepit-ga
List Price: $40.00
Posted: 05 May 2003 11:03 PDT
Expires: 05 May 2003 11:48 PDT
Question ID: 199694
Given the following code which has two buttons that are displayed on
the applet, but only one is enabled at a time.(and producing the
desired colours) Buttons are turned on or off using the setEnabled()
method: What would I need to add to have three colours red,green,and
blue??

********************************************************************************

import java.awt.*;
import java.awt.event.*;
import java.applet.*;

public class But2 extends Applet implements ActionListener
{
    Button butRed, butGreen;
    Color red = Color.red;
    Color green = Color.green;
    Color current = red;


    public void init()
    {
	butRed = new Button("Red");
	butRed.setEnabled(false);
	butRed.addActionListener(this);
	butGreen = new Button("Green");
	butGreen.addActionListener(this);
	add(butRed);
	add(butGreen);
	current = red;
    }
    
    public void actionPerformed(ActionEvent e)
    {
	String butName = e.getActionCommand();
	
	if("Red".equals(butName))
	    {
		butRed.setEnabled(false);
		butGreen.setEnabled(true);
		current = red;
	    }
	if("Green".equals(butName))
	    {
		butRed.setEnabled(true);
		butGreen.setEnabled(false);
		current = green;
	    }
	repaint();
    }

    public void paint(Graphics g)
    {
	g.setColor(current);
	g.fillRect(100,50,200,100);
    }
}

*******************************************************************************

Thanks.
Answer  
There is no answer at this time.

Comments  
There are no comments at this time.

Important Disclaimer: Answers and comments provided on Google Answers are general information, and are not intended to substitute for informed professional medical, psychiatric, psychological, tax, legal, investment, accounting, or other professional advice. Google does not endorse, and expressly disclaims liability for any product, manufacturer, distributor, service or service provider mentioned or any opinion expressed in answers or comments. Please read carefully the Google Answers Terms of Service.

If you feel that you have found inappropriate content, please let us know by emailing us at answers-support@google.com with the question ID listed above. Thank you.
Search Google Answers for
Google Answers  


Google Home - Answers FAQ - Terms of Service - Privacy Policy