CS 100, Summer 2001 Wednesday, 7/25 Lecture 16 ----------------------------------------------------------------------- Announcements: + Extension: Project 1 due 7/27 + Exercise 11 due today! + Pick up graded Exercise 10 + reading: Savitch 7.1, 7.2 (p. 469-471) ----------------------------------------------------------------------- Topics: + GUIs + Swing + Inheritance ---------------------------------------------------------------------- ---------------------------------------------------------------------- + Project 1 - You do not have to preserve case in the output. This is now going to be a bonus point. - Documentation: see newsgroup post. - Formating your output: for encrypted text, it should be PRECISELY the same as our output. For frequency analysis, just make sure you have the rows and columns in the right order with the right numbers in the entries. If you have extra digits after the decimal place, that's okay. - Checking for duplicates in the substitution string: Hint: double loop, count how many of each letter; If any of these are > 1, you can exit with an error message. - Extra '?' at the end of encrypted output? Remember that .read() returns -1 at EOF and you should NOT be encrypting this value. - Submission: Put "None" as your partner if you're working alone ---------------------------------------------------------------------- ---------------------------------------------------------------------- + GUI: graphical user interface - gets information from the user and gives it to the program - uses windows, menus, buttons + Event-driven programming - examples: clicking the mouse, dragging the mouse, pressing a key - to create GUIs, we'll write event handlers (methods that "handle" these events) - flow of control is now a bit different - doesn't happen all in one place (like main() ), nor do you control when and how the methods get called. Instead, you write code that can respond to events as they happen. - In fact, you may NEVER call some of the methods you define. This is like what we saw before with paint() (you don't call it, the computer does. You just specify what should happen when it is called.) ---------------------------------------------------------------------- ---------------------------------------------------------------------- + Window: has border, edges, and title - creating windows: see FirstWindow.java, FirstWindowDemo.java - WindowDestroyer class (from Savitch) (window listener) - how closing the window works: 1. user clicks on "x" button 2. window fires an event that the listener gets 3. listener closes the window and ends the program System.exit(0) means normal termination; System.exit(1) means an error happened + WindowAdapter class: many methods you can "extend" or "redefine" (More on this when we get to inheritance..) + pixels: recap: integer coordinates + setVisible: needed so you can hide/show the window at will + "extends JFrame": we'll explain this when we get to inheritance, too. For now it just means that the graphics program you are writing gets access to a bunch of other useful graphics stuff that you don't have to write yourself. Also, ignore "super();" for now. + initialization of the GUI should happen in the class constructor. ---------------------------------------------------------------------- ---------------------------------------------------------------------- + Useful window stuff (remember SpaceshipImage.java?) - setTitle(String); - setBackground(Color); - see p. 782 for more + Layout managers - keep track of where items go in the GUI - BorderLayout: You can tell it to put things NORTH, SOUTH, EAST, WEST, or CENTER - EXAMPLE: BorderLayoutDemo.java - Also, other predefined managers: - FlowLayout: left to right - GridLayout: rows and columns, each entry the same size ---------------------------------------------------------------------- ---------------------------------------------------------------------- + Swing elements - JLabel (text label) - JButton (clickable button) See ButtonDemo.java - JPanel (panel to hold other things ("container class")) - JTextArea/JTextField (to get input text) See MemoSaver.java - JMenuBar/JMenuItem + Action Listeners ("implements ActionListener") - actionPerformed(ActionEvent e) method - checks what the action was, then does appropriate things + GUI tips: p. 809 ---------------------------------------------------------------------- ---------------------------------------------------------------------- + Inheritance - Tree: subtypes (subclasses): Conifer, Deciduous - Exception: IOException: FileNotFoundException ---------------------------------------------------------------------- ---------------------------------------------------------------------- PICK UP graded Exercise 10 hand in your Exercise 11!