/* * [Gotcha.java] * * Summary: demonstrates pixel coordinate gotcha. * * Copyright: (c) 2005-2017 Roedy Green, Canadian Mind Products, http://mindprod.com * * Licence: This software may be copied and used freely for any purpose but military. * http://mindprod.com/contact/nonmil.html * * Requires: JDK 1.8+ * * Created with: JetBrains IntelliJ IDEA IDE http://www.jetbrains.com/idea/ * * Version History: * 1.0 2005-08-01 initial version */ package com.mindprod.pointsize; import com.mindprod.common18.VersionCheck; import java.applet.Applet; import java.awt.Color; import java.awt.Graphics; /** * demonstrates pixel coordinate gotcha. *

* Simple Applet to display coordinate problem. Run with width="100" height="100" * * @author Roedy Green, Canadian Mind Products * @version 1.0 2005-08-01 initial version * @since 2005-08-01 */ public final class Gotcha extends Applet { /** * Called by the browser or Applet viewer to inform * this Applet that it has been loaded into the system. */ public void init() { if ( !VersionCheck.isJavaVersionOK( 1, 8, 0, this ) ) { return; } // won't bleed through all the way to the browser background. this.setBackground( new Color( 0x00ffffff, true )/* transparent */ ); validate(); setVisible( true ); } /** * {@inheritDoc} */ public void paint( Graphics gr ) { gr.setColor( Color.white ); gr.fillRect( 0, 0, 200, 200 ); // actual region gr.setColor( Color.pink ); gr.fillRect( 40, 40, 100, 80 ); // theoretical region gr.setColor( Color.red ); gr.fillRect( 40, 40, 80, 60 ); // make grid gr.setColor( Color.blue ); for ( int i = 0; i < 200; i += 20 ) { gr.fillRect( i, 0, 1, 200 ); gr.fillRect( 0, i, 200, 1 ); } // x axis number grid gr.setColor( Color.black ); for ( int i = 0; i < 7; i++ ) { // x,y is bottom left corner of text gr.drawString( Integer.toString( i ), 40 - 3 + i * 20, 40 - 5 ); } // y axis number grid gr.setColor( Color.black ); for ( int i = 0; i < 6; i++ ) { gr.drawString( Integer.toString( i ), 40 - 10, 40 + 5 + i * 20 ); } } }