import java.awt.*; public class GraphicsDemo extends Frame { public void paint(Graphics g) { // Set the color of the graphics context g.setColor(Color.YELLOW); // Get the color of the graphics context Color c = g.getColor(); // Display the color on console System.out.println("Current Graphics Color: " + c); } public static void main(String args[]) { GraphicsDemo obj = new GraphicsDemo(); obj.setSize(300, 300); obj.setVisible(true); } }
Current Graphics Color: java.awt.Color[r=255,g=255,b=0]
import java.awt.*; public class GraphicsDemo extends Frame { public void paint(Graphics g) { // Set the color of the graphics context g.setColor(new Color(100, 200, 250)); // Get the color of the graphics context Color c = g.getColor(); // Display the color on console System.out.println("Current Graphics Color: " + c); } public static void main(String args[]) { GraphicsDemo obj = new GraphicsDemo(); obj.setSize(300, 300); obj.setVisible(true); } }
Current Graphics Color: java.awt.Color[r=100,g=200,b=250]