=====
CS 235 - Week 6 Lecture - 2021-09-27
=====
=====
TODAY WE WILL
=====
* announcements
* more on GUI interfaces and event-handling in Java!
* intro to borders!
* intro to JTextField
* prep for next class
* current reading:
* from "Core Java":
* Chapter 10 - Graphical User Interface Programming
* Chapter 11 - 11.3.2 - labels and labeling components
Chapter 11 - 11.4.3 - borders
(and maybe more on exception handling --
Chapter 7 - 7.1, 7.2, 7.3 - related to exceptions)
* so, for a variety of reasons...
* Exam 1 will be on Canvas instead of on-paper
* it will be on FRIDAY, OCTOBER 15th, DURING Lab time
(3:00 - 5:00 pm)
* so, you can take it on Canvas in BSS 317 (and I will be
there)
OR you can take it on Canvas anywhere you have Internet
access (and I can answer questions via Zoom-chat)
======
HERE is the proposed revised schedule, then!
(PLEASE let me know, here OR in e-mail OR in Zoom student hours
of any issues! questions! etc.)
* Friday, OCT 1 - a lab exercise on this week's topics
instead of Exam 1 review
* and Homework 4 is still due Friday, October 1st, 11:59 pm)
* and now a Homework 5 can come out that weekend,
due Friday, October 8th
* Monday, OCT 4 - we'll start layout managers instead of having
Exam 1
* Friday, OCT 8 - still no lab, due to instructor travel
to CCSC-NW 2021
* but Homework 5 will be due 11:59 pm Friday, October 8
* Monday, OCT 11 - REVIEW for Exam 1
(instead of intro to layout mgrs)
* turn in any outstanding HW pieces by 11:59 pm on TUESDAY,
OCT 12,
then I can post example HW solutions by early WEDNESDAY,
OCT 13th
* FRIDAY, OCT 15 - EXAM 1, on Canvas, either in BSS 317 or
in a location of your choosing that has Internet,
from 3:00 - 5:00 pm
* and Homework 6 can then come out that weekend...!
========
* we've seen just ONE of quite a number of Event SUBCLASSES
and descendants: ActionEvent
we've seen just ONE of quite a number of Interface SUB...INTERFACES?!
and descendants: ActionEventListener
* Event - abstract Java class! with many descendant classes
* EventListener - Java interface! with many descendant
interfaces!
=======
* Borders!
* an example of a "goodie" that Swing brought in!
* another package!
javax.swing.border
(so, to be able to use all of its goodies
without having to precede their names with
javax.swing.border,
import javax.swing.border.*;
)
* you can call setBorder for the component for which you watn
a border;
there are ways you can specify quite a bit yourself,
and there are "canned" ways to get some commonly-used options;
e.g., TitledBorder class in this package
EtchedBorder class in this package
JPanel myPanel = new JPanel();
myPanel.setBorder(new TitledBorder(new EtchedBorder,
"I am a JPanel border!"));
=======
* JTextField!
* a component intended to allow for a single line of text input
(but sometimes for displaying a single line of text as well...)
* but note:
* a JLabel should be considered a "pure" output component --
the user reads it, but does not interact with it directly
* a JButton should be considered a "pure" input component --
the user clicks it, it should not be used to display output
(at least in general...!)
* a JTextField is more interestingly complex;
it is definitely often an input component,
but is sometimes also an output component
and sometimes it is used for COMBINATIONS of these!
(and please use this for good and not evil...!)
* ...because it also has greater potential for mis-use;
* ongoing discussion this semester:
trying to determine and choose the "better" component
for each task...
* but let's make some JTextField instances!
* ONE of its constructors lets you just give a desired
width in "columns" <-- sadly inexact measurement!
in theory: 1 column is tha expected width of 1 character
in the font being used for the text of that JTextField
BUT non-mono-spaced fonts definitely make this an issue...!
You want n-characters wide? better add 1 bit to that...
* AND that's just a REQUEST, anyway --
the layout manager may override it...!
(more on that next week!)
* AND this doesn't limit what the user can
enter -- just how much MAY be displayed at once...!
* you can set the text displayed in a JTextField with
its setText method
you can GET the text displayed in a JTextField with
its getText method
you can change the editability of a JTextField with
it setEditable method --
argument of true? it can be edited (that's the default)
argument of false? it CANNOT be edited
* if you MEAN for the user to NOT type into some
textfield at a given point,
it is good style to make it uneditable at that point!