This is a Java Program to Check Whether Antialiasing is Enabled or Not
We have to write a program in Java such that it checks whether the antialiasing is enabled or not
For checking whether antialiasing is enabled or not, we can have the following sets of input and output.
1. When Antialiasing is Enabled :
If antialiasing is enabled, it is expected that the message "Antialiasing is Enabled" is displayed.
2. When Antialiasing is Disabled :
If antialiasing is disabled, it is expected that the message "Antialiasing is Disabled" is displayed.
1. Create a label with appropriate dimensions for the output message.
2. Convert the graphics object to Graphics2D type explicitly.
3. Create an object of class RenderingHints and get the attributes associated with the Graphics2D object.
4. Antialiasing is enabled if the object contains the value VALUE_ANTIALIAS_ON.
5. Display message accordingly.
Here is source code of the Java Program to check whether antialiasing is enabled or not. The program is successfully compiled and tested using javac compiler on Fedora 30. The program output is also shown below.
/* Java Program to Check Whether Antialiasing is Enabled or Not */
public class Antialiasing extends Applet
//Create the label
public void init()
text = new Label();
//Function to check if antialiasing is enabled or not
public void paint(Graphics g)
Graphics2D G = (Graphics2D)g;
RenderingHints rh = G.getRenderingHints();
text.setText("Antialiasing is Enabled");
text.setText("Antialiasing is Disabled");
<applet code = Antialiasing.class width=400 height=400>
To compile an execute the program use the following commands :
>>>javac Antialiasing.java >>>appletviewer Antialiasing.java
1. Explicitly type cast the object of Graphics class to Graphics2D type.
2. Use method getRenderingHints() to get the attributes of the Graphics2D object.
3. Use method containsValue(parameter) to check is the object contains the parameter. To check if antialiasing is enabled, the parameter is RenderingHints.VALUE_ANTIALIAS_ON.
Here’s the run time test cases for checking whether antialiasing is enabled or not for different input cases.
Sanfoundry Global Education & Learning Series – Java Programs.Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our social networks below and stay updated with latest contests, videos, internships and jobs!