/*jesse johnson
  Help.java csc 110
  August 25, 2004 */

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class Help extends JApplet implements ActionListener
{
	// GUI Buttons
	JButton ifButton , ifElseButton , switchButton , whileButton , doWhileButton , forButton, clearArea;
	JTextArea output;
	JLabel statusBar;

	public void init() {

		 Container container = getContentPane();
		 container.setLayout( new FlowLayout() );  
		 Font     f = new Font("Courier", Font.BOLD, 10);
		 
		
		 ifButton = new JButton( "     If..........",f );
		 ifButton.addActionListener( this );
		 container.add( ifButton );
		 
		  
		ifElseButton = new JButton( "     If..Else ",f );
	    ifElseButton.addActionListener( this );
   	    container.add( ifElseButton );

		  
		switchButton = new JButton( " Switch.. " );
	    switchButton.addActionListener( this );
   	    container.add( switchButton );

		  
		whileButton = new JButton( " .While..   " );
	    whileButton.addActionListener( this );
   	    container.add( whileButton );

		  
		doWhileButton = new JButton( "Do While" );
	    doWhileButton.addActionListener( this );
   	    container.add( doWhileButton );

		 
		forButton = new JButton( "For  Loop" );
	    forButton.addActionListener( this );
   	    container.add( forButton );

		output = new JTextArea( 13, 20 );
		container.add( output );

		clearArea = new JButton( "clearArea" );
		clearArea.addActionListener( this );
		container.add ( clearArea );

		setSize ( 225, 500 );

	} // end method init

	public void actionPerformed(ActionEvent ae )
	{
		 String text;
		 JButton but = ( JButton )ae.getSource();
		
		//Handle what button was pushed
	    //Action for if button
		if( but.getText() == "     If..........")
		{
			 text =  " if ( condition ) {\n\n statements;\n\n} ";
			 
			 output.setText( text );
			
			 showStatus("If Statement ");
			 
		}

		else if (but.getText() == "     If..Else " )
		{
			 text = "if ( condition ) {\n\n   statements;\n\n}\nelse { \n\n    statements;\n\n}";
				
			 output.setText( text );

			 showStatus("If...Else Statement");
		}

		else if (but.getText() == " Switch.. " )
		{
			text = "switch ( condition ) {\n\ncase ABC:\n   statement;\n  /*falls through */"+
				"\n\ncase DEF :\n   statements;\n   break;\n\ncase XYZ :\n   statements;\n   break;"+
				"\n\ndefault :\n   statements;\n   break;\n\n}";

			output.setText( text );

			showStatus("Switch Statement");
		}

		else if (but.getText() == " .While..   " )
		{
			text = "while ( condition ) {\n   statements;\n\n}";

			output.setText( text );

			showStatus(" While Loop");

		}

		else if (but.getText() == "Do While" )
		{
			text = "do {\n   statements;\n\n} while ( condition );";

			output.setText( text );

			showStatus("Do...While Loop");
		}

		else if (but.getText() == "For  Loop" )
		{
			text = " for ( initialization; condition; counter ) {\n   statements;\n\n}";

			output.setText( text );

			showStatus("For Loop");

		}

		else if (but.getText() == "clearArea"  )
		{
			text = " ";

			output.setText( text );

			showStatus("Click Another Button");

		}
		
	}
}

Recommended Answers

All 6 Replies

For changing the color ... button.setForegroundColor(Color.red);
For changing the font ... button.setFont("Verdana");

I dont get it, whats the problem?

// GUI Buttons
JButton ifButton , ifElseButton , switchButton , whileButton , doWhileButton , forButton, clearArea;
JTextArea output;
JLabel statusBar

ifButton.setForegroundColor(Color.red);
ifButton.setBackgroundColor(Color.black);
ifButton.setFont("Verdana");

Other buttons are likewise. If you have problems now ... post again.

check out the following copy from the Java API site:

setForeground
public void setForeground(Color fg)Sets the foreground color of this component.

Overrides:
setForeground in class Component
Parameters:
fg - the desired foreground Color
See Also:
Component.getForeground()

Try this..:-

String name=new String("<html><font color=RED size=10>Button1</font></html>");
JButton b1=new JButton(name);

You can use HTML tags in strings....
Use these (HTML) strings to put labels on JButtons/JLabels etc..

I guess you didn't notice that the post was from August 2004?
I very much doubt that the OP is still waiting for an answer.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.