Having problem to set font and color

Having problem to set font and color

Hello Sir, i have some problem to set font and color in my program.Can you take a look for the moment please?

Here is my program:

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

public class showYourLove extends JFrame //inherits from JFrame class { private JPanel panel; //to references a panel private JLabel msgLabel;//to reference a label private JTextField LoveTxtField;//to reference a text field private JButton Button;//to reference a button private JLabel picLabel; private final int width=400;//window width private final int height=600;//window height

public showYourLove() //constructor { setTitle("Show Your Love !"); setSize(width,height); setDefaultCloseOperation(JFrame.EXITONCLOSE); buildPanel(); add(panel); setVisible(true);

}

private void buildPanel(){

//method that adds a lable,textfield and button

JLabel msgLabel= new JLabel("Show your love to your Mom by type I love You Mom"); msgLabel.setFont(new Font("Serif", Font.BOLD, 14)); msgLabel.setForeground(Color.blue);

LoveTxtField=new JTextField(10);
Button=new JButton("Done");
JLabel picLabel=new JLabel(new ImageIcon("C:\\Documents and Settings\\User\\My Documents\\JCreator LE\\MyProjects\\LibGui\\showYourLove\\src\\love.GIF"));






//add an action listener to the button,below the code in which you declare a button of type JButton in the buildPanel() method.

Button.addActionListener(new ButtonListener()); panel=new JPanel(); panel.add(msgLabel); panel.add(LoveTxtField); panel.add(Button); panel.add(picLabel);

}

private class ButtonListener implements ActionListener { public void actionPerformed(ActionEvent e) {

    String actionCommand=e.getActionCommand();


        //Display the result

        JOptionPane.showMessageDialog(null,"Thank you for showing your love here.");

}

}

public static void main(String[]args)

{

showYourLove love = new showYourLove();

} }

Thank You. by [email protected]

View Answers

October 30, 2010 at 11:11 AM

Hello Friend,

Try the following code:

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

public class showYourLove extends JFrame{ 
    private JPanel panel; 
    private JLabel msgLabel;
    private JTextField LoveTxtField;
    private JButton button;
    JLabel picLabel;
    private final int width=400;
 private final int height=600;

public showYourLove() { 
    setTitle("Show Your Love !");
    setSize(width,height); 
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    buildPanel();
    add(panel); 
    setVisible(true);
}
private void buildPanel(){
JLabel msgLabel= new JLabel("Show your love to your Mom by type I love You Mom"); 
msgLabel.setFont(new Font("Monotype Corsiva", Font.BOLD, 14));
msgLabel.setForeground(Color.blue);
LoveTxtField=new JTextField(10);
button=new JButton("Done");
JLabel picLabel=new JLabel(new ImageIcon("C:\\Documents and Settings\\User\\My Documents\\JCreator LE\\MyProjects\\LibGui\\showYourLove\\src\\love.GIF"));
button.addActionListener(new ButtonListener());
panel=new JPanel();
panel.add(msgLabel);
panel.add(LoveTxtField);
panel.add(button);
panel.add(picLabel);

}
private class ButtonListener implements ActionListener {
    public void actionPerformed(ActionEvent e) {
    JOptionPane.showMessageDialog(null,"Thank you for showing your love here.");
}
}
public static void main(String[]args){
showYourLove love = new showYourLove();
}
}

Thanks









