package Java_Review_Strings; // StringTokenizer class. import java.util.*; import java.awt.*; import java.awt.event.*; import javax.swing.*; public class IntegerOps extends JFrame { private JLabel promptLabel; private JTextField inputField; private JTextArea outputArea; // set up GUI and event handling public IntegerOps() { super( "Testing Class StringTokenizer" ); Container container = getContentPane(); container.setLayout( new FlowLayout() ); promptLabel = new JLabel( "Enter \"int operator int\" and press Enter" ); container.add( promptLabel ); inputField = new JTextField( 20 ); inputField.addActionListener( new ActionListener() { // anonymous inner class // handle text field event public void actionPerformed( ActionEvent event ) { StringTokenizer tokens = new StringTokenizer( event.getActionCommand()); int a = Integer.parseInt(tokens.nextToken()); String op = tokens.nextToken(); int b = Integer.parseInt(tokens.nextToken()); int c=0; if(op.equals("+")) c=a+b; else if(op.equals("-")) c=a-b; else if(op.equals("*")) c=a*b; else if(op.equals("/")) c=a/b; else if(op.equals("%")) c=a%b; outputArea.append( a + " " + op + " " + b + " = " + c + "\n" ); } } // end anonymous inner class ); // end call to addActionListener container.add( inputField ); outputArea = new JTextArea( 10, 20 ); outputArea.setEditable( false ); container.add( new JScrollPane( outputArea ) ); setSize( 275, 240 ); // set the window size setVisible( true ); // show the window } // execute application public static void main( String args[] ) { IntegerOps application = new IntegerOps(); application.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE ); } } // end class IntegerAddition