CompSci 280 S Introduction to Software Development

Slides:



Advertisements
Similar presentations
Unit 3 Graphical User Interface (GUI) Dr. Magdi AMER.
Advertisements

Graphic User Interfaces Layout Managers Event Handling.
F27SB2 Programming Languages
Introduction to Java Classes, events, GUI’s. Understand: How to use TextPad How to define a class or object How to create a GUI interface How event-driven.
Java Swing Recitation – 11/(20,21)/2008 CS 180 Department of Computer Science, Purdue University.
Chapter 6 Graphical User Interface (GUI) and Object-Oriented Design (OOD)
Swing CS-328 Dick Steflik John Margulies. Swing vs AWT AWT is Java’s original set of classes for building GUIs Uses peer components of the OS; heavyweight.
Chapter 13: Advanced GUIs and Graphics J ava P rogramming: From Problem Analysis to Program Design, From Problem Analysis to Program Design, Second Edition.
1 Class 8. 2 Chapter Objectives Use Swing components to build the GUI for a Swing program Implement an ActionListener to handle events Add interface components.
PROGRAMMING REVIEW Lab 2 EECS 448 Dr Fengjun Li and Meenakshi Mishra.
Chapter 13 Advanced GUIs and Graphics. Chapter Objectives Learn about applets Explore the class Graphics Learn about the class Font Explore the class.
Java Programming: From Problem Analysis to Program Design, 4e Chapter 12 Advanced GUIs and Graphics.
MVC and Swing IAT 351 Week 7 Lecture/tutorial Lyn Bartram.
Applets and Frames CS 21a: Introduction to Computing I First Semester,
Object Oriented Programming Ders 11: Interfaces Mustafa Emre İlal
MIT AITI 2003 Lecture 17. Swing - Part II. The Java Event Model Up until now, we have focused on GUI's to present information (with one exception) Up.
1 Event Driven Programs Rick Mercer. 2 So what happens next?  You can layout a real pretty GUI  You can click on buttons, enter text into a text field,
Week 7. Lecture 2 Functions, Arrays, PHP&MySQL. Function with More than one argument and a return statement For a function to return a value, the return.
GUI Components and Design Here we add one more component to our programs, JButtons –JButtons can only be inserted into JPanels (or JApplets) –Clicking.
Java Event Handling CSIS 3701: Advanced Object Oriented Programming.
GUIs in Java Swing, Events CS2110, SW Development Methods Readings: MSD, Chapter 12 Lab Exercise.
Graphic User Interface. Graphic User Interface (GUI) Most of us interact with computers using GUIs. GUIs are visual representations of the actions you.
Course ILT Forms and queries Unit objectives Create forms by using AutoForm and the Form Wizard, and add or modify form headers and footers Open and enter.
Chapter 10 Function Block Diagram
Applets and Frames. Copyright 2005, by the authors of these slides, and Ateneo de Manila University. All rights reserved L14: GUI Slide 2 Applets Usually.
1 / 67 COP 3503 FALL 2012 SHAYAN JAVED LECTURE 14 Programming Fundamentals using Java 1.
CS-1020 Dr. Mark L. Hornick 1 Event-Driven Programming.
Introduction to GUI in 1 Graphical User Interface 2 Nouf Almunyif.
Ajmer Singh PGT(IP) JAVA IDE Programming - I. Ajmer Singh PGT(IP) GUI (Graphical User Interface) It is an interface that uses a graphic entities along.
Java Programming, Second Edition Chapter Thirteen Understanding Swing Components.
1 Event Driven Programs with a Graphical User Interface Rick Mercer.
JAVA: An Introduction to Problem Solving & Programming, 6 th Ed. By Walter Savitch ISBN © 2012 Pearson Education, Inc., Upper Saddle River,
1 Event Driven Programs Rick Mercer. 2 So what happens next?  You can layout a real pretty GUI  You can click on buttons, enter text into a text field,
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Outline 17.1 Test-Driving the Student Grades Application.
Chapter 10 - Writing Graphical User Interfaces1 Chapter 10 Writing Graphical User Interfaces.
Swing GUI Components So far, we have written GUI applications which can ‘ draw ’. These applications are simple, yet typical of all Java GUI applications.
Graphical User Interface (GUI)
Notes for Assignment #2 Assn2: GUI Database Interface Corresponds with Chapters 28, 29, 31.
5-1 GUIs and Events Rick Mercer. 5-2 Event-Driven Programming with Graphical user Interfaces  Most applications have graphical user interfaces to respond.
1 A Quick Java Swing Tutorial. 2 Introduction Swing – A set of GUI classes –Part of the Java's standard library –Much better than the previous library:
Java Programming Fifth Edition Chapter 13 Introduction to Swing Components.
GUIs & Event-Driven Programming Chapter 11 Review.
Java Visual Applications CSIS 3701: Advanced Object Oriented Programming.
©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Chapter Chapter 7 ( Book Chapter 14) GUI and Event-Driven Programming.
COM621: Advanced Interactive Web Development Lecture 10 PHP and MySQL.
Client-side (JavaScript) Validation. Associating a function with a click event – Part 1 Use the input tag’s onclick attribute to associate a function.
Object-Oriented Software Engineering
JSP and DB.
A Quick Java Swing Tutorial
GUIs and Events Rick Mercer.
Introduction Many Java application use a graphical user interface or GUI (pronounced “gooey”). A GUI is a graphical window or windows that provide interaction.
CompSci 230 S Programming Techniques
Christopher Budo, Davis Nygren, spencer franks, Luke miller
A First Look at GUI Applications
“Form Ever Follows Function” Louis Henri Sullivan
Graphical User Interface (pronounced "gooey")
Lecture 27 Creating Custom GUIs
CompSci 280 S Introduction to Software Development
A Quick Java Swing Tutorial
Ellen Walker Hiram College
Chapter 13: Advanced GUIs and Graphics
PC02 Term 1 Project Basic Messenger. PC02 Term 1 Project Basic Messenger.
Introduction to Event Handling
Super Market Management
A Quick Java Swing Tutorial
Constructors, GUI’s(Using Swing) and ActionListner
Chapter 5 Processing Input with Applets
CiS 260: App Dev I Chapter 6: GUI and OOD.
Advanced GUIs and Graphics
Graphical User Interface
Presentation transcript:

