Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Answers Viewqa Java-Beginners Having problem to set font and color
Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


kurmadu89
Having problem to set font and color
1 Answer(s)      4 years ago
Posted in : Java Beginners


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 kurmadu89@yahoo.com


Advertisement
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... I love You Mom"); msgLabel.setFont(new Font("Serif", Font.BOLD, 14
Show Font Dialog and Color Dialog
the color from the set of available colors. The method dialog.open() makes the font... Show Font Dialog and Color Dialog   ... and font dialog in Java. SWT allows to show Color Dialog and Font Dialog
Advertisements
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
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
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
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
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
Set text color in JoptionPane
Set text color in JoptionPane In this section, you will learn how to set text color in JOptionPane. Now to do this, we have used UIManager class which...("Panel.background", Color.yellow); JOptionPane.showMessageDialog(null,"Hello","Set Color
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
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
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
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
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 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 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 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 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 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 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
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
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 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
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
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
Advertisements
 

 

 

DMCA.com