This is a Java Program to Display String with Background Color as Cyan in a Frame
We have to write a program in Java such that it creates a frame with background color as cyan and a text with color red is written in the frame.
For displaying string with background color as cyan, we have the following set of input and output.
To Display the Frame :
On the execution of the program, it is expected that the frame has background color as cyan, and also displays the text "The Background of Frame is Cyan" in frame with red color.
1. Create the frame.
2. Set the background color of frame as cyan using setBackground(Color.CYAN).
3. Create a text with required font type and size.
4. Set the color of text to red using setForeground(Color.red).
5. Display the frame.
Here is source code of the Java Program to perform arithmetic operations. The program is successfully compiled and tested using javac compiler on Fedora 30. The program output is also shown below.
/*Java Program to Display Text with Background Color as Cyan*/
public static void main(String args)
//Create a frame
JFrame frame = new JFrame("Cyan Text");
//Write some text to the frame
String str="The Background of Frame is Cyan";
JLabel text = new JLabel(str);
//Set Background Color of Text as red
//Display the frame
1. To set the background color of frame, use the setBackground() function.
2. To set the foreground color of text, use the setForeground() function.
Here’s the run time test cases to display text with background color as cyan.
Sanfoundry Global Education & Learning Series – Java Programs.