123 Comp Sci      
notes labs assignments calendar

Lab 1

LAB 1 #2

Run the following program:

import java.awt.Color;
import javax.swing.JFrame;
import javax.swing.JText Field;
 
public class FrameTester
{
   public static void main(String[] args)
   {
      JFrame frame = new JFrame();
      frame.setSize(200, 200);
      JTextField text = new JTextFi eld ("Hello, World!");
      text.setBackg round(Color.PINK);
      frame.add(text);
      frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
      frame.setVisible(true);
 
   }
}

 

Modify the program as follows:

 

·  

Double the frame size

·  

Change the greeting to “Hello, your name!”

·  

Change the background color to pale green

 

LAB 1 #3

The GregorianCalendar class describes a point in time, as measured by the Gregorian calendar, the standard calendar that is commonly used throughout the world today. You construct a GregorianCalendar object from a year, month, and day of the month, like this:

GregorianCalendar cal = new GregorianCalendar(); // Today's date
GregorianCalendar eckertsBirthday = new GregorianCalendar(1919,
      Calendar.APRIL, 9);

Use constants Calendar.JANUARY . . . Calendar.DECEMBER to specify the month.

 

The add method can be used to add a number of days to a GregorianCalendar object:

cal.add(Calendar.DAY_OF_MONTH, 10); // Now cal is ten days from today

This is a mutator method—it changes the cal object.

 

The get method can be used to query a given GregorianCalendar object:

int dayOfMonth = cal.get(Calendar.DAY_OF_MONTH);
int month = cal.get(Calendar.MONTH);
int year = cal.get(Calendar.YEAR);
int weekday = cal.get(Calendar.DAY_OF_WEEK);
   // 1 is Sunday, 2 is Monday, ..., 7 is Saturday

Your task is to write a program that prints the following information:

 

·  

The date and weekday that is 100 days from today

·  

The weekday of your birthday

·  

The date that is 10,000 days from your birthday

Use the birthday of a computer scientist if you don't want to reveal your own birthday.