Results 1 to 4 of 4
- 10-06-2012, 04:33 AM #1
Member
- Join Date
- Sep 2012
- Posts
- 13
- Rep Power
- 0
Set font,color for multiple objecta in one line
How would i set the font and background color of all of these objects to be the same in one command?
Instead of thisJava Code:Button bGeography = addButton("Geography 100",50,100,250,75,this); Button bSports = addButton("People 100",300,100,250,75,this); Button bVocab = addButton("Vocab 100",550,100,250,75,this);
Java Code:bGeography.setFont(new Font("Arial",1,20)); bVocab.setFont(new Font("Arial",1,20)); bSports.setFont(new Font("Arial",1,20)); bGeography.setBackground(new Color(139,121,94)); bSports.setBackground(new Color(139,121,94)); bVocab.setBackground(new Color(139,121,94));
- 10-06-2012, 04:57 AM #2
Re: Set font,color for multiple objecta in one line
I presume you would write an addButton() method that takes those parameters and does the appropriate things with them. This looks like a school assignment to me.
How to Ask Questions the Smart Way
Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!
- 10-06-2012, 05:32 AM #3
Member
- Join Date
- Sep 2012
- Posts
- 13
- Rep Power
- 0
Re: Set font,color for multiple objecta in one line
I edited the method in my utility class.
Java Code:public Button addButton(String text, int left, int top, int width, int height, ActionListener listener, int one, int two, int three) { Button newComp = new Button(text); add(newComp); newComp.setBounds(left,top,width,height); newComp.setBackground(new Color(one,two,three)); newComp.setFont(new Font("Arial",1,18)); if (listener!=null)newComp.addActionListener(listener); return newComp; }
- 10-06-2012, 07:44 AM #4
Re: Set font,color for multiple objecta in one line
Comments:
1. Learn to indent and otherwise format code for readability: Code Conventions for the Java Programming Language: Contents
2. There's no need for a null check. Calling addActionListener(null) does nothing.
3. Get rid of all the setBounds(...) garbage and learn to use layout managers correctly: Lesson: Laying Out Components Within a Container (The Java™ Tutorials > Creating a GUI With JFC/Swing)
dbWhy do they call it rush hour when nothing moves? - Robin Williams
Similar Threads
-
PdfBox font color
By BobswYourUcle in forum New To JavaReplies: 1Last Post: 07-13-2011, 05:04 AM -
Set Font Color, Font Style & Font Family While Replacing Text
By sherazam in forum Java SoftwareReplies: 0Last Post: 08-18-2010, 10:31 AM -
font color
By newbie123 in forum New To JavaReplies: 2Last Post: 03-01-2010, 03:58 PM -
How to change font/ font color etc in a graphic object using JCombobox?
By JavaInLove in forum AWT / SwingReplies: 5Last Post: 04-25-2009, 08:00 PM -
to set toolItem font color
By vidyakkk in forum SWT / JFaceReplies: 0Last Post: 01-30-2009, 03:06 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks