Package com. beyole. util; import java. awt. color; import java. awt. dimension; import java. awt. font; import java. awt. point; import javax. swing. JFrame; import javax. swing. JLabel; public class test2 {public static void main (String [] args) {JFrame frame = new JFrame ("welcome to mldn "); // instantiate the window program JLabel label = new JLabel ("MLDN", JLabel. CENTER); // instantiate the object, use CENTER-aligned Font fnt = new Font ("Serief", Font. ITALIC, 28); label. setFont (fnt); label. setForeground (Color. red); frame. add (label); // add Dimension dimension = new Dimension () to the container; // instantiate dimensiondimension. setSize (); // you can specify the frame size. setSize (dimension); // sets the component size frame. setBackground (Color. white); // set the background color Point point = new Point (300,200); // set the displayed coordinate frame. setLocation (point); // set the frame position displayed in the form. setVisible (true); // display the component }}
To set the color and Font of a tag, first set the display Font of the tag, first create a Font object, and then use the setFont method of the tag to set the Font, and then use the setForeground method to set the color.
Program: