home *** CD-ROM | disk | FTP | other *** search
Java Source | 1997-02-07 | 3.3 KB | 148 lines |
- /*
- PC Plus Sample program.
- Java Loops
- */
-
- import java.awt.*;
-
- public class Frame1 extends Frame {
-
-
- void button1_Clicked(Event event) {
- // for loop
- list1.clear();
- for( int i = 1; i < 11; i++ )
- list1.addItem( "for loop: " + i );
- list1.addItem( "End of for Loop" );
- }
-
- void button2_Clicked(Event event) {
- // while loop
- int i = 1;
- list1.clear();
- while( i < 11 )
- list1.addItem( "while loop: " + i++ );
- list1.addItem( "End of while Loop" );
-
- }
-
- void button3_Clicked(Event event) {
- // do..while loop
- int i = 1;
- list1.clear();
- do
- list1.addItem( "do..while loop: " + i++ );
- while ( i < 11 );
- list1.addItem( "End of do..while Loop" );
-
- }
-
- void Open_Action(Event event) {
- //{{CONNECTION
- // Action from Open... Show the OpenFileDialog
- //}}
- }
-
- void About_Action(Event event) {
- //{{CONNECTION
- // Action from About Create and show as modal
- //}}
- }
-
- void Exit_Action(Event event) {
- //{{CONNECTION
- // Action from Exit Create and show as modal
- //}}
- }
-
- public Frame1() {
-
- //{{INIT_CONTROLS
- setLayout(null);
- addNotify();
- resize(insets().left + insets().right + 405,insets().top + insets().bottom + 305);
- list1 = new java.awt.List(0,false);
- add(list1);
- list1.reshape(insets().left + 12,insets().top + 12,378,175);
- button1 = new java.awt.Button("for loop");
- button1.reshape(insets().left + 24,insets().top + 204,102,46);
- add(button1);
- button2 = new java.awt.Button("while loop");
- button2.reshape(insets().left + 156,insets().top + 204,102,46);
- add(button2);
- button3 = new java.awt.Button("do..while loop");
- button3.reshape(insets().left + 276,insets().top + 204,102,46);
- add(button3);
- setTitle("A Basic Application");
- //}}
-
- //{{INIT_MENUS
- //}}
- }
-
- public Frame1(String title) {
- this();
- setTitle(title);
- }
-
- public synchronized void show() {
- move(50, 50);
- super.show();
- }
-
- public boolean handleEvent(Event event) {
- if (event.id == Event.WINDOW_DESTROY) {
- hide(); // hide the Frame
- dispose(); // free the system resources
- System.exit(0); // close the application
- return true;
- }
- if (event.target == button1 && event.id == Event.ACTION_EVENT) {
- button1_Clicked(event);
- return true;
- }
- if (event.target == button2 && event.id == Event.ACTION_EVENT) {
- button2_Clicked(event);
- return true;
- }
- if (event.target == button3 && event.id == Event.ACTION_EVENT) {
- button3_Clicked(event);
- return true;
- }
- return super.handleEvent(event);
- }
-
- public boolean action(Event event, Object arg) {
- if (event.target instanceof MenuItem) {
- String label = (String) arg;
- if (label.equalsIgnoreCase("Open...")) {
- Open_Action(event);
- return true;
- } else
- if (label.equalsIgnoreCase("About")) {
- About_Action(event);
- return true;
- } else
- if (label.equalsIgnoreCase("Exit")) {
- Exit_Action(event);
- return true;
- }
- }
- return super.action(event, arg);
- }
-
- static public void main(String args[]) {
- (new Frame1()).show();
- }
-
- //{{DECLARE_CONTROLS
- java.awt.List list1;
- java.awt.Button button1;
- java.awt.Button button2;
- java.awt.Button button3;
- //}}
-
- //{{DECLARE_MENUS
- //}}
- }
-