// Simple while loop example import java.applet.*; import java.awt.*; import java.awt.event.*; public class Loop1 extends Applet implements ActionListener { Label title = new Label("Loop Example"); // Input panel. Panel inputP = new Panel(new GridLayout(1, 2)); Label inputL = new Label("Enter termination value:"); TextField input = new TextField(15); Button enter = new Button("Enter"); public void init() { setLayout(new GridLayout(3, 1)); add(title); add(inputP); inputP.add(inputL); inputP.add(input); add(enter); enter.addActionListener(this); setSize(275,100); } // actionPerformed handles button presses. It is executed whenever // the enter button is pressed. public void actionPerformed(ActionEvent e) { int inputI; // Read the input integer. inputI = Integer.parseInt(input.getText()); // Print a count from 0 to inputI int count = 0; while (count <= inputI) { System.out.println(count); count++; } } }