CompSci 280 S2 2107 Introduction to Software Development Assignment 3 Help

Today’s Agenda Topics: Part 1: Part 2: Part 3: Updating the books table Insert some more records Part 2: Search by title Display book details Part 3: Black box testing – after the term break A3

Part 1 [20 marks] Step 1: Step 2: Drop table? Update table? Add a status column (“On Loan”, “Available”, “Reserve”…) Step 2: Insert 10 records into the BOOKS table You can use phpMyAdmin to make the above changes. Submission Make a screenshot to show the structure of the table [12marks] Make a screenshot to show the records in the table [4 marks] Make a screenshot or type to show your username, password, url for our markers to run your program [4 marks] A3

Part 2: Implementation [50 marks] Choose your language: Java/Python! Download the corresponding template from Canvas Design your program’s user interface: Text box & button only? Do you want to use table? Or menu, combo box or list box etc? Note: If you implement the program using textboxes and buttons only. The maximum mark you can get is 30/50. SQL statements: Identify the SQL statement to search by a title Identify the SQL statement to display a book’s details A3

Marking scheme: 2.1 Documentation inside the Code: Presence of comments and overall programming style (good variable names, method names; Good indentation. Good structure) [5 marks] 2.2 Connection: Users should be able to connect to the MySql Server database and display 10 records A3

Marking scheme: Part 1: Searching by title Part 2: Searching by ID 2.3.1 Users should be able to search by entering a title pressing <ENTER> or clicking the search button 2.3.2 A result list is displayed using a simple GUI component [5 marks] () using a table [15 marks] Part 2: Searching by ID 2.4.1 Users should be able to view a book’s details. by entering a Book_ID [5 marks] () by selecting a row in a table control [15 marks] 2.4.2 The book’s details is displayed. A3

Java Template Complete the Book class Complete BookTableModel Complete all constructors Complete BookTableModel Constructor, getValueAt, populateTable, getCurrentBook Complete the A3 main program Complete user, pass, url etc Create GUI components and add them to the content pane Complete the event handlings Title Textfield Search button JTable - selection A3

Part 2: Implementation Java - GUI Work on the GUI component JLabel, JTextField, JTextArea, JScrollPane Layout Managers: FlowLayout, BorderLayout Create the required GUI components Add them either to a JPanel or the content pane of the Jframe For JTable: Create a bookTableModel Add the bookTableModel to a JTable Add the JTable to the scrollpane topPanel.add(titleTextField); pane.add(content, BorderLayout.PAGE_END); bookTableModel = new BookTableModel(JDBC_DRIVER,URL, USER, PASS ); Alternately, you can display the result list in a JTextArea and create a textbox for users to enter a BOOKID to check the book’s details bookTable = new JTable(bookTableModel); bookTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); ... A3

