
1
CSI3471
Lab8:FaçadePattern
Revised10/23/2008
CopytheexistingEclipseprojectcalledLab8Facadefromthefileserver.Youwillbemodifyingit.Please
renameitasyouhavedoneinthepast,e.g.,L8Grabow.Whenyouarefinishedwiththelabplease
uploadittoyourSVNrepository.
YouwillbeaddingJavacodetodisplaythefollowingGUIframe,whichcanbeusedtoaddastudentto
anexistingsetofstudents.TheGUIusesasinglefaçadeobjecttodoalloftheworkassociatedwith
storingStudentobjects.Beforeyoubegin,lookattheexistingcodeinsideLab8Facade.
Step1:CreateaJFrameobjectandamainclass
CreateapackagecalledtextinputandcreateaclasscalledAddStudentFrame,containingthe
followingcode:
class AddStudentFrame extends JFrame {
public AddStudentFrame() {
setTitle("Add Student");
setSize(DEFAULT_WIDTH, DEFAULT_HEIGHT);
}
public static final int DEFAULT_WIDTH = 300;
public static final int DEFAULT_HEIGHT = 300;
}
Thiscode,however,isinadequatebecausethereisnothingtoinstantiateoneoftheseframes.Therefore,
createanotherclasscalledMainAddStudent,alsoinpackagetextinput,thatcontainsthefollowingcode:
public class MainAddStudent {
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
AddStudentFrame frame = new AddStudentFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
}