Related Tutorials/Questions & Answers:
Having problem to set font and color
Having problem to set font and color  Hello Sir, i have some problem to set font and color in my program.Can you take a look for the moment please...("Show your love to your Mom by type I love You Mom"); msgLabel.setFont(new Font
Having problem with image upload....
Having problem with image upload....  I am uploading profile pictures in my site.But after uploading when I visit my home page where it is supposed... resource is not found on server.The same problem is occurring in case
Advertisements
pojo class having problem
pojo class having problem  Cannot find any information on property 'Username' in a bean of type 'LoginBean.LoginBeanClass' org.apache.jasper.runtime.JspRuntimeLibrary.handleSetProperty(JspRuntimeLibrary.java:664
How to set Marathi font to Label??
How to set Marathi font to Label??  Hello, I am doing one project in java-Swing Farm Management i want to set Marathi label in that so how i can? plzzzz help me its urgent
Show Font Dialog and Color Dialog
Show Font Dialog and Color Dialog   ... and font dialog in Java. SWT allows to show Color Dialog and Font Dialog... the color from the set of available colors.ADS_TO_REPLACE_1 The method dialog.open
Change Color and Font of text
Change Color and Font of text       This section illustrates you how to change color and font of text using TextAttributes class. A string is defined and the class
Set Color in JOptionPane
Set Color in JOptionPane       In this section, you will learn how to set color in JOptionPane. Now to do... following key value pair, we have set the background color for JOptionPane
How to set the Gradient Color as a background color for Java Frame?
How to set the Gradient Color as a background color for Java Frame?  How to set the Gradient Color as a background color for Java Frame
Set text color in JoptionPane
Set text color in JoptionPane In this section, you will learn how to set text...("Panel.background", Color.yellow); JOptionPane.showMessageDialog(null,"Hello","Set Color... we have explained you how to Set text color in JoptionPane
Here is a set of 18 different shades of FireBrick color rangeing from lighter FireBrick color to darker FireBrick color.
.menuText1 { font:10pt bold Arial, Helvetica, sans-serif; color:#FFFFFF; text-align:left; padding:5px 0px 5px 5px; } .menuText2 { font:10pt bold Arial, Helvetica, sans-serif; color:#000000; text-align:left; padding
iPhone Font Size
iPhone Font Size In this example we are going to change the iphone font size and color. You can change the font size and font type using the Inspector that resides in Interface Builder->Tools. It has the number of font
having problem with menu ans sub menu items css ...plz help!!
having problem with menu ans sub menu items css ...plz help!!  PLZ...:none; } .item ul li a{ font-size:15px; text-decoration:none; letter-spacing:1.5px; text-transform:uppercase; color:#222
I am having problem with configuring Hibernate sessionfactory. Please Help
I am having problem with configuring Hibernate sessionfactory. Please Help  Sir, I am having problem with configuring Hibernate sessionfactory.. I was using the old version of Hibernate before now I am using Hibernate 4
This is the 18 color set of LightCoral ranging from light to darker.
.menuText1 { font:10pt bold Arial, Helvetica, sans-serif; color:#FFFFFF; text-align:left; padding:5px 0px 5px 5px; } .menuText2 { font:10pt...:5px 0px 5px 5px; } This is the 18 color set of LightCoral ranging from light
This is the 18 color set of MediumGreen ranging from light to darker.
.menuText1 { font:10pt bold Arial, Helvetica, sans-serif; color:#FFFFFF; text-align:left; padding:5px 0px 5px 5px; } .menuText2 { font:10pt...:5px 0px 5px 5px; } This is the 18 color set of MediumGreen ranging from light
This is the 18 color set of Rosy Brown ranging from light to darker.
.menuText1 { font:10pt bold Arial, Helvetica, sans-serif; color:#FFFFFF; text-align:left; padding:5px 0px 5px 5px; } .menuText2 { font:10pt...:5px 0px 5px 5px; } This is the 18 color set of Rosy Brown ranging from light
This is the 18 color set of Spring Green ranging from light to darker.
.menuText1 { font:10pt bold Arial, Helvetica, sans-serif; color:#FFFFFF; text-align:left; padding:5px 0px 5px 5px; } .menuText2 { font:10pt...:5px 0px 5px 5px; } This is the 18 color set of Spring Green ranging from light
This is the 18 color set of Crimson ranging from light to darker.
.menuText1 { font:10pt bold Arial, Helvetica, sans-serif; color:#FFFFFF; text-align:left; padding:5px 0px 5px 5px; } .menuText2 { font:10pt...:5px 0px 5px 5px; } This is the 18 color set of Crimson ranging from
This is the 18 color set of Tomato ranging from light to darker.
.menuText1 { font:10pt bold Arial, Helvetica, sans-serif; color:#FFFFFF; text-align:left; padding:5px 0px 5px 5px; } .menuText2 { font:10pt...:5px 0px 5px 5px; } This is the 18 color set of Tomato ranging from light
This is the 18 color set of Almond ranging from light to darker.
.menuText1 { font:10pt bold Arial, Helvetica, sans-serif; color:#FFFFFF; text-align:left; padding:5px 0px 5px 5px; } .menuText2 { font:10pt...:5px 0px 5px 5px; } This is the 18 color set of Almond ranging from light
This is the 18 color set of DarkGoldenRod ranging from light to darker.
.menuText1 { font:10pt bold Arial, Helvetica, sans-serif; color:#FFFFFF; text-align:left; padding:5px 0px 5px 5px; } .menuText2 { font:10pt...:5px 0px 5px 5px; } This is the 18 color set of DarkGoldenRod ranging
This is the 18 color set of LightYellow ranging from light to darker.
.menuText1 { font:10pt bold Arial, Helvetica, sans-serif; color:#FFFFFF; text-align:left; padding:5px 0px 5px 5px; } .menuText2 { font:10pt...:5px 0px 5px 5px; } This is the 18 color set of LightYellow ranging from light
This is the 18 color set of MediumPurple ranging from light to darker
.menuText1 { font:10pt bold Arial, Helvetica, sans-serif; color:#FFFFFF; text-align:left; padding:5px 0px 5px 5px; } .menuText2 { font:10pt...:5px 0px 5px 5px; } This is the 18 color set of MediumPurple ranging from light
This is the 18 color set of SlateGray ranging from light to darker.
.menuText1 { font:10pt bold Arial, Helvetica, sans-serif; color:#FFFFFF; text-align:left; padding:5px 0px 5px 5px; } .menuText2 { font:10pt...:5px 0px 5px 5px; } This is the 18 color set of SlateGray ranging from light
This is the beautiful Coral color set that is mostly found in deep blue ocean.
.menuText1 { font:10pt bold Arial, Helvetica, sans-serif; color:#FFFFFF; text-align:left; padding:5px 0px 5px 5px; } .menuText2 { font:10pt...:5px 0px 5px 5px; } This is the beautiful Coral color set that is mostly
This is a set of 18 different shades of DarkSalmon colors covering lighter DarkSalmon color to darker DarkSalmon color.
.menuText1 { font:10pt bold Arial, Helvetica, sans-serif; color:#FFFFFF; text-align:left; padding:5px 0px 5px 5px; } .menuText2 { font:10pt bold Arial, Helvetica, sans-serif; color:#000000; text-align:left; padding
How to set UILabel text size, color etc.. in XCode
How to set UILabel text size, color etc.. in XCode  How to set UILabel text size (height), color etc.. in XCode
Here is a set of 26 different shades of one of the most trendy Gray color rangeing from lighter Gray color to darker Gray color.
.menuText1 { font:10pt bold Arial, Helvetica, sans-serif; color:#FFFFFF; text-align:left; padding:5px 0px 5px 5px; } .menuText2 { font:10pt bold Arial, Helvetica, sans-serif; color:#000000; text-align:left; padding
This is the 26 color set of Blue ranging from light to darker.
.menuText1 { font:10pt bold Arial, Helvetica, sans-serif; color:#FFFFFF; text-align:left; padding:5px 0px 5px 5px; } .menuText2 { font:10pt...:5px 0px 5px 5px; } This is the 26 color set of Blue ranging from light
This is the 26 color set of Green ranging from light to darker.
.menuText1 { font:10pt bold Arial, Helvetica, sans-serif; color:#FFFFFF; text-align:left; padding:5px 0px 5px 5px; } .menuText2 { font:10pt...:5px 0px 5px 5px; } This is the 26 color set of Green ranging from light
Set Different Color to different row in Java Program
Java Set Different Color to different row In this section, you will learn how to set different color to table row using java swing.For this purpose, we have created a table and use TableCellRenderer class to change the color of cell
Here is a set of 26 different shades of one of the most favourite Orange colors rangeing from light Orange color to darker Orange color.
.menuText1 { font:10pt bold Arial, Helvetica, sans-serif; color:#FFFFFF; text-align:left; padding:5px 0px 5px 5px; } .menuText2 { font:10pt bold Arial, Helvetica, sans-serif; color:#000000; text-align:left; padding
Here is a set of 26 different shades of one of the most favourite Pink colors rangeing from light Pink color to darker Pink color.
.menuText1 { font:10pt bold Arial, Helvetica, sans-serif; color:#FFFFFF; text-align:left; padding:5px 0px 5px 5px; } .menuText2 { font:10pt bold Arial, Helvetica, sans-serif; color:#000000; text-align:left; padding
Here is a set of 18 different shades of one of the most trendy Medium Aqua Marine color
.menuText1 { font:10pt bold Arial, Helvetica, sans-serif; color:#FFFFFF; text-align:left; padding:5px 0px 5px 5px; } .menuText2 { font:10pt bold Arial, Helvetica, sans-serif; color:#000000; text-align:left; padding
How to set pdf background color.
How to set pdf background color. In this example, you will see how to set back ground color of pdf in struts2.  index.jsp <html>ADS_TO_REPLACE_1 <head> <title>SetBackGround</title> </head>
UIWebView Background Color
UIWebView Background Color If you wanted to change the background color on UIWebView in iPhone SDK, then you required to set the background color of UIWebView using UIColor. UIColor object represents color and opacity (alpha value
Set the Color of a Tab in a Tabbed Pane Container in Java
Set the Color of a Tab in a Tabbed Pane Container in Java... This program shows you how to set the color for each tab in the tabbed pane... is the color which has to be set for the specific tab. setBackgroundAt(int Index
Here is a set of 18 different shades of one of the most favourite Choclate colors
.menuText1 { font:10pt bold Arial, Helvetica, sans-serif; color:#FFFFFF; text-align:left; padding:5px 0px 5px 5px; } .menuText2 { font:10pt bold Arial, Helvetica, sans-serif; color:#000000; text-align:left
Here is a set of 26 different shades of one of the most favourite Red colors
.menuText1 { font:10pt bold Arial, Helvetica, sans-serif; color:#FFFFFF; text-align:left; padding:5px 0px 5px 5px; } .menuText2 { font:10pt bold Arial, Helvetica, sans-serif; color:#000000; text-align:left; padding
Setting Colors in JSP
;    In Jsp also we can set the background color which we want, the font color can be changed. The table can be coloured . By using...;"> <font color="white"><%= colors[i]%><
Color Picker in Flex
Adobe Flex Color Picker: A color picker helps users to select a color of their own choice. A color picker is a component which displays a set of color as swatch and user has to pick a color. The sample panel displays set of colors which
UITextfield Background Color
; iPhone UITextField Background Color Set the text field background color... text field as a search field. The code is working fine but the problem is ..it's showing a background color. Though my text field color is white. Can you please
UILabel Font Size
UILabel Font Size  Hi Developers, How to set font size of UILabel? I am creating label programmatically and I have to set the font size programatically. How I can set UILabel Font Size? Thanks   HI, Following
font changing
font changing  I have created a welcome page and when I try to change the font style of the label named lblCName it does not change.Indentify..., placeOrdr; Icon image; Font fnt; public void init(){ fnt=new Font("Verdana
Explain the parameters of Font class constructor.
. If name is null, the name of the new Font is set to the name "Default". style...Explain the parameters of Font class constructor.  Explain the parameters of Font class constructor.   Java Font class: Font(String name
Font in Flex4
font for give a color , size and etc. Example: <?xml version...|VGroup{ font-family:Helvetica;ADS_TO_REPLACE_4 font-size:18px; color...Font in Flex4: In this example you can see how we can use font in a flex
PHP GD image negative Color
= imagecolorat($image, $x, $y); $rgb = imagecolorsforindex($index); $color... - $rgb['blue']); imagesetpixel($im, $x, $y, $color); } } return(true... 'Negative color conversion failed.'; } ?> After running the program you
HTML font tag.
;br/><font color="green" size="4"> It is used...HTML font tag. Description : It is a HTML tag, which is used for changing the view of your text. Which will display on view page. Syntax : <font
ModuleNotFoundError: No module named 'font-font-awesome'
ModuleNotFoundError: No module named 'font-font-awesome'  Hi, My... named 'font-font-awesome' How to remove the ModuleNotFoundError: No module named 'font-font-awesome' error? Thanks   Hi, In your
color cycle
color cycle  how do you implement a program for color cycle that has a button such that when i press the button it brings a sequence for example green-red-grey-green e.t.c and should use the getter methods and set methods

Ads