Presentation is loading. Please wait.

Presentation is loading. Please wait.

CSSE221: Software Dev. Honors Day 8 Announcements Announcements HW3 due now, solutions will be posted. HW3 due now, solutions will be posted. Questions.

Similar presentations


Presentation on theme: "CSSE221: Software Dev. Honors Day 8 Announcements Announcements HW3 due now, solutions will be posted. HW3 due now, solutions will be posted. Questions."— Presentation transcript:

1 CSSE221: Software Dev. Honors Day 8 Announcements Announcements HW3 due now, solutions will be posted. HW3 due now, solutions will be posted. Questions on Arrays? Questions on Arrays? Max # of elements in an array: Max # of elements in an array: Integer.MAX_INT, but your machine probably doesn’t have enough space to hold this much data! And the JVM will certainly not claim all your memory even if you did. Integer.MAX_INT, but your machine probably doesn’t have enough space to hold this much data! And the JVM will certainly not claim all your memory even if you did. Newer machines (with 64-bit addressing) will have more… but I don’t know how Java is responding (perhaps Java 7 will have long int array indices) Newer machines (with 64-bit addressing) will have more… but I don’t know how Java is responding (perhaps Java 7 will have long int array indices) Today is Constitution Day. Today is Constitution Day. Speaker in Kahn Room in Union, 10 th hour. Speaker in Kahn Room in Union, 10 th hour. No baby yet… No baby yet…

2 Capsule Deliverables: sec 1 Please email the quiz, key, and summary to me by 7:30 am on the day you are presenting. Please email the quiz, key, and summary to me by 7:30 am on the day you are presenting. Send.doc files Send.doc files (If you get them to me by 3pm on a weekday before you present, I’ll still print them) (If you get them to me by 3pm on a weekday before you present, I’ll still print them) Lessons from week 1: Lessons from week 1: Nice research and summarization! Nice research and summarization! Proofread your stuff. Everyone else will see it. Proofread your stuff. Everyone else will see it. 1-page quizzes are good (or staple) 1-page quizzes are good (or staple) Summaries don’t have to be verbose, just dense with info. Summaries don’t have to be verbose, just dense with info.

3 This week: Fifteen assignment Monday: Monday: Fifteen specification Fifteen specification GUIs using Java’s Swing library GUIs using Java’s Swing library Intro to UML as a design tool Intro to UML as a design tool Start Fifteen Start Fifteen Tuesday: Tuesday: EventListeners: responding to user input EventListeners: responding to user input Time to work on project Time to work on project Thursday: Thursday: Anonymous classes (capsule) Anonymous classes (capsule) Function objects and comparators (capsule) Function objects and comparators (capsule)

4 “Fifteen” Arrays (especially 2D) Creating GUIs using Swing Responding to mouse clicks

5 Fifteem Teams beltonj1-fishmad bennetrn-leveyjr bennindp-speyerea crockeea-morrisps devorejd-priestjs lundgrpb-skilessa johnsoad-smithny sullivja-wentztj mcginnda behlinmc-bennetdj clutecc-dovalojd gatesds heinma1-hulettbh johnsoac-rubinza kruthar-richarme millerbe-eckertwm mosttw-reillytm nibertjw-stokesej Repos is csse221-200810- -. If solo, use your personal repos. Discuss how to pair-program

6 Fundamentals of Software Development 1 6 The Java Swing Library JFrames, JTextBoxes, JButtons, JScrollPanes… what’s available? JFrames, JTextBoxes, JButtons, JScrollPanes… what’s available? What components will I need… What components will I need… …now, for Fifteen? …now, for Fifteen? …later, for a term project? …later, for a term project? Browse the Visual Index to the Swing Components in Sun’s Java Tutorial. Browse the Visual Index to the Swing Components in Sun’s Java Tutorial.Visual Index to the Swing Components Java TutorialVisual Index to the Swing Components Java Tutorial

7 JFrame A simple window that contains the other GUI components A simple window that contains the other GUI components Background Color Background Color getContentPane().setBackground(Color); getContentPane().setBackground(Color); Make sure to set visible Make sure to set visible setVisible(true); setVisible(true); Setting the size Setting the size setSize(width, height); setSize(width, height);

8 Benefits of Extending JFrame or JComponents like JPanel When extending the JFrame class we can still instantiate it as JFrame. When extending the JFrame class we can still instantiate it as JFrame. “Controlling” the JFrame is easier to comprehend when we do not need the calling object stated every time. “Controlling” the JFrame is easier to comprehend when we do not need the calling object stated every time. i.e. setSize(w,h); instead of jFrameObject.setSize(w,h);

