CS 106A Lecture Notes - Lecture 11: Window Screen, Fahrenheit, Graphical User Interface
Document Summary
Lecture notes graphical user interface part 2: review actionlisteners(); public void actionperformed(actionevent e){ string cmd = e. getactioncommand (); //cmd now is name of button: either get name of button or button itself, get name of button e. getactioncommand(), get button itself e. getscource(), old way of checking button (through name) Jbutton hi = new jbutton( hi ) public void actionperformed(actionevent e){ string cmd = e. getactioncommand(); if(cmd. equals( hi )): new way with actual object. Jbutton hi = new jbutton( hi ) public void actionperformed(actionevent e){ string cmd = e. getactioncommand(); if(e. getsource == hi): example of new way, use instance variable hibutton . Public void init(){ hibutton = new jbutton( hi ); add(hibutton, south); addactionlisteners(); public void actionperformed(actionevent e){ if(hibutton == e. getsource()){ println( hello there ): textfields, same pattern every time. Initialize new jtextfield(size) a. i. a. ii. setactioncommand( name ) a. iii. addactionlisteners(this): container that holds text, usually instance variable. Add(new jlabel( name ), south); namefield = new jtextfield(50); namefield. setactioncommand( go );