SE-1021 Software Engineering II 5/22/2019 SE-1021 Software Engineering II Week 5, Class 3 Completing the Calculator GUI layout SE-2811 Dr. Josiah Yoder Slide style: Dr. Hornick Dr. Josiah Yoder
How can we create this calculator layout? Modify the code below to put the operators above the buttons… 112344 5 + - * / 1 2 3 4 6 7 8 9 /// in the constructor… setLayout(new BorderLayout()); JPanel panel = createButtonPanel(); add(panel,BorderLayout.CENTER); public JPanel createOperationPanel() { JPanel panel = new JPanel(); panel.add(new JButton("+")); panel.add(new JButton("-")); panel.add(new JButton("*")); panel.add(new JButton("/")); return panel; } SE-2811 Dr. Josiah Yoder Slide style: Dr. Hornick
Get to know your classmates Turn to a neighbor, and find out who traveled farther over Christmas break When you have determined who traveled farther, that person should raise his hand SE-2811 Dr. Josiah Yoder Slide style: Dr. Hornick
What do we need to do to get our GUI to respond? In your groups of 2… Write a list of as many things that you can think of as possible to complete the GUI application. Favor quantity over quality SE-2811 Dr. Josiah Yoder Slide style: Dr. Hornick
Slide style: Dr. Hornick What is an inner class? An inner class is Declared inside of another class Usually declared private (needed by only one class) Has access to all variables of the top-level class Even instance variables! And so … _____________________________ Even private variables! And so … ______________________________ Dean & Dean, 2nd Ed. Pp 775-776 (Sec. 17.10) http://docs.oracle.com/javase/tutorial/java/javaOO/nested.html SE-2811 Dr. Josiah Yoder Slide style: Dr. Hornick
Slide style: Dr. Hornick Anonymous Inner Class This is a class that is DECLARED at the same place it is INSTANTIATED in the program Syntax: new InterfaceName () { ClassBody } Use: Use it where you would use the constructor of the class SE-2811 Dr. Josiah Yoder Slide style: Dr. Hornick
Slide style: Dr. Hornick Lambda Expression A lambda expression is an anonymous inner class with shorter syntax, for interfaces with just one method. Example: e -> myMethod(e) Use: Use it where you would use a constructor or an anonymous inner class. SE-2811 Dr. Josiah Yoder Slide style: Dr. Hornick
From the Horse’s Mouth* “Lambda expressions let you express instances of single-method classes more compactly.” http://docs.oracle.com/javase/tutorial/java/javaOO/lambdaexpressions.html (emphasis added) * “straight from the Horse’s mouth” is an idiom saying to get something from an authoritative source. It refers to looking into a horse’s mouth to determine its age. SE-2811 Dr. Josiah Yoder Slide style: Dr. Hornick
Slide style: Dr. Hornick Answer this question Example lambda expression: e->System.out.println(e.getActionCommand()) Can a lambda expression use instance variables? How about instance methods? Think alone 1 minutes, discuss in pairs 1 minute SE-2811 Dr. Josiah Yoder Slide style: Dr. Hornick