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]
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