Constructor for View Classweb.cse.ohio-state.edu/software/2221/web-sw1/...• A simple constructor...
Transcript of Constructor for View Classweb.cse.ohio-state.edu/software/2221/web-sw1/...• A simple constructor...
![Page 1: Constructor for View Classweb.cse.ohio-state.edu/software/2221/web-sw1/...• A simple constructor for the . view. class has four main jobs: 1. Create the JFramebeing extended 2. Set](https://reader034.fdocuments.in/reader034/viewer/2022050122/5f524223becc8538b63038b1/html5/thumbnails/1.jpg)
Constructor for View Class
7 January 2019 OSU CSE 1
![Page 2: Constructor for View Classweb.cse.ohio-state.edu/software/2221/web-sw1/...• A simple constructor for the . view. class has four main jobs: 1. Create the JFramebeing extended 2. Set](https://reader034.fdocuments.in/reader034/viewer/2022050122/5f524223becc8538b63038b1/html5/thumbnails/2.jpg)
Tasks To Be Performed• A simple constructor for the view class has four
main jobs:1. Create the JFrame being extended2. Set up the GUI widgets to be used and “lay out”
these widgets in the main application window3. Set up the observers by registering (in our
examples) the object being constructed, i.e., this, with each of the GUI widgets that might have events of interest to the application
4. Start the main application window
7 January 2019 OSU CSE 2
![Page 3: Constructor for View Classweb.cse.ohio-state.edu/software/2221/web-sw1/...• A simple constructor for the . view. class has four main jobs: 1. Create the JFramebeing extended 2. Set](https://reader034.fdocuments.in/reader034/viewer/2022050122/5f524223becc8538b63038b1/html5/thumbnails/3.jpg)
1: Create the JFramesuper("Simple GUI Demo");
7 January 2019 OSU CSE 3
![Page 4: Constructor for View Classweb.cse.ohio-state.edu/software/2221/web-sw1/...• A simple constructor for the . view. class has four main jobs: 1. Create the JFramebeing extended 2. Set](https://reader034.fdocuments.in/reader034/viewer/2022050122/5f524223becc8538b63038b1/html5/thumbnails/4.jpg)
External (GUI) Effectthis
7 January 2019 OSU CSE 4
![Page 5: Constructor for View Classweb.cse.ohio-state.edu/software/2221/web-sw1/...• A simple constructor for the . view. class has four main jobs: 1. Create the JFramebeing extended 2. Set](https://reader034.fdocuments.in/reader034/viewer/2022050122/5f524223becc8538b63038b1/html5/thumbnails/5.jpg)
External (GUI) Effectthis
7 January 2019 OSU CSE 5
Nothing illustrated in these slides actually becomes visible to the user until later!
![Page 6: Constructor for View Classweb.cse.ohio-state.edu/software/2221/web-sw1/...• A simple constructor for the . view. class has four main jobs: 1. Create the JFramebeing extended 2. Set](https://reader034.fdocuments.in/reader034/viewer/2022050122/5f524223becc8538b63038b1/html5/thumbnails/6.jpg)
2: Set Up GUI Widgets (Text)...this.inputText = new JTextArea("",
LINES_IN_TEXT_AREAS,
LINE_LENGTHS_IN_TEXT_AREAS);
...
JScrollPane inputTextScrollPane =
new JScrollPane(this.inputText);
7 January 2019 OSU CSE 6
![Page 7: Constructor for View Classweb.cse.ohio-state.edu/software/2221/web-sw1/...• A simple constructor for the . view. class has four main jobs: 1. Create the JFramebeing extended 2. Set](https://reader034.fdocuments.in/reader034/viewer/2022050122/5f524223becc8538b63038b1/html5/thumbnails/7.jpg)
2: Set Up GUI Widgets (Text)...this.inputText = new JTextArea("",
LINES_IN_TEXT_AREAS,
LINE_LENGTHS_IN_TEXT_AREAS);
...
JScrollPane inputTextScrollPane =
new JScrollPane(this.inputText);
7 January 2019 OSU CSE 7
5 lines,each of length 20
![Page 8: Constructor for View Classweb.cse.ohio-state.edu/software/2221/web-sw1/...• A simple constructor for the . view. class has four main jobs: 1. Create the JFramebeing extended 2. Set](https://reader034.fdocuments.in/reader034/viewer/2022050122/5f524223becc8538b63038b1/html5/thumbnails/8.jpg)
External (GUI) Effectthis.inputText
7 January 2019 OSU CSE 8
inputTextScrollPane
![Page 9: Constructor for View Classweb.cse.ohio-state.edu/software/2221/web-sw1/...• A simple constructor for the . view. class has four main jobs: 1. Create the JFramebeing extended 2. Set](https://reader034.fdocuments.in/reader034/viewer/2022050122/5f524223becc8538b63038b1/html5/thumbnails/9.jpg)
External (GUI) Effectthis.inputText
7 January 2019 OSU CSE 9
inputTextScrollPaneThe scrollbars in JScrollPanes
actually arise only when needed; not needed yet, but illustrated here.
![Page 10: Constructor for View Classweb.cse.ohio-state.edu/software/2221/web-sw1/...• A simple constructor for the . view. class has four main jobs: 1. Create the JFramebeing extended 2. Set](https://reader034.fdocuments.in/reader034/viewer/2022050122/5f524223becc8538b63038b1/html5/thumbnails/10.jpg)
2: Set Up GUI Widgets (Buttons)...this.copyButton =
new JButton("Copy Input");
7 January 2019 OSU CSE 10
![Page 11: Constructor for View Classweb.cse.ohio-state.edu/software/2221/web-sw1/...• A simple constructor for the . view. class has four main jobs: 1. Create the JFramebeing extended 2. Set](https://reader034.fdocuments.in/reader034/viewer/2022050122/5f524223becc8538b63038b1/html5/thumbnails/11.jpg)
External (GUI) Effect
this.copyButton
7 January 2019 OSU CSE 11
![Page 12: Constructor for View Classweb.cse.ohio-state.edu/software/2221/web-sw1/...• A simple constructor for the . view. class has four main jobs: 1. Create the JFramebeing extended 2. Set](https://reader034.fdocuments.in/reader034/viewer/2022050122/5f524223becc8538b63038b1/html5/thumbnails/12.jpg)
2: ... and Lay Out GUI WidgetsJPanel buttonPanel =
new JPanel(
new GridLayout(
ROWS_IN_BUTTON_PANEL_GRID,
COLUMNS_IN_BUTTON_PANEL_GRID));
...
buttonPanel.add(this.resetButton);buttonPanel.add(this.copyButton);
7 January 2019 OSU CSE 12
![Page 13: Constructor for View Classweb.cse.ohio-state.edu/software/2221/web-sw1/...• A simple constructor for the . view. class has four main jobs: 1. Create the JFramebeing extended 2. Set](https://reader034.fdocuments.in/reader034/viewer/2022050122/5f524223becc8538b63038b1/html5/thumbnails/13.jpg)
2: ... and Lay Out GUI WidgetsJPanel buttonPanel =
new JPanel(
new GridLayout(
ROWS_IN_BUTTON_PANEL_GRID,
COLUMNS_IN_BUTTON_PANEL_GRID));
...
buttonPanel.add(this.resetButton);buttonPanel.add(this.copyButton);
7 January 2019 OSU CSE 13
1 row,2 columns
![Page 14: Constructor for View Classweb.cse.ohio-state.edu/software/2221/web-sw1/...• A simple constructor for the . view. class has four main jobs: 1. Create the JFramebeing extended 2. Set](https://reader034.fdocuments.in/reader034/viewer/2022050122/5f524223becc8538b63038b1/html5/thumbnails/14.jpg)
External (GUI) Effect
buttonPanel
7 January 2019 OSU CSE 14
![Page 15: Constructor for View Classweb.cse.ohio-state.edu/software/2221/web-sw1/...• A simple constructor for the . view. class has four main jobs: 1. Create the JFramebeing extended 2. Set](https://reader034.fdocuments.in/reader034/viewer/2022050122/5f524223becc8538b63038b1/html5/thumbnails/15.jpg)
2: ... and Lay Out GUI Widgetsthis.setLayout(new GridLayout(
ROWS_IN_THIS_GRID,
COLUMNS_IN_THIS_GRID));
...
this.add(inputTextScrollPane);this.add(buttonPanel);this.add(outputTextScrollPane);
7 January 2019 OSU CSE 15
![Page 16: Constructor for View Classweb.cse.ohio-state.edu/software/2221/web-sw1/...• A simple constructor for the . view. class has four main jobs: 1. Create the JFramebeing extended 2. Set](https://reader034.fdocuments.in/reader034/viewer/2022050122/5f524223becc8538b63038b1/html5/thumbnails/16.jpg)
2: ... and Lay Out GUI Widgetsthis.setLayout(new GridLayout(
ROWS_IN_THIS_GRID,
COLUMNS_IN_THIS_GRID));
...
this.add(inputTextScrollPane);this.add(buttonPanel);this.add(outputTextScrollPane);
7 January 2019 OSU CSE 16
3 rows,1 column
![Page 17: Constructor for View Classweb.cse.ohio-state.edu/software/2221/web-sw1/...• A simple constructor for the . view. class has four main jobs: 1. Create the JFramebeing extended 2. Set](https://reader034.fdocuments.in/reader034/viewer/2022050122/5f524223becc8538b63038b1/html5/thumbnails/17.jpg)
2: ... and Lay Out GUI Widgetsthis.setLayout(new GridLayout(
ROWS_IN_THIS_GRID,
COLUMNS_IN_THIS_GRID));
...
this.add(inputTextScrollPane);this.add(buttonPanel);this.add(outputTextScrollPane);
7 January 2019 OSU CSE 17
Remember:the two buttons
are in this panel.
![Page 18: Constructor for View Classweb.cse.ohio-state.edu/software/2221/web-sw1/...• A simple constructor for the . view. class has four main jobs: 1. Create the JFramebeing extended 2. Set](https://reader034.fdocuments.in/reader034/viewer/2022050122/5f524223becc8538b63038b1/html5/thumbnails/18.jpg)
External (GUI) Effectthis
7 January 2019 OSU CSE 18
![Page 19: Constructor for View Classweb.cse.ohio-state.edu/software/2221/web-sw1/...• A simple constructor for the . view. class has four main jobs: 1. Create the JFramebeing extended 2. Set](https://reader034.fdocuments.in/reader034/viewer/2022050122/5f524223becc8538b63038b1/html5/thumbnails/19.jpg)
External (GUI) Effectthis
7 January 2019 OSU CSE 19
Remember:none of this is visible to the
user yet.
![Page 20: Constructor for View Classweb.cse.ohio-state.edu/software/2221/web-sw1/...• A simple constructor for the . view. class has four main jobs: 1. Create the JFramebeing extended 2. Set](https://reader034.fdocuments.in/reader034/viewer/2022050122/5f524223becc8538b63038b1/html5/thumbnails/20.jpg)
3: Set Up the Observersthis.resetButton.addActionListener(this);this.copyButton.addActionListener(this);
7 January 2019 OSU CSE 20
![Page 21: Constructor for View Classweb.cse.ohio-state.edu/software/2221/web-sw1/...• A simple constructor for the . view. class has four main jobs: 1. Create the JFramebeing extended 2. Set](https://reader034.fdocuments.in/reader034/viewer/2022050122/5f524223becc8538b63038b1/html5/thumbnails/21.jpg)
Internal (non-GUI) Effect
7 January 2019 OSU CSE 21
![Page 22: Constructor for View Classweb.cse.ohio-state.edu/software/2221/web-sw1/...• A simple constructor for the . view. class has four main jobs: 1. Create the JFramebeing extended 2. Set](https://reader034.fdocuments.in/reader034/viewer/2022050122/5f524223becc8538b63038b1/html5/thumbnails/22.jpg)
4: Start the Main Windowthis.pack();this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setVisible(true);
7 January 2019 OSU CSE 22
![Page 23: Constructor for View Classweb.cse.ohio-state.edu/software/2221/web-sw1/...• A simple constructor for the . view. class has four main jobs: 1. Create the JFramebeing extended 2. Set](https://reader034.fdocuments.in/reader034/viewer/2022050122/5f524223becc8538b63038b1/html5/thumbnails/23.jpg)
External (GUI) Effect: Now Visiblethis
7 January 2019 OSU CSE 23
![Page 24: Constructor for View Classweb.cse.ohio-state.edu/software/2221/web-sw1/...• A simple constructor for the . view. class has four main jobs: 1. Create the JFramebeing extended 2. Set](https://reader034.fdocuments.in/reader034/viewer/2022050122/5f524223becc8538b63038b1/html5/thumbnails/24.jpg)
External (GUI) Effect: Now Visiblethis
7 January 2019 OSU CSE 24
The only code you wrote that executes now is the callback method for the two buttons:this.actionPerformed.