/* CIS 790 hwloop10.java PROF. AUCIELLO DIRECTIONS: DOWNLOAD AND PASTE THIS PROGRAM INTO AN EDITOR. COMPILE IT. MAKE IT RUN. ADD THE COMMENTS. 1 SECTION AT A TIME. MAKE IT RUN. ---> YOU MUST ADD THE COMMENTS, PRINT IT OUT. PUT IN YOUR NOTEBOOK. LATER TO YOUR WEBPAGE! GO! hack at this. put in your picture, your name. play w. colors. learn vertical, horizontal positioning. // hwloop.java follows: // SOURCE CODE BEGINS: // ============================================================ // step 1. define all library links. // step 2. define a class named 'hwloop' that extends and // inherits from java.applet.Applet class. // step 2.5 open bracket (brackets the class just defined.) //step 3. define all global variables. // define textfields, fonts, name field as string. // step 4. create an init() method // define a method called 'init' // step 4.a.0 // open bracket for init method. // Step 4a. Prompt for name. // define a new label. // add that label to the program. // define a text field. // add that text field to the program. // step 4b. // test for no (null) name // if no name, then use "Harvey" as a name. // step 4c. // end init method // end init method // step 5. define a paint method. // "paint" writes to the screen. // paint() method (displays output) // step 5.a.0 open bracket for 'paint' // step 5a. get an an image. Insert yours if possible. // 5b. set 36 point font. // 5c. set background to yellow. // 5d. set text to blue. // 5e. draw the image defined above at hor 400 and ver 65. // 5f. display the string "Hello, World" at hor 5, and ver 145. // 5g. take the name field from the input above, // concatenate (ask about this) it with "from" and "!" // and draw it at hor 5, ver 180. // 5h. set font to 24 point. // 5i. given. // bracket ending paint method // end of paint method // Step 6. start a method that "listens" when the "enter button" // is clicked. // It passes (2) arguments -- event and arg. given. public boolean action(Event event, Object arg) // 6.1 open bracket. // 6.2 command to "get text" and call it "name" // 6.3 repaint the screen. // 6.4 end the boolean function with a "return" true. // 6.5 end event-listening method. // 6.6 end of applet. // end event-listening method. // end of applet. // PLEASE TRY TO EXTEND THIS PROGRAM, ADD MUSIC, // CHANGE FONTS, COLOR, GRAPHICS. // POST THIS APPLET TO YOUR HOME PAGE. // SHOW ME WHAT YOU CAN DO. // ALSO, WE ARE TRYING TO OPERATE IN A 'LEARNING // COMMUNITY' MODE, A 'TEAM CONCEPT' MODE. // EACH OF US HAS UNIQUE SKILLS THAT ARE // STRENGTHENED WHEN SHARED. */ // ============================================================ // THIS PROGRAM WORKS ... TESTED WITH JDK122 ... FEB 10, 2001. JA. // PROGRAM STARTS BELOW: // step 1. define all library links. import java.applet.*; import java.applet.Applet; import java.awt.*; import java.awt.Color; // color import java.awt.event.*; import java.awt.Font; // font import java.awt.Graphics; // graphics library import java.awt.image.*; // req for images. import java.lang.Math; import java.util.Date; import java.util.Random; import java.util.*; // step 2. define a class named 'hwloop' that extends and // inherits from java.applet.Applet class. public class hwloop10 extends java.applet.Applet // declares class. { //step 3. define all global variables. TextField textField1; // define textfield1 Font ftr24 = new Font("TimesRoman", Font.ITALIC, 24); Font fss36 = new Font("Sans Serif", Font.BOLD, 36); // define Font String name; // step 4. create an init() method public void init() { // Step 4a. Prompt for name. Label namelabel1 = new Label(" Enter Your Name ",Label.RIGHT); add(namelabel1); textField1 = new TextField(15); add(textField1); // add textfield to structure if (name == null) name = "Harvey"; } // end init method public void paint(Graphics g) { // Step 5. paint() method (displays output) // step 5a. get an an image. Insert yours if possible. Image gifname270 = getImage(getDocumentBase(),"MONICA.GIF"); g.setFont(fss36); // setFont, part of the graphics 'library', // now 'linked' with the program. setBackground(Color.yellow); g.setColor(Color.blue); g.drawImage(gifname270, 400, 65, this); g.drawString ("Hello World", 5, 145); g.drawString ("from " + name + "! ",5,180); g.setFont(ftr24); g.drawString ("In blue on yellow at 36 points!", 5, 245); g.drawString ("Show Me What You Can Do!",300, 245); } // end of paint method // Step 6. "listen" when the "enter button" is clicked. public boolean action(Event event, Object arg) { name = textField1.getText(); // get name repaint(); return true; } // end event-listening method. } // end of applet.