Download presentation
Presentation is loading. Please wait.
1
March 2005 1R. Smith - University of St Thomas - Minnesota QMCS 230: Today in Class AdministrativeAdministrative –Office Hours Today CANCELED –Project Schedule –This Week Schedule About the ExamAbout the Exam Graphical User Interface (GUI)Graphical User Interface (GUI) –See how far we get
2
March 2005 2R. Smith - University of St Thomas - Minnesota This Week Schedule Lecture/Lab TomorrowLecture/Lab Tomorrow Lab WednesdayLab Wednesday LABS DUELABS DUE –I will accept Lab 16 THIS WEEK Deduct from grade for being lateDeduct from grade for being late –Same with Lab 17 if not received tomorrow –Lab 18 due NEXT Tuesday
3
March 2005 3R. Smith - University of St Thomas - Minnesota Project Schedule Team and project THIS WEEKTeam and project THIS WEEK –Tell me next Monday –What you’re doing; who you’re working with “Design Memo” by December 3“Design Memo” by December 3 –What files/methods you will produce –What inputs and outputs will look like Final Project Due last day of classFinal Project Due last day of class
4
March 2005 4R. Smith - University of St Thomas - Minnesota About the Exam Total points = 114 = 100%Total points = 114 = 100% –No “real” extra credit –I reduced the point values of some problems Grades?Grades? –Class median: 89% –Percent = (114 – Missed) / 114 –Above 90% is an A, etc.
5
March 2005 5R. Smith - University of St Thomas - Minnesota Working through the answers #1 – People tended to forget “throws”#1 – People tended to forget “throws” –A few wrote headers for something not “main” #2 – It looks like a few people just guessed#2 – It looks like a few people just guessed –Prompting for the filename; FileWriter/PrintWriter for input #3, 4 – almost always right#3, 4 – almost always right #5 – Grammar#5 – Grammar #6-8 – forget return type, arg types, arg names#6-8 – forget return type, arg types, arg names –Extra argument for the return value #9 – Semicolon; double quotes; void#9 – Semicolon; double quotes; void –Mark ‘0’ as undefined; insist on arguments #10 – array; value passed to constructor#10 – array; value passed to constructor #12 – weird grammar#12 – weird grammar #13 – weird grammar; not a constructor#13 – weird grammar; not a constructor #14 – void; String type#14 – void; String type
6
March 2005 6R. Smith - University of St Thomas - Minnesota More answers #15 – writing a constructor method#15 – writing a constructor method –Car type = new Car(); // type becomes the variable name #16-8 – size on left hand side#16-8 – size on left hand side #17 – double for size value#17 – double for size value #18 – forgetting “”#18 – forgetting “” #19 – Just needed 0-4#19 – Just needed 0-4 #20 – Starting with 0#20 – Starting with 0 #21-23 – using ArrayList operations#21-23 – using ArrayList operations #21 – Backwards assignment (several)#21 – Backwards assignment (several) –Bad syntax, like an ‘add’ method #23 – using “==“ or = instead of.equals()#23 – using “==“ or = instead of.equals()
7
March 2005 7R. Smith - University of St Thomas - Minnesota GUIs – what we’ll do for ‘graphics’ Arranging windows with interface controlsArranging windows with interface controls Example: the bookshelf lab or carpet labExample: the bookshelf lab or carpet lab –Implement with fields to fill in and a “compute” button GUIs depend heavily on objectsGUIs depend heavily on objects –A historical thing –Xerox PARC developed the modern GUI –They used an OO language to do it
8
March 2005 8R. Smith - University of St Thomas - Minnesota Examples of GUI Objects A Window (type JFrame)A Window (type JFrame) –Dimensions –A Title –Visibility –“Close” operation (what to do when closing) Window Contents, including…Window Contents, including… Labels (type JLabel)Labels (type JLabel) –Contains settable text Text Field (type JTextField)Text Field (type JTextField) –Contains a readable text field Buttons (type JButton)Buttons (type JButton)
9
March 2005 9R. Smith - University of St Thomas - Minnesota Example GUI Objects Can you spot JWindow, JTextField, JLabel, JButton...Can you spot JWindow, JTextField, JLabel, JButton...
10
March 2005 10R. Smith - University of St Thomas - Minnesota Our Friend, JFrame What it has: dimensions, visibility, a title, actions, contents, etc.What it has: dimensions, visibility, a title, actions, contents, etc.
11
March 2005 11R. Smith - University of St Thomas - Minnesota Creating our own window Windows are objects, let’s create oneWindows are objects, let’s create one Import “javax.swing.*”Import “javax.swing.*” JFrame Win = new JFrame();JFrame Win = new JFrame(); Win.setTitle(“R. Smith’s Object Test Window”);Win.setTitle(“R. Smith’s Object Test Window”); Win.setSize(350, 250);Win.setSize(350, 250); Win.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE);Win.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE); Win.setVisible(true);Win.setVisible(true); Let’s try itLet’s try it
12
March 2005 12R. Smith - University of St Thomas - Minnesota To Create a Full GUI… We create customized Window objectsWe create customized Window objects We take JFrame and customize itWe take JFrame and customize it Customizing through inheritanceCustomizing through inheritance When we inherit, we get the existing object features, fields, and methodsWhen we inherit, we get the existing object features, fields, and methods We replace any we want, or add new onesWe replace any we want, or add new ones We get a “normal window” plus what we needWe get a “normal window” plus what we need
13
March 2005 13R. Smith - University of St Thomas - Minnesota Creating our own window object It’s an independent object – put in its own fileIt’s an independent object – put in its own file Imports “javax.swing.*”Imports “javax.swing.*” Class declaration “extends JFrame”Class declaration “extends JFrame” Custom Constructor creates the windowCustom Constructor creates the window –Title: setTitle(“R. Smith’s Object Test Window”); –Size: setSize(350, 250); –Close Button: setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE); –Visibility: setVisible(true); Let’s try itLet’s try it
14
March 2005 14R. Smith - University of St Thomas - Minnesota GUI from the book: KM converter Window Title Label Button Text Field Convert kilometers to milesConvert kilometers to miles
15
March 2005 15R. Smith - University of St Thomas - Minnesota Features Label describing what to doLabel describing what to do Text field for the amount to convertText field for the amount to convert Button to “run” the conversionButton to “run” the conversion Option: add a label to hold the answerOption: add a label to hold the answer For now, it won’t do anythingFor now, it won’t do anything
16
March 2005 16R. Smith - University of St Thomas - Minnesota Implementation We create a special “converter” window typeWe create a special “converter” window type We create objects for each GUI elementWe create objects for each GUI element We attach the objects to the window objectWe attach the objects to the window object
17
March 2005 17R. Smith - University of St Thomas - Minnesota Lab 18: GUI for bookshelf calculation Features of the GUIFeatures of the GUI A label describing how to use itA label describing how to use it Two text fields to collect the dataTwo text fields to collect the data A button to do the calculationA button to do the calculation Another label for outputs and error messagesAnother label for outputs and error messages
18
March 2005 18R. Smith - University of St Thomas - Minnesota That’s it. Questions?Questions? Creative Commons License This work is licensed under the Creative Commons Attribution-Share Alike 3.0 United States License. To view a copy of this license, visit http://creativecommons.org/licenses/by-sa/3.0/us/ or send a letter to Creative Commons, 171 Second Street, Suite 300, San Francisco, California, 94105, USA.
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.