/* Name: Chris Johnson johnson@dcs.gla.ac.uk Last modified: 4/1/99 Description: This applet lays out the labels for a timetable. It forms part of exercise 2 from the user interface design in Java course on: http://www.dcs.gla.ac.uk/~johnson/teaching/hci-java It uses the NewGridBagLayout class designed by G.W. Rouse in An Introduction to Data Structures and Algorithms with Java, Prentice Hall, Hemel Hemstead, 1998. pp 65-78. The details of this class will be introduced in later practicals - it provides a useful means of minimising the initial complexity in developing an AWT interface. */ import java.applet.Applet; // you should have met this before import java.awt.*; // link to the AWT classes import NewGridBagLayout; // we will learn more about layout managers in later practicals public class TimetableLabels extends Applet { // panels are components that can contain other components, such as labels. // we will use a panel to contain the labels that make up the timetable. private Panel timetable = new Panel(); // The following lines provide access to a customised layout manager. This provides // a quick means of placing labels in particular positions on the screen. NewGridBagLayout layout = new NewGridBagLayout(); public void init() { timetable.setLayout(layout); // set up the layout manager Label Time_0900 = new Label("09.00"); // create new labels Label Time_1000 = new Label("10.00"); Label Time_1100 = new Label("11.00"); Label Time_1200 = new Label("12.00"); Label Time_1300 = new Label("13.00"); Label Time_1400 = new Label("14.00"); Label Time_1500 = new Label("15.00"); Label Time_1600 = new Label("16.00"); Label Time_1700 = new Label("17.00"); Label Monday = new Label("Monday"); Label Tuesday = new Label("Tuesday"); Label Wednesday = new Label("Wednesday"); Label Thursday = new Label("Thursday"); Label Friday = new Label("Friday"); //These calls add the labels at appropriate places on the screen. //The first parameter is the name of the label component to be added eg Time_0900 //The second parameter is the panel component that holds all of the label components //The third and fourth parameters sets the X and Y coordinates of the label // The fifth and sixth parameters sets width and height of the label layout.setPositionSizeAdd(Time_0900, timetable, 1, 1, 1, 1); layout.setPositionSizeAdd(Time_1000, timetable, 2, 1, 1, 1); layout.setPositionSizeAdd(Time_1100, timetable, 3, 1, 1, 1); layout.setPositionSizeAdd(Time_1200, timetable, 4, 1, 1, 1); layout.setPositionSizeAdd(Time_1300, timetable, 5, 1, 1, 1); layout.setPositionSizeAdd(Time_1400, timetable, 6, 1, 1, 1); layout.setPositionSizeAdd(Time_1500, timetable, 7, 1, 1, 1); layout.setPositionSizeAdd(Time_1600, timetable, 8, 1, 1, 1); layout.setPositionSizeAdd(Time_1700, timetable, 9, 1, 1, 1); layout.setPositionSizeAdd(Monday, timetable, 0, 3, 1, 1); layout.setPositionSizeAdd(Tuesday, timetable, 0, 4, 1, 1); layout.setPositionSizeAdd(Wednesday,timetable, 0, 5, 1, 1); layout.setPositionSizeAdd(Thursday, timetable, 0, 6, 1, 1); layout.setPositionSizeAdd(Friday, timetable, 0, 7, 1, 1); add(timetable); validate(); } }