GUI in Java TalentHome Solutions

Similar documents
SD Module-1 Advanced JAVA

SD Module-1 Advanced JAVA. Assignment No. 4

The AWT Event Model 9

Method Of Key Event Key Listener must implement three methods, keypressed(), keyreleased() & keytyped(). 1) keypressed() : will run whenever a key is

GUI DYNAMICS Lecture July 26 CS2110 Summer 2011

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

Java. GUI building with the AWT

ECE 462 Object-Oriented Programming using C++ and Java. Key Inputs in Java Games

Java Mouse Actions. C&G criteria: 5.2.1, 5.4.1, 5.4.2,

User interfaces and Swing

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

Graphical User Interfaces 2

(listener)... MouseListener, ActionLister. (adapter)... MouseAdapter, ActionAdapter. java.awt AWT Abstract Window Toolkit GUI

Programming Mobile Devices J2SE GUI

Java Applets / Flash

Computer Programming Java AWT Lab 18

BASICS OF GRAPHICAL APPS

Overloading Example. Overloading. When to Overload. Overloading Example (cont'd) (class Point continued.)

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

CSEN401 Computer Programming Lab. Topics: Graphical User Interface Window Interfaces using Swing

Packages: Putting Classes Together

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

Advanced Java Programming

OBJECT ORIENTED PROGRAMMING. Java GUI part 1 Loredana STANCIU Room B616

Graphic User Interfaces. - GUI concepts - Swing - AWT

CPS122 Lecture: Graphical User Interfaces and Event-Driven Programming

GUI Programming: Swing and Event Handling

Graphical User Interfaces 2

H212 Introduction to Software Systems Honors

GUI Event Handlers (Part II)

กล ม API ท ใช. Programming Graphical User Interface (GUI) Containers and Components 22/05/60

BM214E Object Oriented Programming Lecture 13

Graphical User Interfaces 2

Advanced Java Programming (17625) Event Handling. 20 Marks

The Java Programming Language Basics. Identifiers, Keywords, and Types. Expressions and Flow Control. Object-Oriented Programming. Objects and Classes

CHAPTER 2. Java Overview

Aim: Write a java program to demonstrate the use of following layouts. 1.FlowLayout 2.BorderLayout 3.GridLayout 4.GridBagLayout 5.

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

11/6/15. Objec&ves. RouleQe. Assign 8: Understanding Code. Assign 8: Bug. Assignment 8 Ques&ons? PROGRAMMING PARADIGMS

Introduction to the JAVA UI classes Advanced HCI IAT351

Handling Mouse and Keyboard Events

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

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

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!

Module 4 Multi threaded Programming, Event Handling. OOC 4 th Sem, B Div Prof. Mouna M. Naravani

Sri Vidya College of Engineering & Technology

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

Graphical User Interfaces. Comp 152

G51PRG: Introduction to Programming Second semester Applets and graphics

PROGRAMMING DESIGN USING JAVA (ITT 303) Unit 7

CS 2113 Software Engineering

Chapter 6: Graphical User Interfaces

Window Interfaces Using Swing Objects

Outline. More on the Swing API Graphics: double buffering and timers Model - View - Controller paradigm Applets

G51PGP Programming Paradigms. Lecture 008 Inner classes, anonymous classes, Swing worker thread

Chapter 1 GUI Applications

CS11 Java. Fall Lecture 4

Dr. Hikmat A. M. AbdelJaber

Computer Science 210: Data Structures. Intro to Java Graphics

Java & Graphical User Interface II. Wang Yang wyang AT njnet.edu.cn

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...

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

Chapter 12 Advanced GUIs and Graphics

Laying Out Components. What is Widget Layout?

What is Widget Layout? Laying Out Components. Resizing a Window. Hierarchical Widget Layout. Interior Design for GUIs

CSC207H: Software Design Lecture 11

GUI 4.1 GUI GUI MouseTest.java import javax.swing.*; import java.awt.*; import java.awt.event.*; /* 1 */

Graphical User Interfaces in Java - SWING

Event Driven Programming

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

Window Interfaces Using Swing Objects

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

Dr. Hikmat A. M. AbdelJaber

12/22/11. Copyright by Pearson Education, Inc. All Rights Reserved.

Example Programs. COSC 3461 User Interfaces. GUI Program Organization. Outline. DemoHelloWorld.java DemoHelloWorld2.java DemoSwing.

GUI Event Handlers (Part I)

GUI Program Organization. Sequential vs. Event-driven Programming. Sequential Programming. Outline

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

CS11 Java. Fall Lecture 3

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

Basicsof. JavaGUI and SWING

GUI Basics. Object Orientated Programming in Java. Benjamin Kenwright

The AWT Component Library 10

Programming graphics

IPM 12/13 P4 Handling Events in AWT

Java - Applications. The following code sets up an application with a drop down menu, as yet the menu does not do anything.

Systems Programming Graphical User Interfaces

Java Programming Lecture 6

THE UNIVERSITY OF AUCKLAND

PESIT Bangalore South Campus

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

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

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

Unit 7: Event driven programming

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

CSC 161 SPRING 17 LAB 2-1 BORDERLAYOUT, GRIDLAYOUT, AND EVENT HANDLING

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

Graphics. Lecture 18 COP 3252 Summer June 6, 2017

Programming Languages and Techniques (CIS120)

Transcription:

GUI in Java TalentHome Solutions

AWT Stands for Abstract Window Toolkit API to develop GUI in java Has some predefined components Platform Dependent Heavy weight To use AWT, import java.awt.*

Calculator

Container It is a component that holds other components. Window No border no Menu bar Panel No Title bars no Menu Bars Frame Contains Title bar, Has menu bar

Frame How to create frame? By extending frame class. (Inheritance) By creating object of frame class. (Association) Frame f = new Frame( Name to the frame ); How to access function of frame? f.setsize(); f.setvisible(); f.add();

Important Components Button : The button class is used to create a labelled button that has platform independent implementation. The application result in some action when the button is pushed Button button = new Button("Click Here"); Label : The object of Label class is a component for placing text in a container. It is used to display a single line of read only text. The text can be changed by an application but a user cannot edit it directly. Label label = new Label("First Label.");

Important Components Text Field : The object of a TextField class is a text component that allows the editing of a single line text. TextField txt = new TextField( Single line Editable Field ); Text Area : The object of a TextArea class is a multi line region that displays text. It allows the editing of multiple line text. TextArea txtarea = new TextArea( Multiline Editable Field");

Important Components CheckBox : The Checkbox class is used to create a checkbox. It is used to turn an option on (true) or off (false). Clicking on a Checkbox changes its state from "on" to "off" or from "off" to "on". Checkbox checkbox = new Checkbox( JAVA"); Choice : The object of Choice class is used to show popup menu of choices. Choice selected by user is shown on the top of a menu. Choice choice = new Choice(); Choice.add( Choice Item );

Important Components List : The object of List class represents a list of text items. with the help of list, user can choose either one item or multiple items. List list = new List(5); List.add( List Item ); Dialog : The Dialog control represents a top level window with a border and a title used to take some form of input from the user. It inherits the Window class. Dialog d = new Dialog(f, "Dialog Example", true);

Important Components MenuItem and Menu: The object of MenuItem class adds a simple labelled menu item on menu. The items used in a menu must belong to the MenuItem or any of its subclass. Menu menu = new Menu("Menu"); Menu submenu = new Menu( Submenu ); MenuItem m = new MenuItem( Item 1 ); MenuItem s = new MenuItem( Item 2 ); menu.add(m); menu.add(submenu); submenu.add( s1 );

Listeners These are interfaces They contains some abstract methods To use listeners, we need to define these abstract methods All the Listener interfaces are found in java.awt.event package So, import java.awt.event.*;

ActionListener The Java ActionListener is notified whenever you click on the button or menu item. It is notified against ActionEvent. It has only one method: actionperformed(actionevent e).

Mouse Listener The Java MouseListener is notified whenever you change the state of mouse. It is notified against MouseEvent. It has five methods : public abstract void mouseclicked(mouseevent e); public abstract void mouseentered(mouseevent e); public abstract void mouseexited(mouseevent e); public abstract void mousepressed(mouseevent e); public abstract void mousereleased(mouseevent e);

Mouse Motion Listener The Java MouseMotionListener is notified whenever you move or drag mouse. It is notified against MouseEvent. It has two methods : public abstract void mousedragged(mouseevent e); public abstract void mousemoved(mouseevent e);

Item Listener The Java ItemListener is notified whenever you click on the checkbox. It is notified against ItemEvent. It has only one method: itemstatechanged().

Key Listener The Java KeyListener is notified whenever you change the state of key. It is notified against KeyEvent. It has three methods. public abstract void keypressed(keyevent e); public abstract void keyreleased(keyevent e); public abstract void keytyped(keyevent e);

Layout Manager Layout Managers are used by GUI based java applications to size and position the GUI components. LayoutManager is an interface that is implemented by all the classes of layout managers. There are following classes that represents the layout managers java.awt.flowlayout java.awt.gridlayout java.awt.borderlayout

Border Layout

Border Layout positions the components at 5 locations EAST, WEST, NORTH, SOUTH and CENTER components at EAST and WEST get default or desired width but their height is compulsorily the height of the container minus the sum of heights of components at NORTH and SOUTH. components at NORTH and SOUTH get default or desired height but their widht is compulsorily the width of the container. component at CENTER gets remaining width and height. setlayout(new BorderLayout());

Layouts FlowLayout arranges the components rowise across the container. Every component can get their desired width and height. setlayout(new FlowLayout()); GridLayout divides the component area in a grid of specific rows and cols It arranges the components in the cells of the grid. Every component get width and height of the cell. GridLayout g = new GridLayout(row, column, hgap, vgap);

How to develop GUI Declare components Create Frame & panel(s) Set layout Create other component Add Action Listener Add component to panel Add panel(s) to plane Set size of frame Set visibility of frame

Calculator

Calculator int c,n; String s1,s2,s3,s4,s5; Frame f; Button b1,b2,b3,b4,b5,b6,b7,b8,b9,b10,b11,b12,b13,b14,b15,b 16,b17; Panel p; TextField tf; GridLayout g;

Can you Code for Calculator?