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 colorHaving 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 problempojo 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
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
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 Set Different Color to different row in Java ProgramJava
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
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 ColorUIWebView 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
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 FlexAdobe 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 SizeUILabel
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 changingfont 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 color cyclecolor 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