Part 2: Implementation Java – Event Handling Title Search: Add an event handler to the search button and the title text field Get the title (getText()) Populate the bookTableModel to display the result list searchButton.addActionListener(new ActionListener() { // This method is invoked when the user hits ENTER in the field public void actionPerformed(ActionEvent e) { bookTableModel.populateTable(...); bookTableModel.fireTableDataChanged(); } }); A3

Part 2: Implementation Java – Event Handling Book’s details (using a JTable) Add an event handler to the JTable Get the book Display the result (setText) Alternately, you can use a textfield and button to get the book’s details Add an event handler to the details button Get the ID Display the result bookTable.getSelectionModel().addListSelectionListener(new ListSelectionListener(){ public void valueChanged(ListSelectionEvent event) { //get the selected book and display the details }); } A3

Part 2: Implementation Java – Table Model Create a new table model: BookTableModel extends AbstractTableModel Attributes: ArrayList<Book>, rows (number of rows), cols (number of cols), String[] columnName, Connection conn Create a constructor Parameters: driver, url, username, password Set up a connection object populateTable(“”) <= select * from BOOKS; Implement the required methods: getValueAt(int row, int col), [getRowCount, getColumnCount, getColumnName] isCellEditable return false Implement the following methods: populateTable(title): populate the table model using the search by title SQL statement getCurrentBook(rowIndex): return a book using the search by id SQL statement done A3

Part 2: Implementation Java – Table Model ID Title Author Data: an ArrayList of Books Methods: populateTable(title) Execute the SQL statement Get data from the result set and create a new book using id, title and author Add the newly created book into the ArrayList getCurrentBook(int row) Get the book_id based on the row index Get data from the result set and create a new book using id, title, author… return the book while (rs.next()) { ... rs.getInt(1)... rs.getString(2)...rs.getString(3) ... } A3

Part 2: Implementation Java – Table Model ID Title Author Methods: getRowCount : returns the number of rows Number of elements in the ArrayList getColumnCount: returns the number of cols (i.e. 3) getValueAt(int row, int col) return the corresponding info Get the book based on the row number Col: 0 – return id by the rowth book Col: 1 – return title … Col: 2 – return author A3

Python Template Complete MyTableModel Complete the A3 main program Constructor, data, populateTable, getCurrentBook Complete the A3 main program Complete user, pass, url etc Create GUI components and add them to the content pane Complete the event handlings Search button table - selection A3

Part 2: Implementation Python - GUI topLayout = QHBoxLayout() topLayout.addWidget(enterLabel)); Work on the GUI component QLineEdit(), QPushButton(), QTextEdit() Layout: QHBoxLayout(), QGridLayout() Create the GUI components Add them to the layout For QTableView: Create a bookTableModel Set the dataModel self.tablemodel = MyTableModel(my_host, my_database, my_user, my_password, self) self.tableview.setModel(self.tablemodel) self.tableview.setSelectionMode(QAbstractItemView.SingleSelection) self.tableview.setSelectionBehavior(QAbstractItemView.SelectRows) A3

Part 2: Implementation Python – Event Handling Set the method Title Search: Add an event handler to the search button and the title text field Get the title (.text()) Populate the bookTableModel to display the result list searchButton.clicked.connect(self.populateTable) def populateTable(self): #get the title from the text field #update the table model ... A3

Part 2: Implementation Python – Event Handling Book’s details (using a QTableView) Add an event handler to the table Get the book/row (index.row()) Display the details Alternately, you can use a text field and button to get the book’s details Add an event handler to the details button Get the ID self.tableview.clicked.connect(self.selectRow) def selectRow(self, index): result = self.tablemodel.populateDetails(index.row()) ... A3

Part 2: Implementation Python – Table Model Create a new table model: class MyTableModel(QAbstractTableModel): header_labels = ["ID", "Title", "Author"] Create a constructor Set up a connection, cursor, self.arraydata = … Implement the required methods: data only, ( headerData, rowCount, columnCount ) <=completed Implement the following methods: populateTable(self, search_title): update the table model using the search by title SQL statement populateDetails(self, row_index): return the book’s details using the search by id SQL statement def __init__(self, my_host, my_database, my_user, my_password, parent=None, *args): QAbstractTableModel.__init__(self, parent, *args) A3

Part 2: Implementation Python – Table Model ID Title Author Data: arraydata: a sequence of sequences Methods: populateTable(self, search_title) Execute the SQL statement get data from the result set and update the self.arraydata populateDetails(self, row_index): Get the book_id based on the row index (arraydata[ ][0]) return the corresponding info self.layoutAboutToBeChanged.emit() self.arraydata = ... self.layoutChanged.emit() A3

Part 2: Implementation Java – Table Model ID Title Author Methods: rowCount: returns the number of rows in arraydata columnCount: returns the number of cols data(self, index, role): return the corresponding information based on the row index and col index headerData(self, section, orientation, role=Qt.DisplayRole): Return the column name if not index.isValid(): return QVariant() elif role != Qt.DisplayRole: return QVariant(self... ) if role == Qt.DisplayRole and orientation == Qt.Horizontal: return self.header_labels[section] return QAbstractTableModel.headerData(self, section, orientation, role) A3