Share on Google+Share on Google+

kurmadu89
Having problem to set font and color
1 Answer(s)      6 years and 6 months 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 [email protected]

Ads

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
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 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 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 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 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
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 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
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
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
Tutorials   
Java Spring Hibernate Struts Training Retrieve database from the table dynamically in jsp from oracle using servlet What does core Java include? java What are some way to learn Java quickly? Is it required to learn Java before learning Java Script? Is it necessary to learn java script before learning PHP? Are HTML5 and Java Script boosts Java career? Is Java object oriented? Fingerprint application with Java Uninstall Oracle Virtual Box JSON to HashMap Free Java online Training I want example of Control Statement in Java ANSI Color Codes with Python Create a Program that Calculates Input What is difference between JDK,JRE and JVM? How to see ubuntu version on server? How to get Page Source in Selenium (WebDriver) using Java? The path to the driver executable must be set by the webdriver.gecko.driver system property parse data from a link in java Java Program Qns using BlueJ How to fix HAX Kernel Module Is Not Installed error? Installing Audacity Looking for code Logic to check track changes & Coments in MSWord, MSWordx, MSExcel, MSExcelx is ON/OFF Installing JDK on Mac SAX Parser exception ERROR 601 (42P00): Syntax error. Encountered Thread java.lang.NoClassDefFoundError: org/apache/commons/fileupload/FileItemFactory How to install Ubuntu 16.04 LTS? HttpServletRequest cannot be resolved to a type in eclipse - Solved Unhandled event loop exception GC overhead limit exceeded Spring Data jpa with apache phoenix Caused by: java.lang.IllegalArgumentException: Not a host:port pair: PBUF o.a.h.h.z.RecoverableZooKeeper - Possibly transient ZooKeeper, quorum= com.thinkaurelius.titan.diskstorage.hbase.HBaseStoreManager class not found com.thinkaurelius.titan.diskstorage.hbase.HBaseStoreManager not found How to download and install Java 8 on Windows? How to uninstall JDK 7? How to install gtk-doc-tools package in Ubuntu? How to install Oracle JDK 8 on Ubuntu? ejabberd_ctl.beam not found - Solved How to convert date to UTC format in Java? How to install autoconf, automake and libtool in Ubuntu 15.10? How to convert current date to mm dd yyyy format in Java? How to convert current date to dd mm yyyy format in Java? How to stop window closing in "internalFrameClosing" event. How to find list of all index in Neo4j? neo4j-server.properties file location SASLError using PLAIN: not-authorized

Ads

 
Advertisement null

Ads