CS 241 – Computer Programming II Lab

Slides:



Advertisements
Similar presentations
Java GUI building with the AWT. AWT (Abstract Window Toolkit) Present in all Java implementations Described in (almost) every Java textbook Adequate for.
Advertisements

Graphic User Interfaces Layout Managers Event Handling.
Fall 2007CS 225 Graphical User Interfaces Event Handling Appendix C.
Java Swing Recitation – 11/(20,21)/2008 CS 180 Department of Computer Science, Purdue University.
Event-Driven Programming Thus far, our programs have been executed one statement after the other However, many programs depend on user actions to dictate.
Java GUI Libraries Swing Programming. Swing Components Swing is a collection of libraries that contains primitive widgets or controls used for designing.
Event Handling Events and Listeners Timers and Animation.
Unit 12 Object-oriented programming: Event-driven programming for GUI Jin Sa.
GUI and Event-Driven Programming Recitation – 3/6/2009 CS 180 Department of Computer Science, Purdue University.
Chapter 121 Window Interfaces Using Swing Chapter 12.
CPSC150 JavaLynn Lambert CPSC150 Week 12 InheritanceInterfaces.
CS 241 – Computer Programming II Lab Kalpa Gunaratna –
CPSC150 Week 12 Graphical User Interfaces Chapter 11.
CS 240 – Computer Programming I Lab Kalpa Gunaratna –
CS 241 – Computer Programming II Lab Kalpa Gunaratna –
A.k.a. GUI’s.  If you want to discuss your Lab 2 grade come see me this week. ◦ Office: 436 ERB. One hour prior to class ◦ Open to Appointments MWF 
CS 241 – Computer Programming II Lab Kalpa Gunaratna –
CS 241 – Computer Programming II Lab Kalpa Gunaratna –
Java GUI building with the AWT. AWT (Abstract Window Toolkit) Present in all Java implementations Described in (almost) every Java textbook Adequate for.
Object Oriented Programming Ders 11: Interfaces Mustafa Emre İlal
MIT AITI 2003 Lecture 17. Swing - Part II. The Java Event Model Up until now, we have focused on GUI's to present information (with one exception) Up.
1 Event Driven Programs Rick Mercer. 2 So what happens next?  You can layout a real pretty GUI  You can click on buttons, enter text into a text field,
CS 241 – Computer Programming II Lab Kalpa Gunaratna –
GUI Components and Design Here we add one more component to our programs, JButtons –JButtons can only be inserted into JPanels (or JApplets) –Clicking.
Java Event Handling CSIS 3701: Advanced Object Oriented Programming.
(c) University of Washington07b-1 CSC 143 Java Events, Event Handlers, and Threads Reading: Ch. 17.
GUIs in Java Swing, Events CS2110, SW Development Methods Readings: MSD, Chapter 12 Lab Exercise.
– Advanced Programming P ROGRAMMING IN Lecture 21 Introduction to Swing.
Swing GUI Components You can create graphics components to place on your applet using classes available in the Swing package ( javax.swing ) Class names.
Chapter 12 1 TOPIC 13B l Buttons and Action Listeners Window Interfaces Using Swing Objects.
 2003 Joel C. Adams. All Rights Reserved. Calvin CollegeDept of Computer Science(1/15) MVC and Swing Joel Adams and Jeremy Frens Calvin College.
Layout Managers Arranges and lays out the GUI components on a container.
Event Driven Programming. Event-driven Programming In the early days of computing communication with the outside world was accomplished using a technique.
Object-Oriented Program Development Using Java: A Class-Centered Approach, Enhanced Edition.
CS 240 – Computer Programming I Lab Kalpa Gunaratna –
Java GUI. Graphical User Interface (GUI) a list a button a text field a label combo box checkbox.
CS 4244: Internet Programming User Interface Programming in Java 1.0.
Introduction to GUI in 1 Graphical User Interface 2 Nouf Almunyif.
Kim B. Bruce, Andrea Danyluk & Tom Murtagh Williams College † Partially supported by NSF CCLI grant DUE Java: An Eventful Approach An innovative.
Review_6 AWT, Swing, ActionListener, and Graphics.
1 Layout Managers Layout managers –Provided for arranging GUI components –Provide basic layout capabilities –Processes layout details –Programmer can concentrate.
1 Event Driven Programs Rick Mercer. 2 So what happens next?  You can layout a real pretty GUI  You can click on buttons, enter text into a text field,
CS 240 – Computer Programming I Lab Kalpa Gunaratna –
Chapter 10 - Writing Graphical User Interfaces1 Chapter 10 Writing Graphical User Interfaces.
OOSD Using Java GUI Programming. Components & Containers.
Swing GUI Components So far, we have written GUI applications which can ‘ draw ’. These applications are simple, yet typical of all Java GUI applications.
Lesson 28: More on the GUI button, frame and actions.
UQC117S2 Graphics Programming Lecture 2 Event Handling Program as a sequence of instructions Event -driven program Need to detect the event and carry out.
CSC 205 Programming II Lecture 7 AWT – Event Handling & Layout.
Java Swing and Events Chris North cs3724: HCI. Presentations nadine edwards, steve terhar Vote: UI Hall of Fame/Shame?
Event Driven (Asynchronous) Programming. Event handling in Unity Subclass a class that contains event handling methods, and then override those methods.
AWT Vs SWING. 2 AWT (Abstract Window Toolkit) Present in all Java implementations Described in most Java textbooks Adequate for many applications Uses.
Modular Event Handling
GUIs and Events Rick Mercer.
Introduction Many Java application use a graphical user interface or GUI (pronounced “gooey”). A GUI is a graphical window or windows that provide interaction.
Events and Event Handling
GUI building with the AWT
CS 241 – Computer Programming II Lab
CS 240 – Computer Programming I Lab
A First Look at GUI Applications
CS 240 – Computer Programming I Lab
Java GUI.
Graphical User Interface (pronounced "gooey")
Ellen Walker Hiram College
Event-driven programming for GUI
Course Outcomes of Advanced Java Programming AJP (17625, C603)
PC02 Term 1 Project Basic Messenger. PC02 Term 1 Project Basic Messenger.
GUI building with the AWT
Events, Event Handlers, and Threads
Graphical User Interface
Presentation transcript:

CS 241 – Computer Programming II Lab Kalpa Gunaratna – kalpa@knoesis.org http://knoesis.wright.edu/researchers/kalpa/

Contact Contact by e-mail Office hours kalpa@knoesis.org 376 Joshi Mondays & Wednesday 3:00 pm – 4:00 pm

ActionListener class If ActionListener class is exteneded, actionPerformed abstract method should be implemented. Whatever written inside this method will be executed when an action is performed relevant to this ActionListener. Any GUI component registered to an ActionListener will call this method when an action is performed on the GUI component (press mouse on , etc).

Register an action for a JButton. Example on how to implement ActionListener on a class called NewJFrame. Register an action for a JButton. Action handling in method public class NewJFrame extends JFrame implements ActionListener { JButton button = new JButton(); button.setText("Press"); button.setSize(20, 60); button.addActionListener(this); public void actionPerformed(ActionEvent e) { System.out.println("Mouse pressed"); }

Setting an layout for a panel Example : setting BorderLayout and adding button to south. jPanel.setLayout(new BorderLayout()); jPanel.add(BorderLayout.SOUTH, button);

In Lab Implement ActionListener and register it to a button. When button is pressed add balls to the panel. Button should be added to the south of the panel.

Post Lab Add two methods called as detectCollision and processCollision. Before you move balls, collisions should be detected and perform something as a results. Deleting one ball, change colors, etc.