import java.applet.*; import java.awt.*; import java.awt.Graphics2D; // Used for anti-aliasing import java.awt.RenderingHints; // Used for anti-aliasing public class GraphicsDiceWithApplet extends Applet { public void paint(Graphics g) { // This line causes graphics and text to be rendered with anti-aliasing // turned on, making the overall display look smoother and cleaner ((Graphics2D) g).setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); setSize(314, 198); // Set the size of the applet window setBackground(Color.black); // Set the background color of the applet g.setColor(Color.white); // Set the color for the dice g.fillRect(60, 60, 75, 75); // Create die #1 g.fillRect(180, 60, 75, 75); // Create die #2 int valueDie1 = (int)(Math.random() * 6) + 1; // Choose a random die #1 value int valueDie2 = (int)(Math.random() * 6) + 1; // Choose a random die #2 value g.setColor(Color.red); // Set the color for the dice text g.setFont(new Font("Helvetica", Font.BOLD, 76)); // Set the dice text font and size g.drawString(Integer.toString(valueDie1), 75, 124); // Display the die #1 value g.drawString(Integer.toString(valueDie2), 195, 124); // Display the die #2 value } }