Monday June 12, 2000


Last week we looked at a simple example of a Hello World program using a DOS Editor. Today we will look at three other versions of this program using JBuilder.

Version 1 - DOS Based with JBuilder

  1. Click on the JBuilder2 icon.

  2. Close the project that immediately opens.

  3. Click on File, then New (not New Project) and then on Class.

  4. Click the Finish Button that appears on the pop up screen.

  5. On the next screen that pops up uncheck "Generate parameterless Constructor" and check "Generate main function". Then click OK.

  6. Delete the lines that start with private, myClass1 and MyClass1 with CTRL-Y.

  7. After the line with main in it add the line System.out.println("Hello World");

  8. Click the leftmost Lightning Bolt to run the program.

  9. Notice that it goes by too fast for us to see.

  10. At the beginning of the program type the line import USA.*;

  11. After the System.out.println statement type the line USA.pause();

Version 2 - Windows Based using a Label

  1. Click on the JBuilder icon.

  2. Close the project that immediately opens.

  3. Click on File, then New (not New Project) and then on Class.

  4. Click on the Finish Button that appears on the pop up screen.

  5. Click on the Next Button that appears on the pop-up screen (not Finish).

  6. On the next screen that pops up, check the "Center on Screen" box and then click the Finish Button.

  7. In the upper left-hand corner click on "Frame1.java", and then click on the "Design" tab on the bottom of the code window.

  8. On the Component Palette across the top click on the AWT tab.

  9. Click on the "A" icon on that bar.

  10. Move the cursor to the Middle of the Frame1 and click there.

  11. Click on the "text" field of the properties shown on the right-hand side of the screen. When the cursor is in there replace the phrase "label1" with "Hello World".

  12. Double click in the field to the right of "font" and then click on the three dots.

  13. In the pop up screen set the Font to Times Roman and the size to 36. Then click OK.

  14. Double click on the field to the right of foreground and then on the three dots.

  15. In the window that pops up play with the three slider bars to get a cool color, and then click on OK.

  16. Now click on the leftmost lightning bolt to run the program. Note that like any standard window you can drag it, stretch it, minimize it, or use X to close it.

Version 4 - Windows Based using a Button and TextArea

Continue after Version 3, in the Design mode click on your Hello World label and then hit the Delete Key. Of if you prefer, start over again and repeat steps 1 to 8 from Version 3.

  1. On the Component Palette across the top click on the AWT tab.

  2. Click on the OK button icon on that bar.

  3. Move the cursor to the Top area of Frame 1 and click there. Stretch the button.

  4. Double click on the field to the right of the word "label" on the properties shown on the right-hand side of the screen. When the cursor is in there replace the phrase "button1" with "Go".

  5. On the AWT component palette click on the TextArea icon: second from the right end.

  6. Then click and drag on Frame1 under the button that we added. Slide and resise the TextArea to go from side to side and fill most of the area in the frame under the button.

  7. Double click in the field to the right of "text" and replace "textarea1" with blanks.

  8. Click on your Go-button. When it is selected then click on the "Events" tab at the bottom of the property Inspector on the right-hand side of the screen.

  9. Double-click on the field to the right of "ActionPerformed" (top entry), and then double click there again. This should take you back to using the center area of the screen for "Source Code" (Note tab on bottom). You are now in the area where one enters the code to be executed when the button gets clicked.

  10. At that point type in: textArea1.append("Hello World" + '\n');

  11. Now click on the leftmost lightning bolt. When the program runs click your button a bunch of times. Note that you can scroll through that output area.
Now you can experiment with typing in this program in JBuilder and running it. Make sure you save it in a file called DecimaltoBinary.java.
import USA.*;

public class DecimaltoBinary {
   int original;

   public DecimaltoBinary(int decimal) {
      original = decimal;
   }

   public void convert() {
      int quotient;
      int remainder = 0;

      int num = (int)(Math.log(original)/Math.log(2));

      while (num>=1) {
         quotient = (int)(original/Math.pow(2,num));
         remainder = (int)(original - quotient*Math.pow(2,num));
         System.out.println(quotient);
         original -= quotient*Math.pow(2,num);
         num--;
      }
     
      System.out.println(remainder);
      USA.pause();      
   }

   public static void main(String[] args) {
      DecimaltoBinary myConverter = new DecimaltoBinary(32);
      myConverter.convert();
   }
}