CSCI A202 - Introduction to Programming (II)

Lecture 1: Getting Started (last updated Sat Jan 16)

Lecture One made a presentation of the course, collected initial student feedback and started with a simple BreezyGUI application. I will post a brief and working summary of it here soon. One could reliably use chapter 2 of the text as a reference for the lecture, in the meantime.

This is the general framework of the programs we'll be writing for now:

import java.awt.*;
import BreezyGUI.*;

public class NameOfProgram extends GBFrame {

  <define window objects>  

  <declare variables>  

  public void buttonClicked (Button buttonPushed) {

    <do what needs to be done when a button is pushed>

    // buttonPushed is a reference to the actual 
    // Button that caused this method to be called 
  } 

  public static void main(String[] args) {
    Frame f = new NameOfProgram(); 
    f.setSize(<width>, <height>); 
    f.setVisible(true); 
  }
} 
The file's name is: NameOfProgram.java

So a simple conversion program (HoursToMinutes.java) looks like this:

import java.awt.*;
import BreezyGUI.*;

public class HoursToMinutes extends GBFrame {

  Label         hoursLabel    = addLabel        ("Hours: " , 1, 1, 1, 1); 
  IntegerField  hoursField    = addIntegerField (         0, 1, 2, 1, 1); 
  Label         minuteLabel   = addLabel        ("Minutes:", 2, 1, 1, 1);
  IntegerField  minuteField   = addIntegerField (         0, 2, 2, 1, 1); 
  Button        convertButton = addButton       ("Convert" , 3, 1, 2, 1); 

  public void buttonClicked (Button buttonPushed) {
    minuteField.setNumber(60 * hoursField.getNumber()); 
  } 

  public static void main(String[] args) {
    Frame f = new HoursToMinutes(); 
    f.setSize(200, 300); 
    f.setVisible(true); 
  }
}