//TwoInts.java //demo StringTokenizer to input 2 ints at once. import java.awt.*; import java.util.*; //StringTokenizer import javax.swing.*; public class TwoInts extends JApplet { public void init() { String input = JOptionPane.showInputDialog( "Enter row and column" ); StringTokenizer twoInts = new StringTokenizer(input); //any number of spaces before, between, after numbers OK. int row = Integer.parseInt(twoInts.nextToken()); int col = Integer.parseInt(twoInts.nextToken()); JOptionPane.showMessageDialog(null,"Row= "+row+" Column= "+col); } public void paint(Graphics g) { String s="here:is:a: bunch:of:words:separated by:colons!"; StringTokenizer st = new StringTokenizer(s,":"); //optional 2nd parameter is delimiter (default is space) int i=1; while (st.hasMoreTokens()) //iterate over the tokens g.drawString(st.nextToken(), 10, 20*i++); //each call of nextToken() gets the next token (word) } }