// Fig. 8.14: StringBufferChars.java // The charAt, setCharAt, getChars, and reverse methods // of class StringBuffer. import java.awt.Graphics; import java.applet.Applet; public class StringBufferChars extends Applet { StringBuffer buf; public void init() { buf = new StringBuffer( "hello there" ); } public void paint ( Graphics g ) { g.drawString( "buf = " + buf.toString(), 25, 25 ); g.drawString( "Character at 0: " + buf.charAt( 0 ), 25, 40 ); g.drawString( "Character at 4: " + buf.charAt( 4 ), 25, 55 ); char charArray[] = new char[ buf.length() ]; buf.getChars( 0, buf.length(), charArray, 0 ); g.drawString( "The characters are: ", 25, 85 ); g.drawChars( charArray, 0, charArray.length, 142, 85 ); buf.setCharAt( 0, 'H' ); buf.setCharAt( 6, 'T' ); g.drawString( "buf = " + buf.toString(), 25, 115 ); buf.reverse(); g.drawString( "buf = " + buf.toString(), 25, 145 ); } }