GUI-Based Event Driven Programming

Embed Size (px)

Citation preview

  • 8/19/2019 GUI-Based Event Driven Programming

    1/58

    GUI-Based Event-Driven Programming

    http://rds.yahoo.com/_ylt=A0S020we3v9IYnUAA0SJzbkF;_ylu=X3oDMTBza3M3YnJoBHBvcwMxMzgEc2VjA3NyBHZ0aWQDSTA5N18xMTg-/SIG=1iq1fl362/EXP=1224814494/**http:/images.search.yahoo.com/images/view?back=http://images.search.yahoo.com/search/images?p=java+duke&ni=20&ei=UTF-8&fr=yfp-t-501&xargs=0&pstart=1&b=121&w=70&h=50&imgurl=www.javasource.150m.com/downloadfiles/student%20parking%20gui/duke_pencil.gif&rurl=http://www.javasource.150m.com/download.htm&size=2.2kB&name=duke_pencil.gif&p=java+duke&type=gif&oid=7fb04235f20ab6c8&no=138&tt=1,228&sigr=11b1c732g&sigi=12dqu2eu8&sigb=13bac1l9rhttp://rds.yahoo.com/_ylt=A0S020we3v9IYnUAA0SJzbkF;_ylu=X3oDMTBza3M3YnJoBHBvcwMxMzgEc2VjA3NyBHZ0aWQDSTA5N18xMTg-/SIG=1iq1fl362/EXP=1224814494/**http:/images.search.yahoo.com/images/view?back=http://images.search.yahoo.com/search/images?p=java+duke&ni=20&ei=UTF-8&fr=yfp-t-501&xargs=0&pstart=1&b=121&w=70&h=50&imgurl=www.javasource.150m.com/downloadfiles/student%20parking%20gui/duke_pencil.gif&rurl=http://www.javasource.150m.com/download.htm&size=2.2kB&name=duke_pencil.gif&p=java+duke&type=gif&oid=7fb04235f20ab6c8&no=138&tt=1,228&sigr=11b1c732g&sigi=12dqu2eu8&sigb=13bac1l9r

  • 8/19/2019 GUI-Based Event Driven Programming

    2/58

    Event . The user’s interaction with the GUIcomponent.

    Event-handling Methods . Methods that arecalled when an event occurs.

    The user interacts with a GUI component, the

    program is notified of the event and theprogram processes the event.

  • 8/19/2019 GUI-Based Event Driven Programming

    3/58

    public class Frame extends JFrame implements ActionListener

    A class can inherit existing attributes andbehaviors from another class via extends , and can

    implement one or more interfaces.

    In the class definition above, JFrame class will beinherited and interface ActionListener will be

    implemented.

    http://rds.yahoo.com/_ylt=A0S020u53_9I3PIADn2JzbkF;_ylu=X3oDMTBzZzgwMmhjBHBvcwMyMTMEc2VjA3NyBHZ0aWQDSTA5N18xMTg-/SIG=1i42g6nfg/EXP=1224814905/**http:/images.search.yahoo.com/images/view?back=http://images.search.yahoo.com/search/images?p=java+duke&ni=20&ei=UTF-8&fr=yfp-t-501&xargs=0&pstart=1&b=201&w=123&h=128&imgurl=student.educ.umu.se/~sanann00/images/duke.jpg&rurl=http://student.educ.umu.se/~sanann00/dependencies.html&size=9.9kB&name=duke.jpg&p=java+duke&type=JPG&oid=581f3667c98a4ad2&no=213&tt=1,234&sigr=11mg3psqe&sigi=11df3i068&sigb=13bus36b1http://rds.yahoo.com/_ylt=A0S020u53_9I3PIADn2JzbkF;_ylu=X3oDMTBzZzgwMmhjBHBvcwMyMTMEc2VjA3NyBHZ0aWQDSTA5N18xMTg-/SIG=1i42g6nfg/EXP=1224814905/**http:/images.search.yahoo.com/images/view?back=http://images.search.yahoo.com/search/images?p=java+duke&ni=20&ei=UTF-8&fr=yfp-t-501&xargs=0&pstart=1&b=201&w=123&h=128&imgurl=student.educ.umu.se/~sanann00/images/duke.jpg&rurl=http://student.educ.umu.se/~sanann00/dependencies.html&size=9.9kB&name=duke.jpg&p=java+duke&type=JPG&oid=581f3667c98a4ad2&no=213&tt=1,234&sigr=11mg3psqe&sigi=11df3i068&sigb=13bus36b1

  • 8/19/2019 GUI-Based Event Driven Programming

    4/58

    Class JFrame is from the package javax.swing

    JFrame provides the basic attributes andbehaviors of a window – a title bar andbuttons to minimize, maximize and closethe window.

    http://rds.yahoo.com/_ylt=A0S020yP3_9Ivm0AvhKJzbkF;_ylu=X3oDMTBzZ2IxajRpBHBvcwMxNDYEc2VjA3NyBHZ0aWQDSTA5N18xMTg-/SIG=1io83a6s9/EXP=1224814863/**http:/images.search.yahoo.com/images/view?back=http://images.search.yahoo.com/search/images?p=java+duke&ni=20&ei=UTF-8&fr=yfp-t-501&xargs=0&pstart=1&b=141&w=55&h=50&imgurl=www.javasource.150m.com/downloadfiles/student%20parking%20gui/duke_point.gif&rurl=http://www.javasource.150m.com/download.htm&size=1.2kB&name=duke_point.gif&p=java+duke&type=gif&oid=a455006d5347dc14&no=146&tt=1,234&sigr=11b1c732g&sigi=12ce8i9ji&sigb=13b4g5kh7http://rds.yahoo.com/_ylt=A0S020yP3_9Ivm0AvhKJzbkF;_ylu=X3oDMTBzZ2IxajRpBHBvcwMxNDYEc2VjA3NyBHZ0aWQDSTA5N18xMTg-/SIG=1io83a6s9/EXP=1224814863/**http:/images.search.yahoo.com/images/view?back=http://images.search.yahoo.com/search/images?p=java+duke&ni=20&ei=UTF-8&fr=yfp-t-501&xargs=0&pstart=1&b=141&w=55&h=50&imgurl=www.javasource.150m.com/downloadfiles/student%20parking%20gui/duke_point.gif&rurl=http://www.javasource.150m.com/download.htm&size=1.2kB&name=duke_point.gif&p=java+duke&type=gif&oid=a455006d5347dc14&no=146&tt=1,234&sigr=11b1c732g&sigi=12ce8i9ji&sigb=13b4g5kh7

  • 8/19/2019 GUI-Based Event Driven Programming

    5/58

    Interface . Specifies one or more behaviors that youmust define in your class definition.

    This interface specifies that this class must define amethod with the heading:

    public void actionPerformed (ActionEvent e){}

    The methods task is to process a user’s interaction witha GUI component that generates an action event.

    The method is called automatically in response to theuser’s interaction.

    http://rds.yahoo.com/_ylt=A0S020u53_9I3PIADn2JzbkF;_ylu=X3oDMTBzZzgwMmhjBHBvcwMyMTMEc2VjA3NyBHZ0aWQDSTA5N18xMTg-/SIG=1i42g6nfg/EXP=1224814905/**http:/images.search.yahoo.com/images/view?back=http://images.search.yahoo.com/search/images?p=java+duke&ni=20&ei=UTF-8&fr=yfp-t-501&xargs=0&pstart=1&b=201&w=123&h=128&imgurl=student.educ.umu.se/~sanann00/images/duke.jpg&rurl=http://student.educ.umu.se/~sanann00/dependencies.html&size=9.9kB&name=duke.jpg&p=java+duke&type=JPG&oid=581f3667c98a4ad2&no=213&tt=1,234&sigr=11mg3psqe&sigi=11df3i068&sigb=13bus36b1http://rds.yahoo.com/_ylt=A0S020u53_9I3PIADn2JzbkF;_ylu=X3oDMTBzZzgwMmhjBHBvcwMyMTMEc2VjA3NyBHZ0aWQDSTA5N18xMTg-/SIG=1i42g6nfg/EXP=1224814905/**http:/images.search.yahoo.com/images/view?back=http://images.search.yahoo.com/search/images?p=java+duke&ni=20&ei=UTF-8&fr=yfp-t-501&xargs=0&pstart=1&b=201&w=123&h=128&imgurl=student.educ.umu.se/~sanann00/images/duke.jpg&rurl=http://student.educ.umu.se/~sanann00/dependencies.html&size=9.9kB&name=duke.jpg&p=java+duke&type=JPG&oid=581f3667c98a4ad2&no=213&tt=1,234&sigr=11mg3psqe&sigi=11df3i068&sigb=13bus36b1

  • 8/19/2019 GUI-Based Event Driven Programming

    6/58

    Sets the window’s size.

    Syntax :

    setSize (width, height);

    http://rds.yahoo.com/_ylt=A0S020u53_9I3PIADn2JzbkF;_ylu=X3oDMTBzZzgwMmhjBHBvcwMyMTMEc2VjA3NyBHZ0aWQDSTA5N18xMTg-/SIG=1i42g6nfg/EXP=1224814905/**http:/images.search.yahoo.com/images/view?back=http://images.search.yahoo.com/search/images?p=java+duke&ni=20&ei=UTF-8&fr=yfp-t-501&xargs=0&pstart=1&b=201&w=123&h=128&imgurl=student.educ.umu.se/~sanann00/images/duke.jpg&rurl=http://student.educ.umu.se/~sanann00/dependencies.html&size=9.9kB&name=duke.jpg&p=java+duke&type=JPG&oid=581f3667c98a4ad2&no=213&tt=1,234&sigr=11mg3psqe&sigi=11df3i068&sigb=13bus36b1http://rds.yahoo.com/_ylt=A0S020u53_9I3PIADn2JzbkF;_ylu=X3oDMTBzZzgwMmhjBHBvcwMyMTMEc2VjA3NyBHZ0aWQDSTA5N18xMTg-/SIG=1i42g6nfg/EXP=1224814905/**http:/images.search.yahoo.com/images/view?back=http://images.search.yahoo.com/search/images?p=java+duke&ni=20&ei=UTF-8&fr=yfp-t-501&xargs=0&pstart=1&b=201&w=123&h=128&imgurl=student.educ.umu.se/~sanann00/images/duke.jpg&rurl=http://student.educ.umu.se/~sanann00/dependencies.html&size=9.9kB&name=duke.jpg&p=java+duke&type=JPG&oid=581f3667c98a4ad2&no=213&tt=1,234&sigr=11mg3psqe&sigi=11df3i068&sigb=13bus36b1

  • 8/19/2019 GUI-Based Event Driven Programming

    7/58

    By default a window is NOT displayed on thescreen, it can be displayed using thesetVisible method.

    Syntax :

    setVisible (true);

    http://rds.yahoo.com/_ylt=A0S020u53_9I3PIADn2JzbkF;_ylu=X3oDMTBzZzgwMmhjBHBvcwMyMTMEc2VjA3NyBHZ0aWQDSTA5N18xMTg-/SIG=1i42g6nfg/EXP=1224814905/**http:/images.search.yahoo.com/images/view?back=http://images.search.yahoo.com/search/images?p=java+duke&ni=20&ei=UTF-8&fr=yfp-t-501&xargs=0&pstart=1&b=201&w=123&h=128&imgurl=student.educ.umu.se/~sanann00/images/duke.jpg&rurl=http://student.educ.umu.se/~sanann00/dependencies.html&size=9.9kB&name=duke.jpg&p=java+duke&type=JPG&oid=581f3667c98a4ad2&no=213&tt=1,234&sigr=11mg3psqe&sigi=11df3i068&sigb=13bus36b1http://rds.yahoo.com/_ylt=A0S020u53_9I3PIADn2JzbkF;_ylu=X3oDMTBzZzgwMmhjBHBvcwMyMTMEc2VjA3NyBHZ0aWQDSTA5N18xMTg-/SIG=1i42g6nfg/EXP=1224814905/**http:/images.search.yahoo.com/images/view?back=http://images.search.yahoo.com/search/images?p=java+duke&ni=20&ei=UTF-8&fr=yfp-t-501&xargs=0&pstart=1&b=201&w=123&h=128&imgurl=student.educ.umu.se/~sanann00/images/duke.jpg&rurl=http://student.educ.umu.se/~sanann00/dependencies.html&size=9.9kB&name=duke.jpg&p=java+duke&type=JPG&oid=581f3667c98a4ad2&no=213&tt=1,234&sigr=11mg3psqe&sigi=11df3i068&sigb=13bus36b1

  • 8/19/2019 GUI-Based Event Driven Programming

    8/58

    Displays the text in the title bar of thewindow.

    Syntax :

    setTitle (“text on title bar”);

    http://rds.yahoo.com/_ylt=A0S020u53_9I3PIADn2JzbkF;_ylu=X3oDMTBzZzgwMmhjBHBvcwMyMTMEc2VjA3NyBHZ0aWQDSTA5N18xMTg-/SIG=1i42g6nfg/EXP=1224814905/**http:/images.search.yahoo.com/images/view?back=http://images.search.yahoo.com/search/images?p=java+duke&ni=20&ei=UTF-8&fr=yfp-t-501&xargs=0&pstart=1&b=201&w=123&h=128&imgurl=student.educ.umu.se/~sanann00/images/duke.jpg&rurl=http://student.educ.umu.se/~sanann00/dependencies.html&size=9.9kB&name=duke.jpg&p=java+duke&type=JPG&oid=581f3667c98a4ad2&no=213&tt=1,234&sigr=11mg3psqe&sigi=11df3i068&sigb=13bus36b1http://rds.yahoo.com/_ylt=A0S020u53_9I3PIADn2JzbkF;_ylu=X3oDMTBzZzgwMmhjBHBvcwMyMTMEc2VjA3NyBHZ0aWQDSTA5N18xMTg-/SIG=1i42g6nfg/EXP=1224814905/**http:/images.search.yahoo.com/images/view?back=http://images.search.yahoo.com/search/images?p=java+duke&ni=20&ei=UTF-8&fr=yfp-t-501&xargs=0&pstart=1&b=201&w=123&h=128&imgurl=student.educ.umu.se/~sanann00/images/duke.jpg&rurl=http://student.educ.umu.se/~sanann00/dependencies.html&size=9.9kB&name=duke.jpg&p=java+duke&type=JPG&oid=581f3667c98a4ad2&no=213&tt=1,234&sigr=11mg3psqe&sigi=11df3i068&sigb=13bus36b1

  • 8/19/2019 GUI-Based Event Driven Programming

    9/58

    Displays the text in the title bar of thewindow.

    Should be the first statement of theconstructor.

    Syntax :

    super (“text on title bar”) ;

    http://rds.yahoo.com/_ylt=A0S020u53_9I3PIADn2JzbkF;_ylu=X3oDMTBzZzgwMmhjBHBvcwMyMTMEc2VjA3NyBHZ0aWQDSTA5N18xMTg-/SIG=1i42g6nfg/EXP=1224814905/**http:/images.search.yahoo.com/images/view?back=http://images.search.yahoo.com/search/images?p=java+duke&ni=20&ei=UTF-8&fr=yfp-t-501&xargs=0&pstart=1&b=201&w=123&h=128&imgurl=student.educ.umu.se/~sanann00/images/duke.jpg&rurl=http://student.educ.umu.se/~sanann00/dependencies.html&size=9.9kB&name=duke.jpg&p=java+duke&type=JPG&oid=581f3667c98a4ad2&no=213&tt=1,234&sigr=11mg3psqe&sigi=11df3i068&sigb=13bus36b1http://rds.yahoo.com/_ylt=A0S020u53_9I3PIADn2JzbkF;_ylu=X3oDMTBzZzgwMmhjBHBvcwMyMTMEc2VjA3NyBHZ0aWQDSTA5N18xMTg-/SIG=1i42g6nfg/EXP=1224814905/**http:/images.search.yahoo.com/images/view?back=http://images.search.yahoo.com/search/images?p=java+duke&ni=20&ei=UTF-8&fr=yfp-t-501&xargs=0&pstart=1&b=201&w=123&h=128&imgurl=student.educ.umu.se/~sanann00/images/duke.jpg&rurl=http://student.educ.umu.se/~sanann00/dependencies.html&size=9.9kB&name=duke.jpg&p=java+duke&type=JPG&oid=581f3667c98a4ad2&no=213&tt=1,234&sigr=11mg3psqe&sigi=11df3i068&sigb=13bus36b1

  • 8/19/2019 GUI-Based Event Driven Programming

    10/58

    When a window is no longer needed in anapplication , it must be explicitly disposed of.

    This can be done by explicitly calling themethod setDefaultCloseOperation with theargument JFrame.EXIT_ON_CLOSE

    http://rds.yahoo.com/_ylt=A0S020u53_9I3PIADn2JzbkF;_ylu=X3oDMTBzZzgwMmhjBHBvcwMyMTMEc2VjA3NyBHZ0aWQDSTA5N18xMTg-/SIG=1i42g6nfg/EXP=1224814905/**http:/images.search.yahoo.com/images/view?back=http://images.search.yahoo.com/search/images?p=java+duke&ni=20&ei=UTF-8&fr=yfp-t-501&xargs=0&pstart=1&b=201&w=123&h=128&imgurl=student.educ.umu.se/~sanann00/images/duke.jpg&rurl=http://student.educ.umu.se/~sanann00/dependencies.html&size=9.9kB&name=duke.jpg&p=java+duke&type=JPG&oid=581f3667c98a4ad2&no=213&tt=1,234&sigr=11mg3psqe&sigi=11df3i068&sigb=13bus36b1http://rds.yahoo.com/_ylt=A0S020u53_9I3PIADn2JzbkF;_ylu=X3oDMTBzZzgwMmhjBHBvcwMyMTMEc2VjA3NyBHZ0aWQDSTA5N18xMTg-/SIG=1i42g6nfg/EXP=1224814905/**http:/images.search.yahoo.com/images/view?back=http://images.search.yahoo.com/search/images?p=java+duke&ni=20&ei=UTF-8&fr=yfp-t-501&xargs=0&pstart=1&b=201&w=123&h=128&imgurl=student.educ.umu.se/~sanann00/images/duke.jpg&rurl=http://student.educ.umu.se/~sanann00/dependencies.html&size=9.9kB&name=duke.jpg&p=java+duke&type=JPG&oid=581f3667c98a4ad2&no=213&tt=1,234&sigr=11mg3psqe&sigi=11df3i068&sigb=13bus36b1

  • 8/19/2019 GUI-Based Event Driven Programming

    11/58

    From package java.awt

    Use to attach a GUI component on thecontent pane so they can be displayed atexecution time

    Syntax:Container = getContentPane ( );

    getContentPane ().A method that returns areference to the content pane that can beused to attach GUI component

    http://rds.yahoo.com/_ylt=A0S020yP3_9Ivm0AvhKJzbkF;_ylu=X3oDMTBzZ2IxajRpBHBvcwMxNDYEc2VjA3NyBHZ0aWQDSTA5N18xMTg-/SIG=1io83a6s9/EXP=1224814863/**http:/images.search.yahoo.com/images/view?back=http://images.search.yahoo.com/search/images?p=java+duke&ni=20&ei=UTF-8&fr=yfp-t-501&xargs=0&pstart=1&b=141&w=55&h=50&imgurl=www.javasource.150m.com/downloadfiles/student%20parking%20gui/duke_point.gif&rurl=http://www.javasource.150m.com/download.htm&size=1.2kB&name=duke_point.gif&p=java+duke&type=gif&oid=a455006d5347dc14&no=146&tt=1,234&sigr=11b1c732g&sigi=12ce8i9ji&sigb=13b4g5kh7http://rds.yahoo.com/_ylt=A0S020yP3_9Ivm0AvhKJzbkF;_ylu=X3oDMTBzZ2IxajRpBHBvcwMxNDYEc2VjA3NyBHZ0aWQDSTA5N18xMTg-/SIG=1io83a6s9/EXP=1224814863/**http:/images.search.yahoo.com/images/view?back=http://images.search.yahoo.com/search/images?p=java+duke&ni=20&ei=UTF-8&fr=yfp-t-501&xargs=0&pstart=1&b=141&w=55&h=50&imgurl=www.javasource.150m.com/downloadfiles/student%20parking%20gui/duke_point.gif&rurl=http://www.javasource.150m.com/download.htm&size=1.2kB&name=duke_point.gif&p=java+duke&type=gif&oid=a455006d5347dc14&no=146&tt=1,234&sigr=11b1c732g&sigi=12ce8i9ji&sigb=13b4g5kh7

  • 8/19/2019 GUI-Based Event Driven Programming

    12/58

    Used to define the layout manager for the applet’suser interface.

    Layout Mana ger . Provided to arrange GUIcomponents on the Container for presentationpurposes. This determines the position and size of every GUI component attached to the container.

    Syntax:

    Object of Container.setLayout (new FlowLayout ( ) );

    http://rds.yahoo.com/_ylt=A0S020u53_9I3PIADn2JzbkF;_ylu=X3oDMTBzZzgwMmhjBHBvcwMyMTMEc2VjA3NyBHZ0aWQDSTA5N18xMTg-/SIG=1i42g6nfg/EXP=1224814905/**http:/images.search.yahoo.com/images/view?back=http://images.search.yahoo.com/search/images?p=java+duke&ni=20&ei=UTF-8&fr=yfp-t-501&xargs=0&pstart=1&b=201&w=123&h=128&imgurl=student.educ.umu.se/~sanann00/images/duke.jpg&rurl=http://student.educ.umu.se/~sanann00/dependencies.html&size=9.9kB&name=duke.jpg&p=java+duke&type=JPG&oid=581f3667c98a4ad2&no=213&tt=1,234&sigr=11mg3psqe&sigi=11df3i068&sigb=13bus36b1http://rds.yahoo.com/_ylt=A0S020u53_9I3PIADn2JzbkF;_ylu=X3oDMTBzZzgwMmhjBHBvcwMyMTMEc2VjA3NyBHZ0aWQDSTA5N18xMTg-/SIG=1i42g6nfg/EXP=1224814905/**http:/images.search.yahoo.com/images/view?back=http://images.search.yahoo.com/search/images?p=java+duke&ni=20&ei=UTF-8&fr=yfp-t-501&xargs=0&pstart=1&b=201&w=123&h=128&imgurl=student.educ.umu.se/~sanann00/images/duke.jpg&rurl=http://student.educ.umu.se/~sanann00/dependencies.html&size=9.9kB&name=duke.jpg&p=java+duke&type=JPG&oid=581f3667c98a4ad2&no=213&tt=1,234&sigr=11mg3psqe&sigi=11df3i068&sigb=13bus36b1

  • 8/19/2019 GUI-Based Event Driven Programming

    13/58

    The most basic layout manager

    GUI components are placed on the containerfrom left to right in the order in which theyare attached to the container via the methodadd.

    When the edge of the container is reached,components are continued to the next line.

    http://rds.yahoo.com/_ylt=A0S020u53_9I3PIADn2JzbkF;_ylu=X3oDMTBzZzgwMmhjBHBvcwMyMTMEc2VjA3NyBHZ0aWQDSTA5N18xMTg-/SIG=1i42g6nfg/EXP=1224814905/**http:/images.search.yahoo.com/images/view?back=http://images.search.yahoo.com/search/images?p=java+duke&ni=20&ei=UTF-8&fr=yfp-t-501&xargs=0&pstart=1&b=201&w=123&h=128&imgurl=student.educ.umu.se/~sanann00/images/duke.jpg&rurl=http://student.educ.umu.se/~sanann00/dependencies.html&size=9.9kB&name=duke.jpg&p=java+duke&type=JPG&oid=581f3667c98a4ad2&no=213&tt=1,234&sigr=11mg3psqe&sigi=11df3i068&sigb=13bus36b1http://rds.yahoo.com/_ylt=A0S020u53_9I3PIADn2JzbkF;_ylu=X3oDMTBzZzgwMmhjBHBvcwMyMTMEc2VjA3NyBHZ0aWQDSTA5N18xMTg-/SIG=1i42g6nfg/EXP=1224814905/**http:/images.search.yahoo.com/images/view?back=http://images.search.yahoo.com/search/images?p=java+duke&ni=20&ei=UTF-8&fr=yfp-t-501&xargs=0&pstart=1&b=201&w=123&h=128&imgurl=student.educ.umu.se/~sanann00/images/duke.jpg&rurl=http://student.educ.umu.se/~sanann00/dependencies.html&size=9.9kB&name=duke.jpg&p=java+duke&type=JPG&oid=581f3667c98a4ad2&no=213&tt=1,234&sigr=11mg3psqe&sigi=11df3i068&sigb=13bus36b1

  • 8/19/2019 GUI-Based Event Driven Programming

    14/58

    Contains a string of character to display on thescreen.

    Normally indicates the purpose of another GUI

    component on the screen.Syntax:

    JLabel object_name; // declaration

    object_name = new JLabel (“String to display”) ;

    http://rds.yahoo.com/_ylt=A0S020u53_9I3PIADn2JzbkF;_ylu=X3oDMTBzZzgwMmhjBHBvcwMyMTMEc2VjA3NyBHZ0aWQDSTA5N18xMTg-/SIG=1i42g6nfg/EXP=1224814905/**http:/images.search.yahoo.com/images/view?back=http://images.search.yahoo.com/search/images?p=java+duke&ni=20&ei=UTF-8&fr=yfp-t-501&xargs=0&pstart=1&b=201&w=123&h=128&imgurl=student.educ.umu.se/~sanann00/images/duke.jpg&rurl=http://student.educ.umu.se/~sanann00/dependencies.html&size=9.9kB&name=duke.jpg&p=java+duke&type=JPG&oid=581f3667c98a4ad2&no=213&tt=1,234&sigr=11mg3psqe&sigi=11df3i068&sigb=13bus36b1http://rds.yahoo.com/_ylt=A0S020u53_9I3PIADn2JzbkF;_ylu=X3oDMTBzZzgwMmhjBHBvcwMyMTMEc2VjA3NyBHZ0aWQDSTA5N18xMTg-/SIG=1i42g6nfg/EXP=1224814905/**http:/images.search.yahoo.com/images/view?back=http://images.search.yahoo.com/search/images?p=java+duke&ni=20&ei=UTF-8&fr=yfp-t-501&xargs=0&pstart=1&b=201&w=123&h=128&imgurl=student.educ.umu.se/~sanann00/images/duke.jpg&rurl=http://student.educ.umu.se/~sanann00/dependencies.html&size=9.9kB&name=duke.jpg&p=java+duke&type=JPG&oid=581f3667c98a4ad2&no=213&tt=1,234&sigr=11mg3psqe&sigi=11df3i068&sigb=13bus36b1

  • 8/19/2019 GUI-Based Event Driven Programming

    15/58

    JLabel label1;label1 = new JLabel (“Enter a value”);

    To attach this to the content pane, use add method:

    Syntax:

    Object of Container. add(object of JLabel);

    Example, if c is the content pane, to add the new JLabellabel1, use:

    c.add (label1);

    http://rds.yahoo.com/_ylt=A0S020u53_9I3PIADn2JzbkF;_ylu=X3oDMTBzZzgwMmhjBHBvcwMyMTMEc2VjA3NyBHZ0aWQDSTA5N18xMTg-/SIG=1i42g6nfg/EXP=1224814905/**http:/images.search.yahoo.com/images/view?back=http://images.search.yahoo.com/search/images?p=java+duke&ni=20&ei=UTF-8&fr=yfp-t-501&xargs=0&pstart=1&b=201&w=123&h=128&imgurl=student.educ.umu.se/~sanann00/images/duke.jpg&rurl=http://student.educ.umu.se/~sanann00/dependencies.html&size=9.9kB&name=duke.jpg&p=java+duke&type=JPG&oid=581f3667c98a4ad2&no=213&tt=1,234&sigr=11mg3psqe&sigi=11df3i068&sigb=13bus36b1http://rds.yahoo.com/_ylt=A0S020u53_9I3PIADn2JzbkF;_ylu=X3oDMTBzZzgwMmhjBHBvcwMyMTMEc2VjA3NyBHZ0aWQDSTA5N18xMTg-/SIG=1i42g6nfg/EXP=1224814905/**http:/images.search.yahoo.com/images/view?back=http://images.search.yahoo.com/search/images?p=java+duke&ni=20&ei=UTF-8&fr=yfp-t-501&xargs=0&pstart=1&b=201&w=123&h=128&imgurl=student.educ.umu.se/~sanann00/images/duke.jpg&rurl=http://student.educ.umu.se/~sanann00/dependencies.html&size=9.9kB&name=duke.jpg&p=java+duke&type=JPG&oid=581f3667c98a4ad2&no=213&tt=1,234&sigr=11mg3psqe&sigi=11df3i068&sigb=13bus36b1

  • 8/19/2019 GUI-Based Event Driven Programming

    16/58

    http://rds.yahoo.com/_ylt=A0S020u53_9I3PIADn2JzbkF;_ylu=X3oDMTBzZzgwMmhjBHBvcwMyMTMEc2VjA3NyBHZ0aWQDSTA5N18xMTg-/SIG=1i42g6nfg/EXP=1224814905/**http:/images.search.yahoo.com/images/view?back=http://images.search.yahoo.com/search/images?p=java+duke&ni=20&ei=UTF-8&fr=yfp-t-501&xargs=0&pstart=1&b=201&w=123&h=128&imgurl=student.educ.umu.se/~sanann00/images/duke.jpg&rurl=http://student.educ.umu.se/~sanann00/dependencies.html&size=9.9kB&name=duke.jpg&p=java+duke&type=JPG&oid=581f3667c98a4ad2&no=213&tt=1,234&sigr=11mg3psqe&sigi=11df3i068&sigb=13bus36b1http://rds.yahoo.com/_ylt=A0S020u53_9I3PIADn2JzbkF;_ylu=X3oDMTBzZzgwMmhjBHBvcwMyMTMEc2VjA3NyBHZ0aWQDSTA5N18xMTg-/SIG=1i42g6nfg/EXP=1224814905/**http:/images.search.yahoo.com/images/view?back=http://images.search.yahoo.com/search/images?p=java+duke&ni=20&ei=UTF-8&fr=yfp-t-501&xargs=0&pstart=1&b=201&w=123&h=128&imgurl=student.educ.umu.se/~sanann00/images/duke.jpg&rurl=http://student.educ.umu.se/~sanann00/dependencies.html&size=9.9kB&name=duke.jpg&p=java+duke&type=JPG&oid=581f3667c98a4ad2&no=213&tt=1,234&sigr=11mg3psqe&sigi=11df3i068&sigb=13bus36b1

  • 8/19/2019 GUI-Based Event Driven Programming

    17/58

  • 8/19/2019 GUI-Based Event Driven Programming

    18/58

    JTextField field1;field1 = new JTextField (10);

    To attach this to the content pane, use add method:

    Syntax:

    Object of Container. add(object of JTextField);

    Example, if c is the content pane, to add the new JTextField field1, use:

    c.add (field1);

    http://rds.yahoo.com/_ylt=A0S020u53_9I3PIADn2JzbkF;_ylu=X3oDMTBzZzgwMmhjBHBvcwMyMTMEc2VjA3NyBHZ0aWQDSTA5N18xMTg-/SIG=1i42g6nfg/EXP=1224814905/**http:/images.search.yahoo.com/images/view?back=http://images.search.yahoo.com/search/images?p=java+duke&ni=20&ei=UTF-8&fr=yfp-t-501&xargs=0&pstart=1&b=201&w=123&h=128&imgurl=student.educ.umu.se/~sanann00/images/duke.jpg&rurl=http://student.educ.umu.se/~sanann00/dependencies.html&size=9.9kB&name=duke.jpg&p=java+duke&type=JPG&oid=581f3667c98a4ad2&no=213&tt=1,234&sigr=11mg3psqe&sigi=11df3i068&sigb=13bus36b1http://rds.yahoo.com/_ylt=A0S020u53_9I3PIADn2JzbkF;_ylu=X3oDMTBzZzgwMmhjBHBvcwMyMTMEc2VjA3NyBHZ0aWQDSTA5N18xMTg-/SIG=1i42g6nfg/EXP=1224814905/**http:/images.search.yahoo.com/images/view?back=http://images.search.yahoo.com/search/images?p=java+duke&ni=20&ei=UTF-8&fr=yfp-t-501&xargs=0&pstart=1&b=201&w=123&h=128&imgurl=student.educ.umu.se/~sanann00/images/duke.jpg&rurl=http://student.educ.umu.se/~sanann00/dependencies.html&size=9.9kB&name=duke.jpg&p=java+duke&type=JPG&oid=581f3667c98a4ad2&no=213&tt=1,234&sigr=11mg3psqe&sigi=11df3i068&sigb=13bus36b1

  • 8/19/2019 GUI-Based Event Driven Programming

    19/58

    http://rds.yahoo.com/_ylt=A0S020u53_9I3PIADn2JzbkF;_ylu=X3oDMTBzZzgwMmhjBHBvcwMyMTMEc2VjA3NyBHZ0aWQDSTA5N18xMTg-/SIG=1i42g6nfg/EXP=1224814905/**http:/images.search.yahoo.com/images/view?back=http://images.search.yahoo.com/search/images?p=java+duke&ni=20&ei=UTF-8&fr=yfp-t-501&xargs=0&pstart=1&b=201&w=123&h=128&imgurl=student.educ.umu.se/~sanann00/images/duke.jpg&rurl=http://student.educ.umu.se/~sanann00/dependencies.html&size=9.9kB&name=duke.jpg&p=java+duke&type=JPG&oid=581f3667c98a4ad2&no=213&tt=1,234&sigr=11mg3psqe&sigi=11df3i068&sigb=13bus36b1http://rds.yahoo.com/_ylt=A0S020u53_9I3PIADn2JzbkF;_ylu=X3oDMTBzZzgwMmhjBHBvcwMyMTMEc2VjA3NyBHZ0aWQDSTA5N18xMTg-/SIG=1i42g6nfg/EXP=1224814905/**http:/images.search.yahoo.com/images/view?back=http://images.search.yahoo.com/search/images?p=java+duke&ni=20&ei=UTF-8&fr=yfp-t-501&xargs=0&pstart=1&b=201&w=123&h=128&imgurl=student.educ.umu.se/~sanann00/images/duke.jpg&rurl=http://student.educ.umu.se/~sanann00/dependencies.html&size=9.9kB&name=duke.jpg&p=java+duke&type=JPG&oid=581f3667c98a4ad2&no=213&tt=1,234&sigr=11mg3psqe&sigi=11df3i068&sigb=13bus36b1

  • 8/19/2019 GUI-Based Event Driven Programming

    20/58

    Used to determine if user can edit entries in the JTextField.

    false value means the user cannot edit entries inthe JTextField (gray background), a true valuemeans user can edit entries (white background)

    Syntax:

    JTextField_object.setEditable (true/false);

    Example:field1.setEditable (false);

    http://rds.yahoo.com/_ylt=A0S020u53_9I3PIADn2JzbkF;_ylu=X3oDMTBzZzgwMmhjBHBvcwMyMTMEc2VjA3NyBHZ0aWQDSTA5N18xMTg-/SIG=1i42g6nfg/EXP=1224814905/**http:/images.search.yahoo.com/images/view?back=http://images.search.yahoo.com/search/images?p=java+duke&ni=20&ei=UTF-8&fr=yfp-t-501&xargs=0&pstart=1&b=201&w=123&h=128&imgurl=student.educ.umu.se/~sanann00/images/duke.jpg&rurl=http://student.educ.umu.se/~sanann00/dependencies.html&size=9.9kB&name=duke.jpg&p=java+duke&type=JPG&oid=581f3667c98a4ad2&no=213&tt=1,234&sigr=11mg3psqe&sigi=11df3i068&sigb=13bus36b1http://rds.yahoo.com/_ylt=A0S020u53_9I3PIADn2JzbkF;_ylu=X3oDMTBzZzgwMmhjBHBvcwMyMTMEc2VjA3NyBHZ0aWQDSTA5N18xMTg-/SIG=1i42g6nfg/EXP=1224814905/**http:/images.search.yahoo.com/images/view?back=http://images.search.yahoo.com/search/images?p=java+duke&ni=20&ei=UTF-8&fr=yfp-t-501&xargs=0&pstart=1&b=201&w=123&h=128&imgurl=student.educ.umu.se/~sanann00/images/duke.jpg&rurl=http://student.educ.umu.se/~sanann00/dependencies.html&size=9.9kB&name=duke.jpg&p=java+duke&type=JPG&oid=581f3667c98a4ad2&no=213&tt=1,234&sigr=11mg3psqe&sigi=11df3i068&sigb=13bus36b1

  • 8/19/2019 GUI-Based Event Driven Programming

    21/58

    Rectangular object that the user can press toperform an action

    Syntax:

    JButton object_name; // declaration

    object_name = new JButton(“ Text on Button”) ;

    http://rds.yahoo.com/_ylt=A0S020u53_9I3PIADn2JzbkF;_ylu=X3oDMTBzZzgwMmhjBHBvcwMyMTMEc2VjA3NyBHZ0aWQDSTA5N18xMTg-/SIG=1i42g6nfg/EXP=1224814905/**http:/images.search.yahoo.com/images/view?back=http://images.search.yahoo.com/search/images?p=java+duke&ni=20&ei=UTF-8&fr=yfp-t-501&xargs=0&pstart=1&b=201&w=123&h=128&imgurl=student.educ.umu.se/~sanann00/images/duke.jpg&rurl=http://student.educ.umu.se/~sanann00/dependencies.html&size=9.9kB&name=duke.jpg&p=java+duke&type=JPG&oid=581f3667c98a4ad2&no=213&tt=1,234&sigr=11mg3psqe&sigi=11df3i068&sigb=13bus36b1http://rds.yahoo.com/_ylt=A0S020u53_9I3PIADn2JzbkF;_ylu=X3oDMTBzZzgwMmhjBHBvcwMyMTMEc2VjA3NyBHZ0aWQDSTA5N18xMTg-/SIG=1i42g6nfg/EXP=1224814905/**http:/images.search.yahoo.com/images/view?back=http://images.search.yahoo.com/search/images?p=java+duke&ni=20&ei=UTF-8&fr=yfp-t-501&xargs=0&pstart=1&b=201&w=123&h=128&imgurl=student.educ.umu.se/~sanann00/images/duke.jpg&rurl=http://student.educ.umu.se/~sanann00/dependencies.html&size=9.9kB&name=duke.jpg&p=java+duke&type=JPG&oid=581f3667c98a4ad2&no=213&tt=1,234&sigr=11mg3psqe&sigi=11df3i068&sigb=13bus36b1

  • 8/19/2019 GUI-Based Event Driven Programming

    22/58

    JButton button1;button1 = new JButton (“Click here”);

    To attach this to the content pane, use add method:

    Syntax:

    Object of Container. add(object of JButton);

    Example, if c is the content pane, to add the new

    JButton button1, use:c.add (button1);

    http://rds.yahoo.com/_ylt=A0S020u53_9I3PIADn2JzbkF;_ylu=X3oDMTBzZzgwMmhjBHBvcwMyMTMEc2VjA3NyBHZ0aWQDSTA5N18xMTg-/SIG=1i42g6nfg/EXP=1224814905/**http:/images.search.yahoo.com/images/view?back=http://images.search.yahoo.com/search/images?p=java+duke&ni=20&ei=UTF-8&fr=yfp-t-501&xargs=0&pstart=1&b=201&w=123&h=128&imgurl=student.educ.umu.se/~sanann00/images/duke.jpg&rurl=http://student.educ.umu.se/~sanann00/dependencies.html&size=9.9kB&name=duke.jpg&p=java+duke&type=JPG&oid=581f3667c98a4ad2&no=213&tt=1,234&sigr=11mg3psqe&sigi=11df3i068&sigb=13bus36b1http://rds.yahoo.com/_ylt=A0S020u53_9I3PIADn2JzbkF;_ylu=X3oDMTBzZzgwMmhjBHBvcwMyMTMEc2VjA3NyBHZ0aWQDSTA5N18xMTg-/SIG=1i42g6nfg/EXP=1224814905/**http:/images.search.yahoo.com/images/view?back=http://images.search.yahoo.com/search/images?p=java+duke&ni=20&ei=UTF-8&fr=yfp-t-501&xargs=0&pstart=1&b=201&w=123&h=128&imgurl=student.educ.umu.se/~sanann00/images/duke.jpg&rurl=http://student.educ.umu.se/~sanann00/dependencies.html&size=9.9kB&name=duke.jpg&p=java+duke&type=JPG&oid=581f3667c98a4ad2&no=213&tt=1,234&sigr=11mg3psqe&sigi=11df3i068&sigb=13bus36b1

  • 8/19/2019 GUI-Based Event Driven Programming

    23/58

    http://rds.yahoo.com/_ylt=A0S020u53_9I3PIADn2JzbkF;_ylu=X3oDMTBzZzgwMmhjBHBvcwMyMTMEc2VjA3NyBHZ0aWQDSTA5N18xMTg-/SIG=1i42g6nfg/EXP=1224814905/**http:/images.search.yahoo.com/images/view?back=http://images.search.yahoo.com/search/images?p=java+duke&ni=20&ei=UTF-8&fr=yfp-t-501&xargs=0&pstart=1&b=201&w=123&h=128&imgurl=student.educ.umu.se/~sanann00/images/duke.jpg&rurl=http://student.educ.umu.se/~sanann00/dependencies.html&size=9.9kB&name=duke.jpg&p=java+duke&type=JPG&oid=581f3667c98a4ad2&no=213&tt=1,234&sigr=11mg3psqe&sigi=11df3i068&sigb=13bus36b1http://rds.yahoo.com/_ylt=A0S020u53_9I3PIADn2JzbkF;_ylu=X3oDMTBzZzgwMmhjBHBvcwMyMTMEc2VjA3NyBHZ0aWQDSTA5N18xMTg-/SIG=1i42g6nfg/EXP=1224814905/**http:/images.search.yahoo.com/images/view?back=http://images.search.yahoo.com/search/images?p=java+duke&ni=20&ei=UTF-8&fr=yfp-t-501&xargs=0&pstart=1&b=201&w=123&h=128&imgurl=student.educ.umu.se/~sanann00/images/duke.jpg&rurl=http://student.educ.umu.se/~sanann00/dependencies.html&size=9.9kB&name=duke.jpg&p=java+duke&type=JPG&oid=581f3667c98a4ad2&no=213&tt=1,234&sigr=11mg3psqe&sigi=11df3i068&sigb=13bus36b1

  • 8/19/2019 GUI-Based Event Driven Programming

    24/58

    Specifies that the program should listen for events The keyword this enables the program to refer toitself

    When the user interacts with a GUI component anevent is sent to the program

    Example:button1.addActionListener (this);

    When the user press the button, an event is sent to the appletindicating that an action was performed by the user and callsthe method actionPerformed to process user interaction.

    http://rds.yahoo.com/_ylt=A0S020u53_9I3PIADn2JzbkF;_ylu=X3oDMTBzZzgwMmhjBHBvcwMyMTMEc2VjA3NyBHZ0aWQDSTA5N18xMTg-/SIG=1i42g6nfg/EXP=1224814905/**http:/images.search.yahoo.com/images/view?back=http://images.search.yahoo.com/search/images?p=java+duke&ni=20&ei=UTF-8&fr=yfp-t-501&xargs=0&pstart=1&b=201&w=123&h=128&imgurl=student.educ.umu.se/~sanann00/images/duke.jpg&rurl=http://student.educ.umu.se/~sanann00/dependencies.html&size=9.9kB&name=duke.jpg&p=java+duke&type=JPG&oid=581f3667c98a4ad2&no=213&tt=1,234&sigr=11mg3psqe&sigi=11df3i068&sigb=13bus36b1http://rds.yahoo.com/_ylt=A0S020u53_9I3PIADn2JzbkF;_ylu=X3oDMTBzZzgwMmhjBHBvcwMyMTMEc2VjA3NyBHZ0aWQDSTA5N18xMTg-/SIG=1i42g6nfg/EXP=1224814905/**http:/images.search.yahoo.com/images/view?back=http://images.search.yahoo.com/search/images?p=java+duke&ni=20&ei=UTF-8&fr=yfp-t-501&xargs=0&pstart=1&b=201&w=123&h=128&imgurl=student.educ.umu.se/~sanann00/images/duke.jpg&rurl=http://student.educ.umu.se/~sanann00/dependencies.html&size=9.9kB&name=duke.jpg&p=java+duke&type=JPG&oid=581f3667c98a4ad2&no=213&tt=1,234&sigr=11mg3psqe&sigi=11df3i068&sigb=13bus36b1

  • 8/19/2019 GUI-Based Event Driven Programming

    25/58

    Used to specify the tool tip that is displayedautomatically when the user positions the mousecursor over the label in the GUI

    Syntax :Object of GUI .setToolTipText (“Text”);

    Example:

    labek1.setToolTipText("DLSU - Dasmariñas");

    http://rds.yahoo.com/_ylt=A0S020u53_9I3PIADn2JzbkF;_ylu=X3oDMTBzZzgwMmhjBHBvcwMyMTMEc2VjA3NyBHZ0aWQDSTA5N18xMTg-/SIG=1i42g6nfg/EXP=1224814905/**http:/images.search.yahoo.com/images/view?back=http://images.search.yahoo.com/search/images?p=java+duke&ni=20&ei=UTF-8&fr=yfp-t-501&xargs=0&pstart=1&b=201&w=123&h=128&imgurl=student.educ.umu.se/~sanann00/images/duke.jpg&rurl=http://student.educ.umu.se/~sanann00/dependencies.html&size=9.9kB&name=duke.jpg&p=java+duke&type=JPG&oid=581f3667c98a4ad2&no=213&tt=1,234&sigr=11mg3psqe&sigi=11df3i068&sigb=13bus36b1http://rds.yahoo.com/_ylt=A0S020u53_9I3PIADn2JzbkF;_ylu=X3oDMTBzZzgwMmhjBHBvcwMyMTMEc2VjA3NyBHZ0aWQDSTA5N18xMTg-/SIG=1i42g6nfg/EXP=1224814905/**http:/images.search.yahoo.com/images/view?back=http://images.search.yahoo.com/search/images?p=java+duke&ni=20&ei=UTF-8&fr=yfp-t-501&xargs=0&pstart=1&b=201&w=123&h=128&imgurl=student.educ.umu.se/~sanann00/images/duke.jpg&rurl=http://student.educ.umu.se/~sanann00/dependencies.html&size=9.9kB&name=duke.jpg&p=java+duke&type=JPG&oid=581f3667c98a4ad2&no=213&tt=1,234&sigr=11mg3psqe&sigi=11df3i068&sigb=13bus36b1

  • 8/19/2019 GUI-Based Event Driven Programming

    26/58

    Used to get input from the JTextField

    Syntax:object of JTextField.getText()

    Example:

    JTextField field1;int num;num = Integer.parseInt (field1.getText ( ));

    Note:

    Any input from a JTextField is a String.

    http://rds.yahoo.com/_ylt=A0S020u53_9I3PIADn2JzbkF;_ylu=X3oDMTBzZzgwMmhjBHBvcwMyMTMEc2VjA3NyBHZ0aWQDSTA5N18xMTg-/SIG=1i42g6nfg/EXP=1224814905/**http:/images.search.yahoo.com/images/view?back=http://images.search.yahoo.com/search/images?p=java+duke&ni=20&ei=UTF-8&fr=yfp-t-501&xargs=0&pstart=1&b=201&w=123&h=128&imgurl=student.educ.umu.se/~sanann00/images/duke.jpg&rurl=http://student.educ.umu.se/~sanann00/dependencies.html&size=9.9kB&name=duke.jpg&p=java+duke&type=JPG&oid=581f3667c98a4ad2&no=213&tt=1,234&sigr=11mg3psqe&sigi=11df3i068&sigb=13bus36b1http://rds.yahoo.com/_ylt=A0S020u53_9I3PIADn2JzbkF;_ylu=X3oDMTBzZzgwMmhjBHBvcwMyMTMEc2VjA3NyBHZ0aWQDSTA5N18xMTg-/SIG=1i42g6nfg/EXP=1224814905/**http:/images.search.yahoo.com/images/view?back=http://images.search.yahoo.com/search/images?p=java+duke&ni=20&ei=UTF-8&fr=yfp-t-501&xargs=0&pstart=1&b=201&w=123&h=128&imgurl=student.educ.umu.se/~sanann00/images/duke.jpg&rurl=http://student.educ.umu.se/~sanann00/dependencies.html&size=9.9kB&name=duke.jpg&p=java+duke&type=JPG&oid=581f3667c98a4ad2&no=213&tt=1,234&sigr=11mg3psqe&sigi=11df3i068&sigb=13bus36b1

  • 8/19/2019 GUI-Based Event Driven Programming

    27/58

    Used to display string of information on the JTextField

    Syntax:

    object of JTextField.setText (“String to display”);

    Example:field1.setText (“De La Salle”);

    Note:

    JTextField can only display String.

    http://rds.yahoo.com/_ylt=A0S020u53_9I3PIADn2JzbkF;_ylu=X3oDMTBzZzgwMmhjBHBvcwMyMTMEc2VjA3NyBHZ0aWQDSTA5N18xMTg-/SIG=1i42g6nfg/EXP=1224814905/**http:/images.search.yahoo.com/images/view?back=http://images.search.yahoo.com/search/images?p=java+duke&ni=20&ei=UTF-8&fr=yfp-t-501&xargs=0&pstart=1&b=201&w=123&h=128&imgurl=student.educ.umu.se/~sanann00/images/duke.jpg&rurl=http://student.educ.umu.se/~sanann00/dependencies.html&size=9.9kB&name=duke.jpg&p=java+duke&type=JPG&oid=581f3667c98a4ad2&no=213&tt=1,234&sigr=11mg3psqe&sigi=11df3i068&sigb=13bus36b1http://rds.yahoo.com/_ylt=A0S020u53_9I3PIADn2JzbkF;_ylu=X3oDMTBzZzgwMmhjBHBvcwMyMTMEc2VjA3NyBHZ0aWQDSTA5N18xMTg-/SIG=1i42g6nfg/EXP=1224814905/**http:/images.search.yahoo.com/images/view?back=http://images.search.yahoo.com/search/images?p=java+duke&ni=20&ei=UTF-8&fr=yfp-t-501&xargs=0&pstart=1&b=201&w=123&h=128&imgurl=student.educ.umu.se/~sanann00/images/duke.jpg&rurl=http://student.educ.umu.se/~sanann00/dependencies.html&size=9.9kB&name=duke.jpg&p=java+duke&type=JPG&oid=581f3667c98a4ad2&no=213&tt=1,234&sigr=11mg3psqe&sigi=11df3i068&sigb=13bus36b1

  • 8/19/2019 GUI-Based Event Driven Programming

    28/58

    Used to convert integer values to string.

    JTextField can ONLY display Strings.

    Example:

    num = 10;field1.setText(Integer.toString (num));

    http://rds.yahoo.com/_ylt=A0S020u53_9I3PIADn2JzbkF;_ylu=X3oDMTBzZzgwMmhjBHBvcwMyMTMEc2VjA3NyBHZ0aWQDSTA5N18xMTg-/SIG=1i42g6nfg/EXP=1224814905/**http:/images.search.yahoo.com/images/view?back=http://images.search.yahoo.com/search/images?p=java+duke&ni=20&ei=UTF-8&fr=yfp-t-501&xargs=0&pstart=1&b=201&w=123&h=128&imgurl=student.educ.umu.se/~sanann00/images/duke.jpg&rurl=http://student.educ.umu.se/~sanann00/dependencies.html&size=9.9kB&name=duke.jpg&p=java+duke&type=JPG&oid=581f3667c98a4ad2&no=213&tt=1,234&sigr=11mg3psqe&sigi=11df3i068&sigb=13bus36b1http://rds.yahoo.com/_ylt=A0S020u53_9I3PIADn2JzbkF;_ylu=X3oDMTBzZzgwMmhjBHBvcwMyMTMEc2VjA3NyBHZ0aWQDSTA5N18xMTg-/SIG=1i42g6nfg/EXP=1224814905/**http:/images.search.yahoo.com/images/view?back=http://images.search.yahoo.com/search/images?p=java+duke&ni=20&ei=UTF-8&fr=yfp-t-501&xargs=0&pstart=1&b=201&w=123&h=128&imgurl=student.educ.umu.se/~sanann00/images/duke.jpg&rurl=http://student.educ.umu.se/~sanann00/dependencies.html&size=9.9kB&name=duke.jpg&p=java+duke&type=JPG&oid=581f3667c98a4ad2&no=213&tt=1,234&sigr=11mg3psqe&sigi=11df3i068&sigb=13bus36b1

  • 8/19/2019 GUI-Based Event Driven Programming

    29/58

    Used to convert numeric values to string.

    Example:

    num = 10;field1.setText(String.valueOf (num));

    http://rds.yahoo.com/_ylt=A0S020u53_9I3PIADn2JzbkF;_ylu=X3oDMTBzZzgwMmhjBHBvcwMyMTMEc2VjA3NyBHZ0aWQDSTA5N18xMTg-/SIG=1i42g6nfg/EXP=1224814905/**http:/images.search.yahoo.com/images/view?back=http://images.search.yahoo.com/search/images?p=java+duke&ni=20&ei=UTF-8&fr=yfp-t-501&xargs=0&pstart=1&b=201&w=123&h=128&imgurl=student.educ.umu.se/~sanann00/images/duke.jpg&rurl=http://student.educ.umu.se/~sanann00/dependencies.html&size=9.9kB&name=duke.jpg&p=java+duke&type=JPG&oid=581f3667c98a4ad2&no=213&tt=1,234&sigr=11mg3psqe&sigi=11df3i068&sigb=13bus36b1http://rds.yahoo.com/_ylt=A0S020u53_9I3PIADn2JzbkF;_ylu=X3oDMTBzZzgwMmhjBHBvcwMyMTMEc2VjA3NyBHZ0aWQDSTA5N18xMTg-/SIG=1i42g6nfg/EXP=1224814905/**http:/images.search.yahoo.com/images/view?back=http://images.search.yahoo.com/search/images?p=java+duke&ni=20&ei=UTF-8&fr=yfp-t-501&xargs=0&pstart=1&b=201&w=123&h=128&imgurl=student.educ.umu.se/~sanann00/images/duke.jpg&rurl=http://student.educ.umu.se/~sanann00/dependencies.html&size=9.9kB&name=duke.jpg&p=java+duke&type=JPG&oid=581f3667c98a4ad2&no=213&tt=1,234&sigr=11mg3psqe&sigi=11df3i068&sigb=13bus36b1

  • 8/19/2019 GUI-Based Event Driven Programming

    30/58

    From java.awt

    Used to define the background color andforeground color that will be used by the GUIcomponent.

    http://rds.yahoo.com/_ylt=A0S020u53_9I3PIADn2JzbkF;_ylu=X3oDMTBzZzgwMmhjBHBvcwMyMTMEc2VjA3NyBHZ0aWQDSTA5N18xMTg-/SIG=1i42g6nfg/EXP=1224814905/**http:/images.search.yahoo.com/images/view?back=http://images.search.yahoo.com/search/images?p=java+duke&ni=20&ei=UTF-8&fr=yfp-t-501&xargs=0&pstart=1&b=201&w=123&h=128&imgurl=student.educ.umu.se/~sanann00/images/duke.jpg&rurl=http://student.educ.umu.se/~sanann00/dependencies.html&size=9.9kB&name=duke.jpg&p=java+duke&type=JPG&oid=581f3667c98a4ad2&no=213&tt=1,234&sigr=11mg3psqe&sigi=11df3i068&sigb=13bus36b1http://rds.yahoo.com/_ylt=A0S020u53_9I3PIADn2JzbkF;_ylu=X3oDMTBzZzgwMmhjBHBvcwMyMTMEc2VjA3NyBHZ0aWQDSTA5N18xMTg-/SIG=1i42g6nfg/EXP=1224814905/**http:/images.search.yahoo.com/images/view?back=http://images.search.yahoo.com/search/images?p=java+duke&ni=20&ei=UTF-8&fr=yfp-t-501&xargs=0&pstart=1&b=201&w=123&h=128&imgurl=student.educ.umu.se/~sanann00/images/duke.jpg&rurl=http://student.educ.umu.se/~sanann00/dependencies.html&size=9.9kB&name=duke.jpg&p=java+duke&type=JPG&oid=581f3667c98a4ad2&no=213&tt=1,234&sigr=11mg3psqe&sigi=11df3i068&sigb=13bus36b1

  • 8/19/2019 GUI-Based Event Driven Programming

    31/58

  • 8/19/2019 GUI-Based Event Driven Programming

    32/58

    black blue

    cyan darkGray gray green lightGray

    magenta pink orange red white yellow

    http://rds.yahoo.com/_ylt=A0S020u53_9I3PIADn2JzbkF;_ylu=X3oDMTBzZzgwMmhjBHBvcwMyMTMEc2VjA3NyBHZ0aWQDSTA5N18xMTg-/SIG=1i42g6nfg/EXP=1224814905/**http:/images.search.yahoo.com/images/view?back=http://images.search.yahoo.com/search/images?p=java+duke&ni=20&ei=UTF-8&fr=yfp-t-501&xargs=0&pstart=1&b=201&w=123&h=128&imgurl=student.educ.umu.se/~sanann00/images/duke.jpg&rurl=http://student.educ.umu.se/~sanann00/dependencies.html&size=9.9kB&name=duke.jpg&p=java+duke&type=JPG&oid=581f3667c98a4ad2&no=213&tt=1,234&sigr=11mg3psqe&sigi=11df3i068&sigb=13bus36b1http://rds.yahoo.com/_ylt=A0S020u53_9I3PIADn2JzbkF;_ylu=X3oDMTBzZzgwMmhjBHBvcwMyMTMEc2VjA3NyBHZ0aWQDSTA5N18xMTg-/SIG=1i42g6nfg/EXP=1224814905/**http:/images.search.yahoo.com/images/view?back=http://images.search.yahoo.com/search/images?p=java+duke&ni=20&ei=UTF-8&fr=yfp-t-501&xargs=0&pstart=1&b=201&w=123&h=128&imgurl=student.educ.umu.se/~sanann00/images/duke.jpg&rurl=http://student.educ.umu.se/~sanann00/dependencies.html&size=9.9kB&name=duke.jpg&p=java+duke&type=JPG&oid=581f3667c98a4ad2&no=213&tt=1,234&sigr=11mg3psqe&sigi=11df3i068&sigb=13bus36b1

  • 8/19/2019 GUI-Based Event Driven Programming

    33/58

    Syntax 2:

    object.setBackground(new Color (R,G,B));

    Examples:

    c.setBackground(new Color(0,128,64));field1.setBackground(new Color(0,128,64));

    Note: RGB values are the RED, GREEN and BLUEcomponents of a Color (values are from 0 to 255)

    http://rds.yahoo.com/_ylt=A0S020u53_9I3PIADn2JzbkF;_ylu=X3oDMTBzZzgwMmhjBHBvcwMyMTMEc2VjA3NyBHZ0aWQDSTA5N18xMTg-/SIG=1i42g6nfg/EXP=1224814905/**http:/images.search.yahoo.com/images/view?back=http://images.search.yahoo.com/search/images?p=java+duke&ni=20&ei=UTF-8&fr=yfp-t-501&xargs=0&pstart=1&b=201&w=123&h=128&imgurl=student.educ.umu.se/~sanann00/images/duke.jpg&rurl=http://student.educ.umu.se/~sanann00/dependencies.html&size=9.9kB&name=duke.jpg&p=java+duke&type=JPG&oid=581f3667c98a4ad2&no=213&tt=1,234&sigr=11mg3psqe&sigi=11df3i068&sigb=13bus36b1http://rds.yahoo.com/_ylt=A0S020u53_9I3PIADn2JzbkF;_ylu=X3oDMTBzZzgwMmhjBHBvcwMyMTMEc2VjA3NyBHZ0aWQDSTA5N18xMTg-/SIG=1i42g6nfg/EXP=1224814905/**http:/images.search.yahoo.com/images/view?back=http://images.search.yahoo.com/search/images?p=java+duke&ni=20&ei=UTF-8&fr=yfp-t-501&xargs=0&pstart=1&b=201&w=123&h=128&imgurl=student.educ.umu.se/~sanann00/images/duke.jpg&rurl=http://student.educ.umu.se/~sanann00/dependencies.html&size=9.9kB&name=duke.jpg&p=java+duke&type=JPG&oid=581f3667c98a4ad2&no=213&tt=1,234&sigr=11mg3psqe&sigi=11df3i068&sigb=13bus36b1

  • 8/19/2019 GUI-Based Event Driven Programming

    34/58

    Defines the foreground color of the GUIcomponents.

    Syntax 1:

    object.setForeground(Color.predefined color);

    Examples:

    c. setForeground(Color.yellow);field1. setForeground(Color.blue);

    http://rds.yahoo.com/_ylt=A0S020u53_9I3PIADn2JzbkF;_ylu=X3oDMTBzZzgwMmhjBHBvcwMyMTMEc2VjA3NyBHZ0aWQDSTA5N18xMTg-/SIG=1i42g6nfg/EXP=1224814905/**http:/images.search.yahoo.com/images/view?back=http://images.search.yahoo.com/search/images?p=java+duke&ni=20&ei=UTF-8&fr=yfp-t-501&xargs=0&pstart=1&b=201&w=123&h=128&imgurl=student.educ.umu.se/~sanann00/images/duke.jpg&rurl=http://student.educ.umu.se/~sanann00/dependencies.html&size=9.9kB&name=duke.jpg&p=java+duke&type=JPG&oid=581f3667c98a4ad2&no=213&tt=1,234&sigr=11mg3psqe&sigi=11df3i068&sigb=13bus36b1http://rds.yahoo.com/_ylt=A0S020u53_9I3PIADn2JzbkF;_ylu=X3oDMTBzZzgwMmhjBHBvcwMyMTMEc2VjA3NyBHZ0aWQDSTA5N18xMTg-/SIG=1i42g6nfg/EXP=1224814905/**http:/images.search.yahoo.com/images/view?back=http://images.search.yahoo.com/search/images?p=java+duke&ni=20&ei=UTF-8&fr=yfp-t-501&xargs=0&pstart=1&b=201&w=123&h=128&imgurl=student.educ.umu.se/~sanann00/images/duke.jpg&rurl=http://student.educ.umu.se/~sanann00/dependencies.html&size=9.9kB&name=duke.jpg&p=java+duke&type=JPG&oid=581f3667c98a4ad2&no=213&tt=1,234&sigr=11mg3psqe&sigi=11df3i068&sigb=13bus36b1

  • 8/19/2019 GUI-Based Event Driven Programming

    35/58

    Syntax 2:

    object.setForeground(new Color (R,G,B));

    Examples:

    c.setForeground(new Color(0,128,64));field1.setForeground(new Color(0,128,64));

    Note: 0,0,0 is black255, 255, 255 is white

    http://rds.yahoo.com/_ylt=A0S020u53_9I3PIADn2JzbkF;_ylu=X3oDMTBzZzgwMmhjBHBvcwMyMTMEc2VjA3NyBHZ0aWQDSTA5N18xMTg-/SIG=1i42g6nfg/EXP=1224814905/**http:/images.search.yahoo.com/images/view?back=http://images.search.yahoo.com/search/images?p=java+duke&ni=20&ei=UTF-8&fr=yfp-t-501&xargs=0&pstart=1&b=201&w=123&h=128&imgurl=student.educ.umu.se/~sanann00/images/duke.jpg&rurl=http://student.educ.umu.se/~sanann00/dependencies.html&size=9.9kB&name=duke.jpg&p=java+duke&type=JPG&oid=581f3667c98a4ad2&no=213&tt=1,234&sigr=11mg3psqe&sigi=11df3i068&sigb=13bus36b1http://rds.yahoo.com/_ylt=A0S020u53_9I3PIADn2JzbkF;_ylu=X3oDMTBzZzgwMmhjBHBvcwMyMTMEc2VjA3NyBHZ0aWQDSTA5N18xMTg-/SIG=1i42g6nfg/EXP=1224814905/**http:/images.search.yahoo.com/images/view?back=http://images.search.yahoo.com/search/images?p=java+duke&ni=20&ei=UTF-8&fr=yfp-t-501&xargs=0&pstart=1&b=201&w=123&h=128&imgurl=student.educ.umu.se/~sanann00/images/duke.jpg&rurl=http://student.educ.umu.se/~sanann00/dependencies.html&size=9.9kB&name=duke.jpg&p=java+duke&type=JPG&oid=581f3667c98a4ad2&no=213&tt=1,234&sigr=11mg3psqe&sigi=11df3i068&sigb=13bus36b1

  • 8/19/2019 GUI-Based Event Driven Programming

    36/58

    From java.awt.

    Use to define the font name, font style and font size of the textthat will be used by a GUI component.

    Syntax:

    Font = new Font ( "Font Name", Font Style, Font Size);

    Example:

    Font font = new Font ("Trebuchet MS", Font.BOLD, 24);

    Note:

    Available Font Style are: Font.BOLD, Font.ITALIC, Font.PLAIN

    http://rds.yahoo.com/_ylt=A0S020u53_9I3PIADn2JzbkF;_ylu=X3oDMTBzZzgwMmhjBHBvcwMyMTMEc2VjA3NyBHZ0aWQDSTA5N18xMTg-/SIG=1i42g6nfg/EXP=1224814905/**http:/images.search.yahoo.com/images/view?back=http://images.search.yahoo.com/search/images?p=java+duke&ni=20&ei=UTF-8&fr=yfp-t-501&xargs=0&pstart=1&b=201&w=123&h=128&imgurl=student.educ.umu.se/~sanann00/images/duke.jpg&rurl=http://student.educ.umu.se/~sanann00/dependencies.html&size=9.9kB&name=duke.jpg&p=java+duke&type=JPG&oid=581f3667c98a4ad2&no=213&tt=1,234&sigr=11mg3psqe&sigi=11df3i068&sigb=13bus36b1http://rds.yahoo.com/_ylt=A0S020u53_9I3PIADn2JzbkF;_ylu=X3oDMTBzZzgwMmhjBHBvcwMyMTMEc2VjA3NyBHZ0aWQDSTA5N18xMTg-/SIG=1i42g6nfg/EXP=1224814905/**http:/images.search.yahoo.com/images/view?back=http://images.search.yahoo.com/search/images?p=java+duke&ni=20&ei=UTF-8&fr=yfp-t-501&xargs=0&pstart=1&b=201&w=123&h=128&imgurl=student.educ.umu.se/~sanann00/images/duke.jpg&rurl=http://student.educ.umu.se/~sanann00/dependencies.html&size=9.9kB&name=duke.jpg&p=java+duke&type=JPG&oid=581f3667c98a4ad2&no=213&tt=1,234&sigr=11mg3psqe&sigi=11df3i068&sigb=13bus36b1

  • 8/19/2019 GUI-Based Event Driven Programming

    37/58

    Font.BOLD 1

    Font.ITALIC 2

    Font.PLAIN 0

    Font.BOLD + Font.ITALIC 3

    http://rds.yahoo.com/_ylt=A0S020u53_9I3PIADn2JzbkF;_ylu=X3oDMTBzZzgwMmhjBHBvcwMyMTMEc2VjA3NyBHZ0aWQDSTA5N18xMTg-/SIG=1i42g6nfg/EXP=1224814905/**http:/images.search.yahoo.com/images/view?back=http://images.search.yahoo.com/search/images?p=java+duke&ni=20&ei=UTF-8&fr=yfp-t-501&xargs=0&pstart=1&b=201&w=123&h=128&imgurl=student.educ.umu.se/~sanann00/images/duke.jpg&rurl=http://student.educ.umu.se/~sanann00/dependencies.html&size=9.9kB&name=duke.jpg&p=java+duke&type=JPG&oid=581f3667c98a4ad2&no=213&tt=1,234&sigr=11mg3psqe&sigi=11df3i068&sigb=13bus36b1http://rds.yahoo.com/_ylt=A0S020u53_9I3PIADn2JzbkF;_ylu=X3oDMTBzZzgwMmhjBHBvcwMyMTMEc2VjA3NyBHZ0aWQDSTA5N18xMTg-/SIG=1i42g6nfg/EXP=1224814905/**http:/images.search.yahoo.com/images/view?back=http://images.search.yahoo.com/search/images?p=java+duke&ni=20&ei=UTF-8&fr=yfp-t-501&xargs=0&pstart=1&b=201&w=123&h=128&imgurl=student.educ.umu.se/~sanann00/images/duke.jpg&rurl=http://student.educ.umu.se/~sanann00/dependencies.html&size=9.9kB&name=duke.jpg&p=java+duke&type=JPG&oid=581f3667c98a4ad2&no=213&tt=1,234&sigr=11mg3psqe&sigi=11df3i068&sigb=13bus36b1

  • 8/19/2019 GUI-Based Event Driven Programming

    38/58

    Use to set the Font defined by the Font class.

    Syntax:

    Object of GUI.setFont(object of Font Class);

    Example:

    Font font = new Font ("Trebuchet MS", Font.BOLD, 24);Label1.setFont(font);

    http://rds.yahoo.com/_ylt=A0S020u53_9I3PIADn2JzbkF;_ylu=X3oDMTBzZzgwMmhjBHBvcwMyMTMEc2VjA3NyBHZ0aWQDSTA5N18xMTg-/SIG=1i42g6nfg/EXP=1224814905/**http:/images.search.yahoo.com/images/view?back=http://images.search.yahoo.com/search/images?p=java+duke&ni=20&ei=UTF-8&fr=yfp-t-501&xargs=0&pstart=1&b=201&w=123&h=128&imgurl=student.educ.umu.se/~sanann00/images/duke.jpg&rurl=http://student.educ.umu.se/~sanann00/dependencies.html&size=9.9kB&name=duke.jpg&p=java+duke&type=JPG&oid=581f3667c98a4ad2&no=213&tt=1,234&sigr=11mg3psqe&sigi=11df3i068&sigb=13bus36b1http://rds.yahoo.com/_ylt=A0S020u53_9I3PIADn2JzbkF;_ylu=X3oDMTBzZzgwMmhjBHBvcwMyMTMEc2VjA3NyBHZ0aWQDSTA5N18xMTg-/SIG=1i42g6nfg/EXP=1224814905/**http:/images.search.yahoo.com/images/view?back=http://images.search.yahoo.com/search/images?p=java+duke&ni=20&ei=UTF-8&fr=yfp-t-501&xargs=0&pstart=1&b=201&w=123&h=128&imgurl=student.educ.umu.se/~sanann00/images/duke.jpg&rurl=http://student.educ.umu.se/~sanann00/dependencies.html&size=9.9kB&name=duke.jpg&p=java+duke&type=JPG&oid=581f3667c98a4ad2&no=213&tt=1,234&sigr=11mg3psqe&sigi=11df3i068&sigb=13bus36b1

  • 8/19/2019 GUI-Based Event Driven Programming

    39/58

    import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JTextField; import javax.swing.JButton;

    import java.awt.FlowLayout; import java.awt.Container; import java.awt.Font; import java.awt.Color;

    import java.awt.event.ActionListener; import java.awt.event.ActionEvent;

    http://rds.yahoo.com/_ylt=A0S020u53_9I3PIADn2JzbkF;_ylu=X3oDMTBzZzgwMmhjBHBvcwMyMTMEc2VjA3NyBHZ0aWQDSTA5N18xMTg-/SIG=1i42g6nfg/EXP=1224814905/**http:/images.search.yahoo.com/images/view?back=http://images.search.yahoo.com/search/images?p=java+duke&ni=20&ei=UTF-8&fr=yfp-t-501&xargs=0&pstart=1&b=201&w=123&h=128&imgurl=student.educ.umu.se/~sanann00/images/duke.jpg&rurl=http://student.educ.umu.se/~sanann00/dependencies.html&size=9.9kB&name=duke.jpg&p=java+duke&type=JPG&oid=581f3667c98a4ad2&no=213&tt=1,234&sigr=11mg3psqe&sigi=11df3i068&sigb=13bus36b1http://rds.yahoo.com/_ylt=A0S020u53_9I3PIADn2JzbkF;_ylu=X3oDMTBzZzgwMmhjBHBvcwMyMTMEc2VjA3NyBHZ0aWQDSTA5N18xMTg-/SIG=1i42g6nfg/EXP=1224814905/**http:/images.search.yahoo.com/images/view?back=http://images.search.yahoo.com/search/images?p=java+duke&ni=20&ei=UTF-8&fr=yfp-t-501&xargs=0&pstart=1&b=201&w=123&h=128&imgurl=student.educ.umu.se/~sanann00/images/duke.jpg&rurl=http://student.educ.umu.se/~sanann00/dependencies.html&size=9.9kB&name=duke.jpg&p=java+duke&type=JPG&oid=581f3667c98a4ad2&no=213&tt=1,234&sigr=11mg3psqe&sigi=11df3i068&sigb=13bus36b1

  • 8/19/2019 GUI-Based Event Driven Programming

    40/58

    Package: javax.swing Consists of a label positioned beside a circle;you can click the cirlce to select or deselect

    Syntax 1:

    //no label, unselected Example:

  • 8/19/2019 GUI-Based Event Driven Programming

    41/58

    Syntax 2:

    Example:

    Syntax 3:

    //with label, selected Example:

  • 8/19/2019 GUI-Based Event Driven Programming

    42/58

  • 8/19/2019 GUI-Based Event Driven Programming

    43/58

    Syntax 2:

    Example:

    Syntax 3:

    //with label, selected Example:

  • 8/19/2019 GUI-Based Event Driven Programming

    44/58

    JCheckBox and JRadioButton have the sameset of properties and methods.

    Methods and properties that can be appliedto JRadioButton object can also be applied to

    JCheckBox object.

  • 8/19/2019 GUI-Based Event Driven Programming

    45/58

  • 8/19/2019 GUI-Based Event Driven Programming

    46/58

    sets the state of the JCheckBox to true forselected or false for unselected

    Syntax:object.setSelected(boolean);

    Example:

  • 8/19/2019 GUI-Based Event Driven Programming

    47/58

  • 8/19/2019 GUI-Based Event Driven Programming

    48/58

    Determines which object generated the event

  • 8/19/2019 GUI-Based Event Driven Programming

    49/58

    Determines whether the event was a selectionor a deselection

    Returns an integer that is equal to two classvariables:◦ ItemEvent.SELECTED◦ ItemEvent.DESELECTED

  • 8/19/2019 GUI-Based Event Driven Programming

    50/58

    Package: javax.swing Used to groups several components, such as JCheckBoxes, so a user can select only one ata time.

    When you groupd JCheckBox objects, all ofthe other JCheckBoxes are automaticallyturned off when the user selects any onecheckbox.

  • 8/19/2019 GUI-Based Event Driven Programming

    51/58

    Syntax:ButtonGroup object = new ButtonGroup();GUI_object.add(buttonGroup_object);

    Example:

  • 8/19/2019 GUI-Based Event Driven Programming

    52/58

    Method of JList which is used to determine the number of items that are visible in the list.

    Example:

    colorList.setVisibleRowCount(5);

    5 rows are initially displayed

    http://rds.yahoo.com/_ylt=A0S020u53_9I3PIADn2JzbkF;_ylu=X3oDMTBzZzgwMmhjBHBvcwMyMTMEc2VjA3NyBHZ0aWQDSTA5N18xMTg-/SIG=1i42g6nfg/EXP=1224814905/**http:/images.search.yahoo.com/images/view?back=http://images.search.yahoo.com/search/images?p=java+duke&ni=20&ei=UTF-8&fr=yfp-t-501&xargs=0&pstart=1&b=201&w=123&h=128&imgurl=student.educ.umu.se/~sanann00/images/duke.jpg&rurl=http://student.educ.umu.se/~sanann00/dependencies.html&size=9.9kB&name=duke.jpg&p=java+duke&type=JPG&oid=581f3667c98a4ad2&no=213&tt=1,234&sigr=11mg3psqe&sigi=11df3i068&sigb=13bus36b1http://rds.yahoo.com/_ylt=A0S020u53_9I3PIADn2JzbkF;_ylu=X3oDMTBzZzgwMmhjBHBvcwMyMTMEc2VjA3NyBHZ0aWQDSTA5N18xMTg-/SIG=1i42g6nfg/EXP=1224814905/**http:/images.search.yahoo.com/images/view?back=http://images.search.yahoo.com/search/images?p=java+duke&ni=20&ei=UTF-8&fr=yfp-t-501&xargs=0&pstart=1&b=201&w=123&h=128&imgurl=student.educ.umu.se/~sanann00/images/duke.jpg&rurl=http://student.educ.umu.se/~sanann00/dependencies.html&size=9.9kB&name=duke.jpg&p=java+duke&type=JPG&oid=581f3667c98a4ad2&no=213&tt=1,234&sigr=11mg3psqe&sigi=11df3i068&sigb=13bus36b1

  • 8/19/2019 GUI-Based Event Driven Programming

    53/58

    This method of JList specifies the list selection mode. Needs:import javax.swing.ListSelectionModel;

    Possible values are:

    1) SINGLE_SELECTION2) SINGLE_INTERVAL_SELECTION3) MULTIPLE_INTERVAL_SELCTION

    Example:colorList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);

    http://rds.yahoo.com/_ylt=A0S020u53_9I3PIADn2JzbkF;_ylu=X3oDMTBzZzgwMmhjBHBvcwMyMTMEc2VjA3NyBHZ0aWQDSTA5N18xMTg-/SIG=1i42g6nfg/EXP=1224814905/**http:/images.search.yahoo.com/images/view?back=http://images.search.yahoo.com/search/images?p=java+duke&ni=20&ei=UTF-8&fr=yfp-t-501&xargs=0&pstart=1&b=201&w=123&h=128&imgurl=student.educ.umu.se/~sanann00/images/duke.jpg&rurl=http://student.educ.umu.se/~sanann00/dependencies.html&size=9.9kB&name=duke.jpg&p=java+duke&type=JPG&oid=581f3667c98a4ad2&no=213&tt=1,234&sigr=11mg3psqe&sigi=11df3i068&sigb=13bus36b1http://rds.yahoo.com/_ylt=A0S020u53_9I3PIADn2JzbkF;_ylu=X3oDMTBzZzgwMmhjBHBvcwMyMTMEc2VjA3NyBHZ0aWQDSTA5N18xMTg-/SIG=1i42g6nfg/EXP=1224814905/**http:/images.search.yahoo.com/images/view?back=http://images.search.yahoo.com/search/images?p=java+duke&ni=20&ei=UTF-8&fr=yfp-t-501&xargs=0&pstart=1&b=201&w=123&h=128&imgurl=student.educ.umu.se/~sanann00/images/duke.jpg&rurl=http://student.educ.umu.se/~sanann00/dependencies.html&size=9.9kB&name=duke.jpg&p=java+duke&type=JPG&oid=581f3667c98a4ad2&no=213&tt=1,234&sigr=11mg3psqe&sigi=11df3i068&sigb=13bus36b1

  • 8/19/2019 GUI-Based Event Driven Programming

    54/58

    From javax.swing:

    import javax.swing.JScrollPane;

    Object that is used to provide the automaticscrolling functionality for the JList.

    Example:

    c.add(new JScrollPane(colorList));

    http://rds.yahoo.com/_ylt=A0S020u53_9I3PIADn2JzbkF;_ylu=X3oDMTBzZzgwMmhjBHBvcwMyMTMEc2VjA3NyBHZ0aWQDSTA5N18xMTg-/SIG=1i42g6nfg/EXP=1224814905/**http:/images.search.yahoo.com/images/view?back=http://images.search.yahoo.com/search/images?p=java+duke&ni=20&ei=UTF-8&fr=yfp-t-501&xargs=0&pstart=1&b=201&w=123&h=128&imgurl=student.educ.umu.se/~sanann00/images/duke.jpg&rurl=http://student.educ.umu.se/~sanann00/dependencies.html&size=9.9kB&name=duke.jpg&p=java+duke&type=JPG&oid=581f3667c98a4ad2&no=213&tt=1,234&sigr=11mg3psqe&sigi=11df3i068&sigb=13bus36b1http://rds.yahoo.com/_ylt=A0S020u53_9I3PIADn2JzbkF;_ylu=X3oDMTBzZzgwMmhjBHBvcwMyMTMEc2VjA3NyBHZ0aWQDSTA5N18xMTg-/SIG=1i42g6nfg/EXP=1224814905/**http:/images.search.yahoo.com/images/view?back=http://images.search.yahoo.com/search/images?p=java+duke&ni=20&ei=UTF-8&fr=yfp-t-501&xargs=0&pstart=1&b=201&w=123&h=128&imgurl=student.educ.umu.se/~sanann00/images/duke.jpg&rurl=http://student.educ.umu.se/~sanann00/dependencies.html&size=9.9kB&name=duke.jpg&p=java+duke&type=JPG&oid=581f3667c98a4ad2&no=213&tt=1,234&sigr=11mg3psqe&sigi=11df3i068&sigb=13bus36b1

  • 8/19/2019 GUI-Based Event Driven Programming

    55/58

    This is used to register an event thatimplements a ListSelectionListener.

    Calls the valueChanged methodautomatically to process the event.

    Example:

    colorList.addListSelectionListener(this);

    http://rds.yahoo.com/_ylt=A0S020u53_9I3PIADn2JzbkF;_ylu=X3oDMTBzZzgwMmhjBHBvcwMyMTMEc2VjA3NyBHZ0aWQDSTA5N18xMTg-/SIG=1i42g6nfg/EXP=1224814905/**http:/images.search.yahoo.com/images/view?back=http://images.search.yahoo.com/search/images?p=java+duke&ni=20&ei=UTF-8&fr=yfp-t-501&xargs=0&pstart=1&b=201&w=123&h=128&imgurl=student.educ.umu.se/~sanann00/images/duke.jpg&rurl=http://student.educ.umu.se/~sanann00/dependencies.html&size=9.9kB&name=duke.jpg&p=java+duke&type=JPG&oid=581f3667c98a4ad2&no=213&tt=1,234&sigr=11mg3psqe&sigi=11df3i068&sigb=13bus36b1http://rds.yahoo.com/_ylt=A0S020u53_9I3PIADn2JzbkF;_ylu=X3oDMTBzZzgwMmhjBHBvcwMyMTMEc2VjA3NyBHZ0aWQDSTA5N18xMTg-/SIG=1i42g6nfg/EXP=1224814905/**http:/images.search.yahoo.com/images/view?back=http://images.search.yahoo.com/search/images?p=java+duke&ni=20&ei=UTF-8&fr=yfp-t-501&xargs=0&pstart=1&b=201&w=123&h=128&imgurl=student.educ.umu.se/~sanann00/images/duke.jpg&rurl=http://student.educ.umu.se/~sanann00/dependencies.html&size=9.9kB&name=duke.jpg&p=java+duke&type=JPG&oid=581f3667c98a4ad2&no=213&tt=1,234&sigr=11mg3psqe&sigi=11df3i068&sigb=13bus36b1

  • 8/19/2019 GUI-Based Event Driven Programming

    56/58

    Returns the selected item;s index in the list.public void valueChanged (ListSelectionEvent e){if (colorList.getSelectedIndex() == 0)

    c.setBackground(Color.blue);}

    -OR-

    Color color[]= {Color.blue, Color.cyan, Color.green, Color.magenta};

    public void valueChanged (ListSelectionEvent e){c.setBackground(color[colorList.getSelectedIndex()]);}

    http://rds.yahoo.com/_ylt=A0S020u53_9I3PIADn2JzbkF;_ylu=X3oDMTBzZzgwMmhjBHBvcwMyMTMEc2VjA3NyBHZ0aWQDSTA5N18xMTg-/SIG=1i42g6nfg/EXP=1224814905/**http:/images.search.yahoo.com/images/view?back=http://images.search.yahoo.com/search/images?p=java+duke&ni=20&ei=UTF-8&fr=yfp-t-501&xargs=0&pstart=1&b=201&w=123&h=128&imgurl=student.educ.umu.se/~sanann00/images/duke.jpg&rurl=http://student.educ.umu.se/~sanann00/dependencies.html&size=9.9kB&name=duke.jpg&p=java+duke&type=JPG&oid=581f3667c98a4ad2&no=213&tt=1,234&sigr=11mg3psqe&sigi=11df3i068&sigb=13bus36b1http://rds.yahoo.com/_ylt=A0S020u53_9I3PIADn2JzbkF;_ylu=X3oDMTBzZzgwMmhjBHBvcwMyMTMEc2VjA3NyBHZ0aWQDSTA5N18xMTg-/SIG=1i42g6nfg/EXP=1224814905/**http:/images.search.yahoo.com/images/view?back=http://images.search.yahoo.com/search/images?p=java+duke&ni=20&ei=UTF-8&fr=yfp-t-501&xargs=0&pstart=1&b=201&w=123&h=128&imgurl=student.educ.umu.se/~sanann00/images/duke.jpg&rurl=http://student.educ.umu.se/~sanann00/dependencies.html&size=9.9kB&name=duke.jpg&p=java+duke&type=JPG&oid=581f3667c98a4ad2&no=213&tt=1,234&sigr=11mg3psqe&sigi=11df3i068&sigb=13bus36b1

  • 8/19/2019 GUI-Based Event Driven Programming

    57/58

  • 8/19/2019 GUI-Based Event Driven Programming

    58/58

    From java.awtImport java.awt.Toolkit;

    Example:

    setIconImage(Toolkit.getDefaultToolkit().getImage(“lasalle.jpg"));

    http://rds.yahoo.com/_ylt=A0S020u53_9I3PIADn2JzbkF;_ylu=X3oDMTBzZzgwMmhjBHBvcwMyMTMEc2VjA3NyBHZ0aWQDSTA5N18xMTg-/SIG=1i42g6nfg/EXP=1224814905/**http:/images.search.yahoo.com/images/view?back=http://images.search.yahoo.com/search/images?p=java+duke&ni=20&ei=UTF-8&fr=yfp-t-501&xargs=0&pstart=1&b=201&w=123&h=128&imgurl=student.educ.umu.se/~sanann00/images/duke.jpg&rurl=http://student.educ.umu.se/~sanann00/dependencies.html&size=9.9kB&name=duke.jpg&p=java+duke&type=JPG&oid=581f3667c98a4ad2&no=213&tt=1,234&sigr=11mg3psqe&sigi=11df3i068&sigb=13bus36b1http://rds.yahoo.com/_ylt=A0S020u53_9I3PIADn2JzbkF;_ylu=X3oDMTBzZzgwMmhjBHBvcwMyMTMEc2VjA3NyBHZ0aWQDSTA5N18xMTg-/SIG=1i42g6nfg/EXP=1224814905/**http:/images.search.yahoo.com/images/view?back=http://images.search.yahoo.com/search/images?p=java+duke&ni=20&ei=UTF-8&fr=yfp-t-501&xargs=0&pstart=1&b=201&w=123&h=128&imgurl=student.educ.umu.se/~sanann00/images/duke.jpg&rurl=http://student.educ.umu.se/~sanann00/dependencies.html&size=9.9kB&name=duke.jpg&p=java+duke&type=JPG&oid=581f3667c98a4ad2&no=213&tt=1,234&sigr=11mg3psqe&sigi=11df3i068&sigb=13bus36b1