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

Edited by JuneM: add text

7 Years
Discussion Span
Last Post by verruckt24

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

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.