9 JLabel Displays text to user Displays text to user User cannot edit text User cannot edit text Construction: JLabel message = new JLabel(String text); Construction: JLabel message = new JLabel(String text);Methods: String text = message.getText(); String text = message.getText(); message.setText(String text); message.setText(String text);

10 JTextField Lets user enter or modify a single line of text Lets user enter or modify a single line of text Construction: Construction: JTextField text = new JTextField(int WidthInCharacters); JTextField text = new JTextField(int WidthInCharacters); Getting the Text: Getting the Text: String input = text.getText(); String input = text.getText(); Setting text in a Text Field: Setting text in a Text Field: text.setText(String output); text.setText(String output);

11 JTextArea Lets user enter or modify multiple lines of text. Lets user enter or modify multiple lines of text. Declaration: private JTextArea text; Declaration: private JTextArea text; Constructors: Constructors: text = new JTextArea(int rows, int columns); text = new JTextArea(int rows, int columns); text = new JTextArea(String output); text = new JTextArea(String output); text = new JTextArea(String output, int rows, int columns); text = new JTextArea(String output, int rows, int columns); Useful methods: Useful methods: String input = text.getText(); String input = text.getText(); text.setText(String output); text.setText(String output); setEditable(Boolean editable); setEditable(Boolean editable); boolean editable = text.isEditable(); boolean editable = text.isEditable();

12 JButton Used to let user execute action Used to let user execute action Construction: JButton button = new JButton(String text); Construction: JButton button = new JButton(String text); button.setBackground(Color color); button.setBackground(Color color);

13 JPanel Simple container that groups objects Simple container that groups objects Meant to subdivide Meant to subdivide Creation Syntax: Creation Syntax: JPanel panelName = new JPanel(); JPanel panelName = new JPanel(); Useful attributes and methods Useful attributes and methods.setLayout(new Layout());.setLayout(new Layout());.add(component);.add(component);.setBackground(Color color);.setBackground(Color color);

14 Layout Managers Frames are organized by layout managers. Frames are organized by layout managers. Organizes the locations of the components within the frame Organizes the locations of the components within the frame Not only frames use layout managers, but Panels are also organized by layout managers. Not only frames use layout managers, but Panels are also organized by layout managers. Allows for panels within panels. Allows for panels within panels.

15 Layout: Flow Layout Places the components from the left side to the right side. Places the components from the left side to the right side. Wraps around the right side. Wraps around the right side..setLayout(new FlowLayout());.setLayout(new FlowLayout()); No special add syntax. No special add syntax.

16 Layout: Border Layout North, South, East, West, Center North, South, East, West, Center setLayout(new BorderLayout()); setLayout(new BorderLayout());.add(component, BorderLayout.NORTH);.add(component, BorderLayout.NORTH);

17 Layout: Grid Layout Similar to flow in the left to right manner, but the grid that you define limits the size of any one component Similar to flow in the left to right manner, but the grid that you define limits the size of any one component You can leave out a definite definition of how many rows or columns are in the grid. You can leave out a definite definition of how many rows or columns are in the grid. setLayout(new GridLayout(r,c)); setLayout(new GridLayout(r,c)); Adds in components from left to right, top to bottom. Cannot specify which block. Adds in components from left to right, top to bottom. Cannot specify which block.

18 PaintComponent Used with JPanels, and all JComponents, to paint the components on the screen. Used with JPanels, and all JComponents, to paint the components on the screen. Called automatically, no need to invoke it. Called automatically, no need to invoke it. Use repaint(); to force the paintComponent() method to execute. Use repaint(); to force the paintComponent() method to execute. Start with super.paintComponent(g); where g is your Graphics object Start with super.paintComponent(g); where g is your Graphics object public void paintComponent(Graphics g) { super.paintComponent(g); setBackgroundColor(Color.red);g.drawOval(10,40,20,20);}

19 Alternative designs I want a component to appear. Question: I want a component to appear. Question: Should I paint it? Add a new component? Should I paint it? Add a new component? Answer: It depends… Answer: It depends… On how much control you want over its appearance On how much control you want over its appearance On how you want it to respond to events On how you want it to respond to events It’s usually a tradeoff. It’s usually a tradeoff. Press me!

20 Listeners If you want to respond to events, you need to implement a Listener interface. If you want to respond to events, you need to implement a Listener interface. We’ll look at these in detail tomorrow We’ll look at these in detail tomorrow

21 Demo together


Download ppt "CSSE221: Software Dev. Honors Day 8 Announcements Announcements HW3 due now, solutions will be posted. HW3 due now, solutions will be posted. Questions."

Similar presentations


Ads by Google