I need to create a JApplet containing a JLabel and a Jbutton. a JButton should automatically change font typeface, style and size when clicked. I have this coding so far :

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class JChangeFont extends JFrame implements ActionListener
{
JLabel name = new JLabel ("Your Name");
Font bigfont = new Font ("Arial",Font.ITALIC, 16);
JButton press = new JButton ("Press");
final int WIDTH = 450;
final int HEIGHT = 200;

and I am stuck here, I don't know what to write forward, can you please show me the coding for changing jbutton font?

Thanks for your help

I know that I need to implement the actionPerformed() method required by ActionListener. Then you need to add the JFrame as an ActionListener of the "press" button. In the actionPerformed() method, change the font of the JButton with the JButton setFont() method.... but I don't know the coding for that...

Can you please help? Thanks in advance

JButton class inherits the setFont method of the JComponent class, you could use that. Check the API reference.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.