User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the Java section within the Software Development category of DaniWeb, a massive community of 455,976 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,797 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our Java advertiser: Lunarpages Java Web Hosting
Views: 9307 | Replies: 4
Reply
Join Date: Aug 2004
Posts: 3
Reputation: jjohnson33 is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
jjohnson33 jjohnson33 is offline Offline
Newbie Poster

Help I can't figure out how to change my jbutton font and color ( heres the code )

  #1  
Aug 25th, 2004
/*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");

}

}
}
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Jul 2004
Location: Pakistan
Posts: 1,673
Reputation: nanosani is an unknown quantity at this point 
Rep Power: 8
Solved Threads: 50
Colleague
nanosani's Avatar
nanosani nanosani is offline Offline
Unauthenticated Liar

Re: I can't figure out how to change my jbutton font and color ( heres the code )

  #2  
Aug 26th, 2004
For changing the color ... button.setForegroundColor(Color.red);
For changing the font ... button.setFont("Verdana");
Reply With Quote  
Join Date: Jul 2004
Posts: 4
Reputation: BlackDeath is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
BlackDeath's Avatar
BlackDeath BlackDeath is offline Offline
Newbie Poster

Re: I can't figure out how to change my jbutton font and color ( heres the code )

  #3  
Aug 26th, 2004
I dont get it, whats the problem?
It's not wrong not knowing, but it's wrong not wanting to know.
Reply With Quote  
Join Date: Jul 2004
Location: Pakistan
Posts: 1,673
Reputation: nanosani is an unknown quantity at this point 
Rep Power: 8
Solved Threads: 50
Colleague
nanosani's Avatar
nanosani nanosani is offline Offline
Unauthenticated Liar

Re: I can't figure out how to change my jbutton font and color ( heres the code )

  #4  
Aug 27th, 2004
Originally Posted by jjohnson33
// 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.
Reply With Quote  
Join Date: Aug 2004
Posts: 4
Reputation: scordle725 is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
scordle725 scordle725 is offline Offline
Newbie Poster

Re: I can't figure out how to change my jbutton font and color ( heres the code )

  #5  
Aug 31st, 2004
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()
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb Java Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the Java Forum

All times are GMT -4. The time now is 9:20 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC