Course Status Networking GUI Wrap-up. CS Java. Introduction to Java. Andy Mroczkowski

Similar documents
Table of Contents. Chapter 1 Getting Started with Java SE 7 1. Chapter 2 Exploring Class Members in Java 15. iii. Introduction of Java SE 7...

CONTENTS. Chapter 1 Getting Started with Java SE 6 1. Chapter 2 Exploring Variables, Data Types, Operators and Arrays 13

PIC 20A GUI with swing

CSE 143. Event-driven Programming and Graphical User Interfaces (GUIs) with Swing/AWT

All the Swing components start with J. The hierarchy diagram is shown below. JComponent is the base class.

CS 251 Intermediate Programming GUIs: Components and Layout

CS 251 Intermediate Programming GUIs: Event Listeners

PROGRAMMING DESIGN USING JAVA (ITT 303) Unit 7

Part I: Learn Common Graphics Components

Graphical User Interfaces. Comp 152

Starting Out with Java: From Control Structures Through Objects Sixth Edition

CSE 331. Event-driven Programming and Graphical User Interfaces (GUIs) with Swing/AWT

Frames, GUI and events. Introduction to Swing Structure of Frame based applications Graphical User Interface (GUI) Events and event handling

AP CS Unit 11: Graphics and Events

14.2 Java s New Nimbus Look-and-Feel 551 Sample GUI: The SwingSet3 Demo Application As an example of a GUI, consider Fig. 14.1, which shows the SwingS

Topic 9: Swing. Swing is a BIG library Goal: cover basics give you concepts & tools for learning more

Topic 9: Swing. Why are we studying Swing? GUIs Up to now: line-by-line programs: computer displays text user types text. Outline. 1. Useful & fun!

Course Status Polymorphism Containers Exceptions Midterm Review. CS Java. Introduction to Java. Andy Mroczkowski

Parts of a Contract. Contract Example. Interface as a Contract. Wednesday, January 30, 13. Postcondition. Preconditions.

Unit 6: Graphical User Interface

Final Exam CS 251, Intermediate Programming December 13, 2017

Window Interfaces Using Swing Objects

Java Swing. based on slides by: Walter Milner. Java Swing Walter Milner 2005: Slide 1

Outline. Topic 9: Swing. GUIs Up to now: line-by-line programs: computer displays text user types text AWT. A. Basics

Class 16: The Swing Event Model

Introduction Course Information Object Oriented Concepts Operators & Control Statements Assignment 3. CS Java. Introduction to Java

Graphics. Lecture 18 COP 3252 Summer June 6, 2017

Dr. Hikmat A. M. AbdelJaber

Window Interfaces Using Swing Objects

To gain experience using GUI components and listeners.

Java Programming Lecture 6

Java Swing. Recitation 11/(20,21)/2008. CS 180 Department of Computer Science, Purdue University

CSE 331. Event- driven Programming and Graphical User Interfaces (GUIs) with Swing/AWT

Graphical User Interfaces. Swing. Jose Jesus García Rueda

Chapter 12 Advanced GUIs and Graphics

Sri Vidya College of Engineering & Technology

Graphical User Interface (GUI) components in Java Applets. With Abstract Window Toolkit (AWT) we can build an applet that has the basic GUI

Goals. Lecture 7 More GUI programming. The application. The application D&D 12. CompSci 230: Semester JFrame subclass: ListOWords

17 GUI API: Container 18 Hello world with a GUI 19 GUI API: JLabel 20 GUI API: Container: add() 21 Hello world with a GUI 22 GUI API: JFrame: setdefau

Programming graphics

Systems Programming Graphical User Interfaces

Handout 14 Graphical User Interface (GUI) with Swing, Event Handling

Object Oriented Design & Patterns. Part 1

Java. GUI building with the AWT

Mobile MOUSe JAVA2 FOR PROGRAMMERS ONLINE COURSE OUTLINE

Command-Line Applications. GUI Libraries GUI-related classes are defined primarily in the java.awt and the javax.swing packages.

SD Module-1 Advanced JAVA

Basicsof. JavaGUI and SWING

SD Module-1 Advanced JAVA. Assignment No. 4

KF5008 Program Design & Development. Lecture 1 Usability GUI Design and Implementation

Datenbank-Praktikum. Universität zu Lübeck Sommersemester 2006 Lecture: Swing. Ho Ngoc Duc 1

Chapter 6: Graphical User Interfaces

CS 180 Final Exam Review 12/(11, 12)/08

GUI DYNAMICS Lecture July 26 CS2110 Summer 2011

Introduction to the JAVA UI classes Advanced HCI IAT351

Graphical User Interface (GUI)

CPS122 Lecture: Graphical User Interfaces and Event-Driven Programming

Previously, we have seen GUI components, their relationships, containers, layout managers. Now we will see how to paint graphics on GUI components

Java Graphical User Interfaces AWT (Abstract Window Toolkit) & Swing

Agenda. Container and Component

CPS122 Lecture: Graphical User Interfaces and Event-Driven Programming

Introduction to GUIs. Principles of Software Construction: Objects, Design, and Concurrency. Jonathan Aldrich and Charlie Garrod Fall 2014

G51PGP Programming Paradigms. Lecture 009 Concurrency, exceptions

CS211 GUI Dynamics. Announcements. Motivation/Overview. Example Revisted

Graphical User Interfaces in Java - SWING

2110: GUIS: Graphical User Interfaces

Swing from A to Z Some Simple Components. Preface

Jonathan Aldrich Charlie Garrod

CHAPTER 2. Java Overview

Introduction to Graphical User Interfaces (GUIs) Lecture 10 CS2110 Fall 2008

11/7/12. Discussion of Roulette Assignment. Objectives. Compiler s Names of Classes. GUI Review. Window Events

Window Interfaces Using Swing. Chapter 12

Welcome to CIS 068! 1. GUIs: JAVA Swing 2. (Streams and Files we ll not cover this in this semester, just a review) CIS 068

Do not turn to the next page until the start of the exam.

Part 3: Graphical User Interface (GUI) & Java Applets

COMPSCI 230. Software Design and Construction. Swing

GUI in Java TalentHome Solutions

Contents Chapter 1 Introduction to Programming and the Java Language

CS 2113 Software Engineering

Swing UI. Powered by Pentalog. by Vlad Costel Ungureanu for Learn Stuff

Building a GUI in Java with Swing. CITS1001 extension notes Rachel Cardell-Oliver

SELF-STUDY. Glossary

Graphics programming. COM6516 Object Oriented Programming and Design Adam Funk (originally Kirill Bogdanov & Mark Stevenson)

Introduction... xv SECTION 1: DEVELOPING DESKTOP APPLICATIONS USING JAVA Chapter 1: Getting Started with Java... 1

Containers and Components

Dr. Hikmat A. M. AbdelJaber

Control Flow: Overview CSE3461. An Example of Sequential Control. Control Flow: Revisited. Control Flow Paradigms: Reacting to the User

Lab 4. D0010E Object-Oriented Programming and Design. Today s lecture. GUI programming in

Hanley s Survival Guide for Visual Applications with NetBeans 2.0 Last Updated: 5/20/2015 TABLE OF CONTENTS

GUI Programming: Swing and Event Handling

Graphical User Interfaces (GUIs)

CompSci 125 Lecture 17. GUI: Graphics, Check Boxes, Radio Buttons

Chapter 14. More Swing

10/16/2008. CSG 170 Round 5. Prof. Timothy Bickmore. User Analysis Task Analysis (6) Problem Scenarios (3)

CSE Lab 8 Assignment Note: This is the last lab for CSE 1341

CS111: PROGRAMMING LANGUAGE II

Graphic User Interfaces. - GUI concepts - Swing - AWT

Supporting Materials

Graphical User Interfaces in Java

Lecture 5: Java Graphics

Transcription:

CS 190 - Java Introduction to Java Andy Mroczkowski uamroczk@cs.drexel.edu Department of Computer Science Drexel University March 10, 2008 / Lecture 8

Outline Course Status Course Information & Schedule Assignments & Final Project Networking IP Networking Intro Simple Sockets in Java Demo GUI Java GUI Intro Events Layouts Swing Controls Wrap-up Wrap-up The End

Course Information Instructor Andy Mroczkowski uamroczk@cs.drexel.edu Office Location: UC 147 Office Hours: Monday 6-7 & evenings by appointment Course CS 190 - Java Web: www.cs.drexel.edu/ uamroczk/cs190 Book: Thinking in Java, 4th Edition Previous edition available for free at wwww.mindview.net/books/tij/ Course materials adapted from Nadya Belov Many examples from TiJ, 4th Ed.

Schedule 1 Jan 7 Jan 14 Jan 21 Jan 28 Feb 4 Feb 11 Feb 18 Feb 25 Mar 3 Mar 10 Mar 19 Course Overview, Introduction to Java No Class No Class (University Holiday) Object Oriented Concepts, Control Statements Access Control, Intialization & Cleanup, Reuse, Interfaces, Containers, Exceptions, Polymorphism, Midterm Review Midterm, Inner-Classes Type Information, Generics, Arrays Files & I/O, Threading GUI, Special Topics (Networking, Reflection) Final Project 1 Also subject to change

Assignment 5 Questions?

Final Project Collaboration OK but you must let me know Group of 3 Max Extra credit Multiple players (Live or automated) Saving Scores (File I/O) Betting Networking... or your idea GUI?

Final Project Collaboration OK but you must let me know Group of 3 Max Extra credit Multiple players (Live or automated) Saving Scores (File I/O) Betting Networking... or your idea GUI?

Final Project Collaboration OK but you must let me know Group of 3 Max Extra credit Multiple players (Live or automated) Saving Scores (File I/O) Betting Networking... or your idea GUI?

Final Project Questions?

Final Project - Tips Random generator = new Random ( ) ; i n t index1 = generator. n e x t I n t ( decksize ) ; i n t index2 = generator. n e x t I n t ( decksize ) ;

Final Project - Tips public class BlackjackHand extends Hand

Networking (A quick introduction)

Networking (A quick introduction)

IP Networking Addressing Host Port Data transmission Send Receive

IP Networking Addressing Host Port Data transmission Send Receive

IP Networking Addressing Host Port Data transmission Send Receive

IP Networking Addressing Host Port Data transmission Send Receive

IP Networking Addressing Host Port Data transmission Send Receive

IP Hosts Host Post office www.google.com 192.168.20.10 127.0.0.1 Port Mailbox ftp - 21 http - 80 less than 1024 priveledged greater than 1024 unpriveledged

IP Hosts Host Post office www.google.com 192.168.20.10 127.0.0.1 Port Mailbox ftp - 21 http - 80 less than 1024 priveledged greater than 1024 unpriveledged

IP Hosts Host Post office www.google.com 192.168.20.10 127.0.0.1 Port Mailbox ftp - 21 http - 80 less than 1024 priveledged greater than 1024 unpriveledged

IP Hosts Host Post office www.google.com 192.168.20.10 127.0.0.1 Port Mailbox ftp - 21 http - 80 less than 1024 priveledged greater than 1024 unpriveledged

IP Hosts Host Post office www.google.com 192.168.20.10 127.0.0.1 Port Mailbox ftp - 21 http - 80 less than 1024 priveledged greater than 1024 unpriveledged

IP Hosts Host Post office www.google.com 192.168.20.10 127.0.0.1 Port Mailbox ftp - 21 http - 80 less than 1024 priveledged greater than 1024 unpriveledged

Data transmission IP Sockets Data endpoints Two types Stream (TCP) Datagram (UDP)

Data transmission IP Sockets Data endpoints Two types Stream (TCP) Datagram (UDP)

Data transmission IP Sockets Data endpoints Two types Stream (TCP) Datagram (UDP)

Data transmission IP Sockets Data endpoints Two types Stream (TCP) Datagram (UDP)

Simple Sockets in Java Socket and ServerSocket classes ServerSocket Listen for and accept connections Can have handle many incoming connections Socket Initiate client connections Read and write data streams

Simple Sockets in Java Socket and ServerSocket classes ServerSocket Listen for and accept connections Can have handle many incoming connections Socket Initiate client connections Read and write data streams

Simple Sockets in Java Socket and ServerSocket classes ServerSocket Listen for and accept connections Can have handle many incoming connections Socket Initiate client connections Read and write data streams

Simple Sockets in Java Socket and ServerSocket classes ServerSocket Listen for and accept connections Can have handle many incoming connections Socket Initiate client connections Read and write data streams

Simple Sockets in Java Socket and ServerSocket classes ServerSocket Listen for and accept connections Can have handle many incoming connections Socket Initiate client connections Read and write data streams

Create a ServerSocket ServerSocket server = new ServerSocket ( ( i n t l i s t e n _ p o r t ) ;

Listening for connections ServerSocket server = new ServerSocket ( ( i n t l i s t e n _ p o r t ) ; Socket s = server. accept ( ) ;

Create a client Socket Socket c l i e n t = new Socket ( S t r i n g server, i n t p o r t ) ;

Sending and Receiving data / / Readin InputStream i n = socket. getinputstream ( ) ; / / W r i t i n OutputStream out = socket. getoutputstream ( ) ; Now we can read/write just like they was files!

Demo

Questions?

GUI ALL examlpes from Thinking in Java, 4th ed.

Java GUI - History In the beginning, there was AWT And it was a dark, dark time. Then the geeks said, let there be Swing. And so it was. Some of the elders tell stories about "Applets", but no one has seen one in years. They are thought to be extinct.

Java GUI - History In the beginning, there was AWT And it was a dark, dark time. Then the geeks said, let there be Swing. And so it was. Some of the elders tell stories about "Applets", but no one has seen one in years. They are thought to be extinct.

Java GUI - History In the beginning, there was AWT And it was a dark, dark time. Then the geeks said, let there be Swing. And so it was. Some of the elders tell stories about "Applets", but no one has seen one in years. They are thought to be extinct.

Java GUI - History In the beginning, there was AWT And it was a dark, dark time. Then the geeks said, let there be Swing. And so it was. Some of the elders tell stories about "Applets", but no one has seen one in years. They are thought to be extinct.

Java GUI - History In the beginning, there was AWT And it was a dark, dark time. Then the geeks said, let there be Swing. And so it was. Some of the elders tell stories about "Applets", but no one has seen one in years. They are thought to be extinct.

Swing Basics Objects just like everything else Most things inherit from java.awt.component Everything is done programatically Though there are visual tools that can generate code for you Strives for consistency

Swing Basics Objects just like everything else Most things inherit from java.awt.component Everything is done programatically Though there are visual tools that can generate code for you Strives for consistency

Swing Basics Objects just like everything else Most things inherit from java.awt.component Everything is done programatically Though there are visual tools that can generate code for you Strives for consistency

Swing Basics Objects just like everything else Most things inherit from java.awt.component Everything is done programatically Though there are visual tools that can generate code for you Strives for consistency

Swing Basics Objects just like everything else Most things inherit from java.awt.component Everything is done programatically Though there are visual tools that can generate code for you Strives for consistency

Swing Basics - JFrame import javax. swing. ; public class HelloSwing { public s t a t i c void main ( String [ ] args ) { JFrame frame = new JFrame ( " Hello Swing " ) ; frame. setdefaultcloseoperation ( JFrame.EXIT_ON_CLOSE ) ; frame. setsize ( 300, 100 ) ; frame. setvisible ( true ) ; } }

Swing Basics - JLabel import javax. swing. ; import java. u t i l. concurrent. ; public class HelloLabel { public s t a t i c void main ( String [ ] args ) throws Exception { JFrame frame = new JFrame ( " Hello Swing " ) ; JLabel label = new JLabel ( "A Label " ) ; frame. add ( label ) ; frame. setdefaultcloseoperation ( JFrame.EXIT_ON_CLOSE ) ; frame. setsize ( 300, 100 ) ; frame. setvisible ( true ) ; TimeUnit.SECONDS. sleep ( 1 ) ; label. settext ( " Hey! This i s d i f f e r e n t " ) ; } }

Swing Demo Display Helper import javax. swing. ; public class SwingConsole { public s t a t i c void run ( f i n a l JFrame f, f i n a l i n t width, f i n a l i n t height ) { SwingUtilities. invokelater ( new Runnable ( ) { public void run ( ) { f. s e t T i t l e ( f. getclass ( ). getsimplename ( ) ) ; f. setdefaultcloseoperation ( JFrame.EXIT_ON_CLOSE ) ; f. setsize ( width, height ) ; f. s e t V i s i b l e ( true ) ; } } ) ; } }

JButton import javax. swing. ; import java. awt. ; public class Button1 extends JFrame { private JButton b1 = new JButton ( " Button 1 " ) ; private JButton b2 = new JButton ( " Button 2 " ) ; public Button1 ( ) { setlayout ( new FlowLayout ( ) ) ; / / Note Layout Manager add ( b1 ) ; add ( b2 ) ; } } public s t a t i c void main ( String [ ] args ) { SwingConsole. run ( new Button1 ( ), 200, 100 ) ; }

Events Ok, we can create controls. How do we make them do something?

import javax. swing. ; import java. awt. ; import java. awt. event. ; public class Button2 extends JFrame { private JButton b1 = new JButton ( " Button 1 " ) ; private JButton b2 = new JButton ( " Button 2 " ) ; private JTextField t x t = new JTextField ( 10 ) ; class B u t t o n L i s t e n e r implements A c t i o n L i s t e n e r { public void actionperformed ( ActionEvent e ) { S t r i n g name = ( ( JButton ) e. getsource ( ) ). gettext ( ) ; t x t. settext ( name ) ; } } private ButtonListener bl = new ButtonListener ( ) ; public Button2 ( ) { b1. addactionlistener ( bl ) ; b2. addactionlistener ( bl ) ; setlayout ( new FlowLayout ( ) ) ; add ( b1 ) ; add ( b2 ) ; add ( t x t ) ; } } public s t a t i c void main ( String [ ] args ) { SwingConsole. run ( new Button2 ( ), 200, 150 ) ; }

import javax. swing. ; import java. awt. ; import java. awt. event. ; public class Button2b extends JFrame { private JButton b1 = new JButton ( " Button 1 " ) ; private JButton b2 = new JButton ( " Button 2 " ) ; private JTextField t x t = new JTextField ( 10 ) ; private ActionListener bl = new ActionListener ( ) { public void actionperformed ( ActionEvent e ) { S t r i n g name = ( ( JButton ) e. getsource ( ) ). gettext ( ) ; t x t. settext ( name ) ; } } ; public Button2b ( ) { b1. addactionlistener ( bl ) ; b2. addactionlistener ( bl ) ; setlayout ( new FlowLayout ( ) ) ; add ( b1 ) ; add ( b2 ) ; add ( t x t ) ; } } public s t a t i c void main ( String [ ] args ) { SwingConsole. run ( new Button2 ( ), 200, 150 ) ; }

Events ActionEvent AdjustmentEvent ComponentEvent ContainerEvent FocusEvent KeyEvent MouseEvent WindowEvent ItemEvent TextEvent JButton, JList, JTextField JScrollBar Component and its derivatives Container and its derivatives Component and its derivatives Component and its derivatives Component and its derivatives Window and its derivatives JCheckBox, JComboBox, JList JTextArea, JTextField

Event Demo

Layouts Java can automatically position or layout components Several different LayoutManagers Absolute positioning still available, but hard to do by hand Designer/code generation tools

Layouts Java can automatically position or layout components Several different LayoutManagers Absolute positioning still available, but hard to do by hand Designer/code generation tools

Layouts BorderLayout North South East West FlowLayout "flows" in GridLayout Rows by Columns GridBagLayout Control Freak BoxLayout Simplified GridBagLayout

Layout Demos

Swing Controls Buttons Icons TextFields Borders TextPane CheckBoxes RadioButtons ComboBoxes List TabbedPane MessageBoxes Menus Drawing Dialogs HTML Progress

Wrap-up

What We Covered Object Oriented Concepts Information Hiding Encapsulation Re-use Operators Control Statements Conditionals Loops Java coding style Access Control Scope Packages Visibility

Initialization & Cleanup Creating objects Constructors finalize Re-use Composition Delegation Inheritance Abstract Classes Interfaces Collections ArrayList HashMap Iterator What We Covered (cont.)

What We Covered (cont.) Exceptions Inner Classes Anonymous Inner Classes Type Information RTTI Class objects Arrays Generics I/O Files Streams

What We Covered (cont.) Basic threads Basic networkins GUI Swing Components Layouts Events

What we didn t cover Enumerated Types Containers in depth Annotations In Thinking in Java or on the web

Thank you and Good Night!