| | |
I can't figure out how to change my jbutton font and color ( heres the code )
Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: Aug 2004
Posts: 3
Reputation:
Solved Threads: 0
/*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");
}
}
}
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");
}
}
}
Re: I can't figure out how to change my jbutton font and color ( heres the code )
0
#2 Aug 26th, 2004
For changing the color ... button.setForegroundColor(Color.red);
For changing the font ... button.setFont("Verdana");
For changing the font ... button.setFont("Verdana");
Re: I can't figure out how to change my jbutton font and color ( heres the code )
0
#3 Aug 26th, 2004
Re: I can't figure out how to change my jbutton font and color ( heres the code )
0
#4 Aug 27th, 2004
•
•
•
•
Originally Posted by jjohnson33
// GUI Buttons
JButton ifButton , ifElseButton , switchButton , whileButton , doWhileButton , forButton, clearArea;
JTextArea output;
JLabel statusBar
Java Syntax (Toggle Plain Text)
ifButton.setForegroundColor(Color.red); ifButton.setBackgroundColor(Color.black); ifButton.setFont("Verdana");
Other buttons are likewise. If you have problems now ... post again.
•
•
Join Date: Aug 2004
Posts: 4
Reputation:
Solved Threads: 0
Re: I can't figure out how to change my jbutton font and color ( heres the code )
0
#5 Aug 31st, 2004
![]() |
Similar Threads
- JButton text color (Java)
- how to change the font color of command button please help newbiee.... (Visual Basic 4 / 5 / 6)
- JTextArea & Font Color (Java)
- change font type, font color, font size and bacground color in listbox (JavaScript / DHTML / AJAX)
- change the font/color of the selected text on a web page through javascript (JavaScript / DHTML / AJAX)
Other Threads in the Java Forum
- Previous Thread: help with database assignment
- Next Thread: Loading images in AWT
| Thread Tools | Search this Thread |
911 actionlistener addressbook android api append applet application array arrays automation binary bluetooth character chat class classes client code component consumer csv database desktop draw eclipse error event exception fractal ftp game givemetehcodez graphics gui html ide image input integer j2me japplet java javaarraylist javac javaee javaprojects jmf jni jpanel julia linked linux list loop map method methods mobile netbeans newbie objects online oracle oriented panel print printf problem program programming project projects properties recursion replaydirector reporting researchinmotion robot rotatetext rsa scanner screen se server set size sms sort sql string swing template test threads time tree ubuntu update windows






