//HelloApplet2b.java //getWidth() and getHeight() and relative positioning import java.awt.*; import javax.swing.*; public class HelloApplet2b extends JApplet { //paint draws in the applet. //called automatically after init() and ***whenever window is uncovered or resized. public void paint( Graphics g ) { int width=getWidth(); //***current width of applet area int height=getHeight(); //***current height of applet area g.setColor( Color.GREEN ); g.fillOval( 0, 0, width/2, height/2 ); //half whatever the width and height are g.setColor( Color.MAGENTA ); g.fillOval( width/2, 0, width/2, height/2 ); g.setColor( Color.CYAN ); g.fillOval( 0, height/2, width/2, height/2 ); g.setColor( Color.YELLOW ); g.fillOval( width/2, height/2, width/2, height/2 ); g.setColor( Color.RED ); g.drawLine( 0, 0, width, height ); g.drawLine( width, 0, 0, height ); g.drawRect( 10, 10, width-20, height-20 ); g.drawOval( 0, 0, width-1, height-1 ); g.setColor( Color.BLUE ); g.setFont( new Font( "Serif", Font.BOLD, 16 ) ); g.drawString( "Hello world", width/2-20, height/2 ); } } /* "frame" fillrects. font size proportional to height. 200 size font 10x10 at 1/4, 3/4 combos */