PC02 Consolidation %WITTY_QUOTE%. PC02 Consolidation %WITTY_QUOTE%

Slides:



Advertisements
Similar presentations
Graphical User Interfaces
Advertisements

Unit 3 Graphical User Interface (GUI) Dr. Magdi AMER.
Graphic User Interfaces Layout Managers Event Handling.
F27SB2 Programming Languages
CMSC 341 Building Java GUIs. 09/26/2007 CMSC 341 GUI 2 Why Java GUI Development? Course is about Data Structures, not GUIs. We are giving you the opportunity.
Things to mention public static void main(String [] args) –The starting point for a free-standing Java application (i.e. one not run from the DrJava interactions.
Introduction to Java Classes, events, GUI’s. Understand: How to use TextPad How to define a class or object How to create a GUI interface How event-driven.
Event Driven Programming and GUIs Part 3 CS221 – 4/15/09.
Chapter 6 Graphical User Interface (GUI) and Object-Oriented Design (OOD)
Java GUI Libraries Swing Programming. Swing Components Swing is a collection of libraries that contains primitive widgets or controls used for designing.
Graphical User Interface (GUI) Programming III. Lecture Objectives Exploring more GUI programming elements in Java Using labels in GUIs Using colors to.
IEEM 110 Computing in Industrial Applications Basic User Interface in Java.
CPSC150 JavaLynn Lambert CPSC150 Week 12 InheritanceInterfaces.
PROGRAMMING REVIEW Lab 2 EECS 448 Dr Fengjun Li and Meenakshi Mishra.
Java Programming Chapter 10 Graphical User Interfaces.
Introduction to GUI Java offers a great number of pre-defined classes to support the development of graphical user interfaces –These are broken down into.
Peter Andreae Computer Science Victoria University of Wellington Copyright: Peter Andreae, Victoria University of Wellington User Interface COMP 112 #30.
Using the Netbeans GUI Builder. The Netbeans IDE provides a utility called the GUI Builder that assists you with creating Windows applications. The Netbeans.
MSc Workshop - © S. Kamin, U.Reddy Lect 5 – GUI Prog - 1 Lecture 5 – GUI Programming r Inner classes  this and super r Layout r Reading: m.
CIS 068 Welcome to CIS 083 ! Introduction to GUIs: JAVA Swing.
Applets and Frames CS 21a: Introduction to Computing I First Semester,
F27SB2 Software Development 2 Lecture 4: Java GUIs 3.
CSE 219 Computer Science III Graphical User Interface.
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.
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.
CS Lecture 01 Frames and Components and events Lynda Thomas
CSE115: Introduction to Computer Science I Dr. Carl Alphonce 343 Davis Hall
Field Trip #19 Animations with Java By Keith Lynn.
1 CSC111H Graphical User Interfaces (GUIs) Introduction GUIs in Java Understanding Events A Simple Application The Containment Hierarchy Layout Managers.
Graphic User Interface. Graphic User Interface (GUI) Most of us interact with computers using GUIs. GUIs are visual representations of the actions you.
Graphics and Event-Driven Programming in Java John C. Ramirez Department of Computer Science University of Pittsburgh.
Copyright © 2002, Systems and Computer Engineering, Carleton University c-Gui3.ppt * Object-Oriented Software Development Part 18-c Building.
MSc Workshop - © S. Kamin, U. ReddyLect 3 - GUI -1 Lecture 3 - Graphical User Interfaces r GUI toolkits in Java API r JFrame r GUI components.
Java Methods A & AB Object-Oriented Programming and Data Structures Maria Litvin ● Gary Litvin Copyright © 2006 by Maria Litvin, Gary Litvin, and Skylight.
Swing GUI Components You can create graphics components to place on your applet using classes available in the Swing package ( javax.swing ) Class names.
Timer class and inner classes. Processing timer events Timer is part of javax.swing helps manage activity over time Use it to set up a timer to generate.
CompSci 100E 35.1 Graphical User Interfaces: GUIs  Components  Flat Layouts  Hierarchical Layouts  Designing a GUI  Coding a GUI.
MT311 Java Application Development and Programming Languages Li Tak Sing ( 李德成 )
Concurrent Programming and Threads Threads Blocking a User Interface.
Object Oriented Programming Engr. M. Fahad Khan Lecturer, Software Engineering Department University of Engineering & Technology, Taxila.
University of Limerick1 Software Architecture Java Layout Managers.
Java GUI. Graphical User Interface (GUI) a list a button a text field a label combo box checkbox.
CompSci Event Handling. CompSci Event Handling The Plan  Sequential (Single Thread) Model  Event Model  Making the GUI interactive  Examples.
Introduction to GUI in 1 Graphical User Interface 2 Nouf Almunyif.
1 GUIs, Layout, Drawing Rick Mercer. 2 Event-Driven Programming with Graphical user Interfaces  Most applications have graphical user interfaces (GUIs)
1 Lecture 25 Listening to buttons and mice Quotes by Tony Hoare There are two ways of constructing a software design: (1) make it so simple that there.
Review_6 AWT, Swing, ActionListener, and Graphics.
Java layout managers. import java.awt.*; import java.awt.event.*; import javax.swing.*; class ButtonPanel extends JPanel implements ActionListener { public.
Ajmer Singh PGT(IP) JAVA IDE Programming - I. Ajmer Singh PGT(IP) GUI (Graphical User Interface) It is an interface that uses a graphic entities along.
Creating a GUI Class An example of class design using inheritance and interfaces.
GUI Tutorial 1. A Bit of Philosophy on what to Teach  There are numerous libraries, frameworks, options  Modern GUIs are often developed using XML (e.g.,
JAVA: An Introduction to Problem Solving & Programming, 6 th Ed. By Walter Savitch ISBN © 2012 Pearson Education, Inc., Upper Saddle River,
Chapter 10 - Writing Graphical User Interfaces1 Chapter 10 Writing Graphical User Interfaces.
Swing GUI Components So far, we have written GUI applications which can ‘ draw ’. These applications are simple, yet typical of all Java GUI applications.
Graphical User Interface (GUI)
5-1 GUIs and Events Rick Mercer. 5-2 Event-Driven Programming with Graphical user Interfaces  Most applications have graphical user interfaces to respond.
GUI.1 Graphical User Interfaces GUIs. GUI.2 The Plan Components Flat Layouts Hierarchical Layouts Designing a GUI Coding a GUI.
Graphical User Interfaces -- GUIs
Lecture 16 More GUI programming
Swing JComponents.
Graphical User Interface (pronounced "gooey")
Lecture 27 Creating Custom GUIs
Graphical User Interface (GUI) Programming III
Ellen Walker Hiram College
PC02 Term 1 Project Basic Messenger. PC02 Term 1 Project Basic Messenger.
College Student Tracker
Steps to Creating a GUI Interface
13 April 2010 GUIS: Graphical User Interfaces
Graphical User Interface
Presentation transcript:

PC02 Consolidation %WITTY_QUOTE%

This is the consolidation for this term Introduction This is the consolidation for this term Has lots of exercises on all the topics covered And some small things that are interesting, but you haven’t seen yet Start at any point you want Put all these in a single project called “Term01Consolidation” And then packages for each topic you do

Choose a Topic to Recap Constructors JFrames JPanels GUI Components Topic Index Choose a Topic to Recap Constructors JFrames JPanels GUI Components

When making classes, we can add constructors Functions that are run when an object of the class is instantiated Setting memory aside on the computer for the object Often used to ‘set up’ the object Like giving instance variables values

When making classes, we can add constructors Constructors (EX) When making classes, we can add constructors Functions that are run when an object of the class is instantiated Setting memory aside on the computer for the object Often used to ‘set up’ the object Like giving instance variables values

Constructors (EX 1) Make a package called constructor_practice In it, a class called Axolotl Create two instance variables for the name and age Create a constructor without any parameters Sets name to “Unknown” Sets age to 0 Outputs “Making an Axolotl with no known values” to the console Create a class called ConstructorProgram (and give it the main) Instantiate an Axolotl object (using the constructor you made)

Constructors (EX 2) Create a constructor in Axolotl with one parameter The Axolotl’s name This constructor should Assign the parameter to name Set the age to 0 Output “Making name, the Axolotl, with no known age” Instantiate an Axolotl object in the ConstructorProgram main Use this new constructor by giving it a name

Constructors (EX 3) Create a constructor in Axolotl with one parameter The Axolotl’s age This constructor should Assign the parameter to age Set the name to “Unknown” Output “Making a age year old Axolotl with no name” Instantiate an Axolotl object in the ConstructorProgram main Use this new constructor by giving it an age

Constructors (EX 4) Create a constructor in Axolotl with two parameters The Axolotl’s name and age This constructor should Assign the parameters to the correct variables Output “Making name, the age year old Axolotl” Instantiate an Axolotl object in the ConstructorProgram main Use this new constructor by giving it a name and an age

JFrames act as windows for a GUI We add a JPanel to it to add other components Can do three main things Make JFrame with title Set the close operation Pack and show

JFrames (EX) Make a package called jframe_practice In it, a class called JFrameProgram Make a JFrame object: Set it to quit the program when closed Set its size Make it visible Try using pack() before making it visible What’s the difference?

Allows multiple components to be shown JPanels Allows multiple components to be shown Rather than just one via JFrames Handles layout (e.g. BorderLayout, GridLayout) Can also change colour It’s background

JPanels (EX 1) Make a package called jpanel_practice In it, a class called JPanelProgram Make a JFrame window (and make it close the program on exit) Make a JPanel object Change its colour Give it a preferred size Add it to the window Pack and show the window What happens if you don’t pack()?

JPanels (EX 2) Set the layout of this JPanel to BorderLayout Create two more JPanels Give them both different colours Give them both the same preferred size Add one JPanel to the north of the main JPanel Add the other JPanel to the south of the main JPanel

We have looked at multiple JComponents (things we add to a JPanel) JLabel JTextField JButton Each have different uses

Make a package called jcomponent_practice JComponents (EX 1) Make a package called jcomponent_practice In it, a class called JComponentProgram Make a JFrame window (and make it close the program on exit) Make a JPanel object (using the BorderLayout) Give the JPanel a colour and preferred size Pack and show the window

JComponents (EX 2) Before packing the window, create a JLabel object Set the font of the JLabel Set the colour of the JLabel Set the text to centrally align horizontally Add the JLabel to the north of the JPanel What does this look like now?

JComponents (EX 3) Before packing the window, create a JTextField object Set the font of the JTextField Add the JTextField to the centre of the JPanel What does this look like now? Try adding the JTextField to a blank JPanel (with no layout) And give JTextField a preferred size Then add this new JPanel to centre of main JPanel Does it look different?

JComponents (EX 4) Before packing the window, create a JButton object Give the JButton an anonymous ActionListener Make it get the text from the JTextField And output the text to the console Add the JButton to the south of the main JPanel

You will make a timer that counts down from the chosen number Final Project This will act as a final project (if you don’t need a recap on anything else) You will make a timer that counts down from the chosen number

Make a new package called final_project Create a class called Program Create a new JFrame

Set the following for the JFrame: Final Project (2) Set the following for the JFrame: DefaultCloseOperation to WindowConstants.EXIT_ON_CLOSE Resizable to false Visible to true Pack it

Make another class and call it TimerPanel Make it extend JPanel Final Project (3) Make another class and call it TimerPanel Make it extend JPanel Give it a constructor Also give it three attributes: private int maximum = 30 private int current = maximum private boolean isRunning = false

We will need a label as well: Final Project (4) Change your size and layout. Because our class extends Jpanel, we can set it’s properties like this: setPreferredSize(new Dimension(250, 100)); setLayout(new BorderLayout()); We will need a label as well: JLabel label = new JLabel("" + current, SwingConstants.CENTER); add(label, BorderLayout.CENTER); label.setFont(new Font("Serif", Font.PLAIN, 72));

Next, make a new panel and 3 buttons: Final Project (5) Next, make a new panel and 3 buttons: JPanel panel = new JPanel(); JButton reset = new JButton("Reset"); JButton pause = new JButton("Pause"); JButton play = new JButton("Play"); Add your buttons to the panel: panel.add(play); panel.add(pause); panel.add(reset);

Next, make a new panel and 3 buttons: Final Project (6) Next, make a new panel and 3 buttons: JPanel panel = new JPanel(); JButton reset = new JButton("Reset"); JButton pause = new JButton("Pause"); JButton play = new JButton("Play"); Add your buttons to the panel: panel.add(play); panel.add(pause); panel.add(reset);

Now we need to add some action listeners All of them look like this: Final Project (7) Now we need to add some action listeners All of them look like this: play.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { CODE } });

They should do the following things: Final Project (8) They should do the following things: Play: isPlaying = true; Pause: isPlaying = false; Reset: current = maximum; label.setText("" + current); isPlaying = false;

Final Project (9) Finally, let’s add the main thread. Make a new Runnable, and in run() add an infinite while loop. It should do the following: if (isPlaying) { if(current <=0){ isPlaying = false; } label.setText("" + current); current--; Thread.sleep(1000); } else { Thread.sleep(100); }

You will need a try catch block around the whole thing Final Project (10) You will need a try catch block around the whole thing Also, make sure to call start().

THE END Have a nice holiday!