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

Size: px
Start display at page:

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

Transcription

1 CBOP3203

2 Graphical User Interface (GUI) components in Java Applets. With Abstract Window Toolkit (AWT) we can build an applet that has the basic GUI components like button, text input, scroll bar and others. Swing class library have many advantages and choices in terms of different types of GUI components, characteristic and running in different computer environment.

3 Provides graphical user interface (GUI) components that are used in all Java applets and applications Contains classes that can be extended and their properties inherited; classes can also be abstract Ensures that every GUI component that is displayed on the screen is a subclass of the abstract class Component or MenuComponent Has Container, which is an abstract subclass of Component and includes two subclasses: Panel Window

4 Part of the AWT Class Hierarchy Object Component Button Checkbox TextComponent Choice List Container Label Canvas ScrollBar TextArea TextField Panel Window ScrollPane Applet Dialog Frame

5 Add components with the add() method. The two main types of containers are Window and Panel. A Window is a free floating window on the display. A Panel is a container of GUI components that must exist in the context of some other container, such as window or applet.

6 The position and size of a component in a container is determined by a layout manager. You can control the size or position of components by disabling the layout manager. You must then use setlocation(), setsize(), or setbounds() on components to locate them in the container.

7 import javax.swing.*; import java.awt.*; public class AppletSwing extends JApplet { public void init() { Container conpane=getcontentpane(); conpane.setbackground(color.blue); conpane.setlayout(new FlowLayout()); Components are placed in a container Provides work space for JApplet

8 Control components are very important for the communication between the user and the machine. There are many control components in Java that offer different types of services.

9 JButton JCheckBox JComboBox JList JMenu JRadioButton

10 JSlider JSpinner JTextField JPasswordField

11 JColorChooser JEditorPane and JTextPane

12 JFileChooser JTree

13 JTable JTextArea

14 JProgressBar JSeparator JLabel JToolTip

15 A button in Swing library is known as JButton as in javax.swing.jbutton Normally a button is used as a control component to: Start an action. Change a form or character. Display a menu. Display another window.

16 import javax.swing.*; import java.awt.*; public class TestButton extends JApplet { private JButton btnyes, btnno; public void init(){ Container conpane=getcontentpane(); conpane.setlayout(new FlowLayout()); btnyes=new JButton("Yes"); conpane.add(btnyes); btnno=new JButton("No"); conpane.add(btnno); Adding button to the container Declare the button Using FlowLayout Creating and Labeling

17 If we want the program to receive input from the user, we need to use the text field component. In Swing, the component used to receive the input from the user is called JTextField.

18 import javax.swing.*; import java.awt.*; public class TestTextField extends JApplet { public void init(){ Container conpane=getcontentpane(); conpane.setlayout(new FlowLayout()); JTextField txtname=new JTextField(20); conpane.add(txtname);

19 Like JTextField, JPasswordField are single-line areas in which text entered by the user from keyboard will be displayed. A JPasswordField will hide the data that is been entered assuming the data entered is secret is only known to the user.

20 import javax.swing.*; import java.awt.*; public class TestPasswordField extends JApplet { public void init(){ Container conpane=getcontentpane(); conpane.setlayout(new FlowLayout()); JPasswordField pwd =new JPasswordField(); pwd.setechochar('*'); conpane.add(pwd);

21 If we want to label the container, we must build an object JLabel. Generally the object JTextField and JLabel are created together. The following lines will add a label to the container conpane. JLabel lblname=new JLabel( Name: ); conpane.add(lblname);

22 import javax.swing.*; import java.awt.*; public class TestTextLabel extends JApplet { private JLabel lblname; private JTextField txtname; public void init(){ Container conpane=getcontentpane(); conpane.setlayout(new FlowLayout()); txtname=new JTextField(20); conpane.add(lblname); lblname=new JLabel("Name:"); conpane.add(txtname);

23 We have discussed earlier the use of text field to input data but this is not suitable if we want the user to choose from a list of choices. Swing has a component that is more suitable for this type of job that is the JRadioButton. If the user wants to choose only one from a list of choices, JRadioButton component can be used.

24 import javax.swing.*; import java.awt.*; public class ChooseTVChannels extends JApplet { private JCheckBox tv1,tv2,tv3, ntv7; public void init(){ Container conpane = getcontentpane(); conpane.setlayout(new FlowLayout()); tv1 = new JCheckBox("TV1", false); conpane.add(tv1); tv2 = new JCheckBox("TV2", true); conpane.add(tv2); tv3 = new JCheckBox("TV3", false); conpane.add(tv3); ntv7 = new JCheckBox("NTV7", true); conpane.add(ntv7); User can chose more than one favorite channels

25 import javax.swing.*; import java.awt.*; public class RadioButtonExample extends JApplet { private JRadioButton tv1,tv2,tv3,ntv7; private ButtonGroup tv; public void init( ){ Container conpane = getcontentpane( ); conpane.setlayout(new FlowLayout()); tv = new ButtonGroup( ); tv1 = new JRadioButton("TV1",false); tv.add(tv1); conpane.add(tv1); tv2 = new JRadioButton ("TV2",false); tv.add(tv2); conpane.add(tv2); tv3 = new JRadioButton ("TV3",false); tv.add(tv3); conpane.add(tv3); ntv7 = new JRadioButton ("NTV7",true); tv.add(ntv7); conpane.add(ntv7); Adding radio button to the logical group tv Creating a logical identifier for JRadioButton group user is allowed to choose only one from the list at one time

26 If we have many choices to choose from (maybe more than 5), radio button component is not a good choice. It would be better to use a list or what is known in Swing as JList.

27 import javax.swing.*; import java.awt.*; public class mylist extends JApplet { private JList TVList; private String[] item={"tv1","tv2","tv3","ntv7"; public void init( ){ Container conpane = getcontentpane(); conpane.setlayout(new FlowLayout()); TVList = new JList(item); TVList.setVisibleRowCount(3); Creating a list object with a array data (above) as the parameter TVList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); JScrollPane scrollpane = new JScrollPane(TVList); conpane.add(scrollpane);

28 Combo box is a component like the list component (JList) where the user has a multiple choices to make at one time. Combo box component in Swing is known as JComboBox. JComboBox is different from JList because it hides the list. When combo box is displayed the user needs to click the arrow displayed before the user can see the list. Then the user can choose one item from the list.

29 import javax.swing.*; import java.awt.*; public class combobox extends JApplet { private JComboBox cmbtv; private String [] item={"tv1","tv2","tv3","ntv7"; public void init( ){ Container conpane= getcontentpane(); conpane.setlayout(new FlowLayout()); cmbtv = new JComboBox(item); conpane.add(cmbtv);

30 In Swing, Panel is known as JPanel. Panel is a container-like content pane where you can place and arrange any Swing components in a particular window. Panel will act as a sub-container. Component arrangement is done by dividing the window space into groups of components. For example, we can build a Panel for the button and others for the list or combo box. Provide a space for components. Allow subpanels to have their own layout manager.

31 import javax.swing.*; import java.awt.*; public class TestPanel extends JApplet { public void init( ){ Container conpane= getcontentpane(); conpane.setlayout(new FlowLayout()); JPanel panel=new JPanel(); //creating the JPanel Object JButton btnyes = new JButton("Yes"); JButton btnno = new JButton("No"); panel.add(btnyes); //adding object JButton Yes to the Panel panel.add(btnno); //adding object JButton No to the Panel conpane.add(panel); //adding object JPanel to the main container

32 In Swing, text area is known as JTextArea. The function is the same as JTextField. The difference is in the usage, where the height is more than a line. When a user places the JTextArea to a program, the user must state the number of line used.

33 import javax.swing.*; import java.awt.*; public class TextArea extends JApplet { private JTextArea teks; public void init( ){ Container conpane = getcontentpane(); conpane.setlayout(new FlowLayout()); JPanel panel = new JPanel(); teks = new JTextArea(10,10); JScrollPane skrol = new JScrollPane(teks, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS); teks.setlinewrap(true); panel.add(skrol); conpane.add(panel);

34 Slider in Swing component is known as JSlider. Two very common usages for slider are: 1. Using slider as a control, when the bar is moved, it represents a value. 2. A replacement to the text field when the maximum and minimum input range is known.

35 import javax.swing.*; import java.awt.*; public class myslider extends JApplet { public void init( ){ Container conpane = getcontentpane( ); conpane.setlayout(new FlowLayout( )); JSlider skrol = new JSlider(JSlider.HORIZONTAL,0, 100,50); skrol.setmajortickspacing(50); skrol.setminortickspacing(5); skrol.setpaintticks(true); skrol.setpaintlabels(true); conpane.add(skrol); orientation and the specified minimum, maximum, and initial values The number of values between the major tick marks -- the larger marks that break up the minor tick marks. The number of values between the minor tick marks -- the smaller marks that occur between the major tick marks.

36 Layout manager is used to arrange the GUI components in the container. Each container (such as Panel or Frame) has a default layout manager associated with it, which you can change by calling setlayout. Layout manager is responsible for deciding the layout policy and size of each of its container s child components.

37 The layout manager is in java.awt package. There are eight-layout managers. Some of them are: FlowLayout: This is the easiest layout manager. The components are arranged horizontally until there is no more space, then a new line is added for the next component.

38 BorderLayout Divides the container into five areas that is north, south, east, west and center.

39 GridBagLayout GridBagLayout is a sophisticated, flexible layout manager. It aligns components by placing them within a grid of cells, allowing components to span more than one cell. The rows in the grid can have different heights, and grid columns can have different widths.

40 GridLayout Arranges all the components into rows and columns. It aligns components by placing them within a grid of cells, allowing components to span more than one cell. The rows in the grid can have different heights, and grid columns can have different widths.

41 CardLayout This layout is also known as tabbed. Each component is piled on top so that only one component is displayed at one time. The CardLayout class lets you implement an area that contains different components at different times.

42 BoxLayout The BoxLayout class puts components in a single row or column. It respects the components' requested maximum sizes and also lets you align components.

43 Null Places the components into the container without a layout manager. We use the NULL layout manager when placing the component on the applet physical location. This is not recommended for application where the window always changes.

44 import javax.swing.*; import java.awt.*; public class BorderLayout extends JApplet { private JButton north,south,east,west,center; public void init( ){ Container conpane = getcontentpane( ); //conpane.setlayout(new BorderLayout( )); north = new JButton("North"); south = new JButton("South"); east = new JButton("East"); west = new JButton("West"); center = new JButton("Center"); conpane.add("north",north); conpane.add("south",south); conpane.add("east",east); conpane.add("west",west); conpane.add("center",center);

45 import java.awt.*; import javax.swing.*; public class Calculator extends JApplet { private JButton b0, b1, b2, b3, b4; private JButton b5, b6, b7, b8, b9; private JButton b10, b11, b12, b13, b14, b15; public void init( ) { Container conpane = getcontentpane( ); conpane.setbackground(color.white); JPanel panel = new JPanel( ); panel.setlayout(new GridLayout(4,4)); b7 = new JButton("7"); panel.add(b7); b8 = new JButton("8"); panel.add(b8); b9 = new JButton("9"); panel.add(b9); b10 = new JButton("/"); panel.add(b10); b4 = new JButton("4"); panel.add(b4); b5 = new JButton("5"); panel.add(b5); b6 = new JButton("6"); panel.add(b6); b11 = new JButton("*"); panel.add(b11); b1 = new JButton("1"); panel.add(b1); b2 = new JButton("2"); panel.add(b2); b3 = new JButton("3"); panel.add(b3); b12 = new JButton("-"); panel.add(b12); b0 = new JButton("0"); panel.add(b0); b13 = new JButton("."); panel.add(b13); b14 = new JButton("+"); panel.add(b14); b15 = new JButton("="); panel.add(b15); conpane.add("center",panel);

46 Q1. Create an applet that can display the following component. No event handling is needed for the components. name address

47 Q2. Create an applet that can display the following component. No event handling is needed for the components.

48 Q3. Create an applet that can display the following component. No event handling is needed for the components.

49 Q4. Create an applet with the following GUI. You do not have to provide any functionality.

50 Q5. Create an applet with the following GUI. You do not have to provide any functionality.

Swing. By Iqtidar Ali

Swing. By Iqtidar Ali Swing By Iqtidar Ali Background of Swing We have been looking at AWT (Abstract Window ToolKit) components up till now. Programmers were not comfortable when doing programming with AWT. Bcoz AWT is limited

More information

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

Swing UI. Powered by Pentalog. by Vlad Costel Ungureanu for Learn Stuff Swing UI by Vlad Costel Ungureanu for Learn Stuff User Interface Command Line Graphical User Interface (GUI) Tactile User Interface (TUI) Multimedia (voice) Intelligent (gesture recognition) 2 Making the

More information

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

Handout 14 Graphical User Interface (GUI) with Swing, Event Handling Handout 12 CS603 Object-Oriented Programming Fall 15 Page 1 of 12 Handout 14 Graphical User Interface (GUI) with Swing, Event Handling The Swing library (javax.swing.*) Contains classes that implement

More information

Graphical User Interfaces. Comp 152

Graphical User Interfaces. Comp 152 Graphical User Interfaces Comp 152 Procedural programming Execute line of code at a time Allowing for selection and repetition Call one function and then another. Can trace program execution on paper from

More information

Java Swing. Lists Trees Tables Styled Text Components Progress Indicators Component Organizers

Java Swing. Lists Trees Tables Styled Text Components Progress Indicators Component Organizers Course Name: Advanced Java Lecture 19 Topics to be covered Java Swing Lists Trees Tables Styled Text Components Progress Indicators Component Organizers AWT to Swing AWT: Abstract Windowing Toolkit import

More information

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

Graphical User Interfaces. Swing. Jose Jesus García Rueda Graphical User Interfaces. Swing Jose Jesus García Rueda Introduction What are the GUIs? Well known examples Basic concepts Graphical application. Containers. Actions. Events. Graphical elements: Menu

More information

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

11/6/15. Objec&ves. RouleQe. Assign 8: Understanding Code. Assign 8: Bug. Assignment 8 Ques&ons? PROGRAMMING PARADIGMS Objec&ves RouleQe Assign 8: Refactoring for Extensibility Programming Paradigms Introduc&on to GUIs in Java Ø Event handling Nov 6, 2015 Sprenkle - CSCI209 1 Nov 6, 2015 Sprenkle - CSCI209 2 Assign 8:

More information

Java IDE Programming-I

Java IDE Programming-I Java IDE Programming-I Graphical User Interface : is an interface that uses pictures and other graphic entities along with text, to interact with user. User can interact with GUI using mouse click/ or

More information

2110: GUIS: Graphical User Interfaces

2110: GUIS: Graphical User Interfaces 2110: GUIS: Graphical User Interfaces Their mouse had a mean time between failure of a week it would jam up irreparably, or... jam up on the table--... It had a flimsy cord whose wires would break. Steve

More information

Chapter 12 Advanced GUIs and Graphics

Chapter 12 Advanced GUIs and Graphics Chapter 12 Advanced GUIs and Graphics Chapter Objectives Learn about applets Explore the class Graphics Learn about the classfont Explore the classcolor Java Programming: From Problem Analysis to Program

More information

Unit 6: Graphical User Interface

Unit 6: Graphical User Interface Faculty of Computer Science Programming Language 2 Object oriented design using JAVA Dr. Ayman Ezzat Email: ayman@fcih.net Web: www.fcih.net/ayman Unit 6: Graphical User Interface 1 1. Overview of the

More information

Introduction to the JAVA UI classes Advanced HCI IAT351

Introduction to the JAVA UI classes Advanced HCI IAT351 Introduction to the JAVA UI classes Advanced HCI IAT351 Week 3 Lecture 1 17.09.2012 Lyn Bartram lyn@sfu.ca About JFC and Swing JFC Java TM Foundation Classes Encompass a group of features for constructing

More information

PROGRAMMING DESIGN USING JAVA (ITT 303) Unit 7

PROGRAMMING DESIGN USING JAVA (ITT 303) Unit 7 PROGRAMMING DESIGN USING JAVA (ITT 303) Graphical User Interface Unit 7 Learning Objectives At the end of this unit students should be able to: Build graphical user interfaces Create and manipulate buttons,

More information

Learn Java Programming, Dr.Hashamdar. Getting Started with GUI Programming

Learn Java Programming, Dr.Hashamdar. Getting Started with GUI Programming Learn Java Programming, Dr.Hashamdar Getting Started with GUI Programming 1 Creating GUI Objects // Create a button with text OK JButton jbtok = new JButton("OK"); // Create a label with text "Enter your

More information

Chapter 6: Graphical User Interfaces

Chapter 6: Graphical User Interfaces Chapter 6: Graphical User Interfaces CS 121 Department of Computer Science College of Engineering Boise State University April 21, 2015 Chapter 6: Graphical User Interfaces CS 121 1 / 36 Chapter 6 Topics

More information

Chapter 12 GUI Basics

Chapter 12 GUI Basics Chapter 12 GUI Basics 1 Creating GUI Objects // Create a button with text OK JButton jbtok = new JButton("OK"); // Create a label with text "Enter your name: " JLabel jlblname = new JLabel("Enter your

More information

Java Graphical User Interfaces

Java Graphical User Interfaces Java Graphical User Interfaces 1 The Abstract Windowing Toolkit (AWT) Since Java was first released, its user interface facilities have been a significant weakness The Abstract Windowing Toolkit (AWT)

More information

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

Part 3: Graphical User Interface (GUI) & Java Applets 1,QWURGXFWLRQWR-DYD3URJUDPPLQJ (( Part 3: Graphical User Interface (GUI) & Java Applets EE905-GUI 7RSLFV Creating a Window Panels Event Handling Swing GUI Components ƒ Layout Management ƒ Text Field ƒ

More information

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

Starting Out with Java: From Control Structures Through Objects Sixth Edition Starting Out with Java: From Control Structures Through Objects Sixth Edition Chapter 12 A First Look at GUI Applications Chapter Topics 12.1 Introduction 12.2 Creating Windows 12.3 Equipping GUI Classes

More information

Chapter 13 GUI Basics. Liang, Introduction to Java Programming, Seventh Edition, (c) 2009 Pearson Education, Inc. All rights reserved.

Chapter 13 GUI Basics. Liang, Introduction to Java Programming, Seventh Edition, (c) 2009 Pearson Education, Inc. All rights reserved. Chapter 13 GUI Basics 1 Motivations The design of the API for Java GUI programming is an excellent example of how the object-oriented principle is applied. In the chapters that follow, you will learn the

More information

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

CSE 143. Event-driven Programming and Graphical User Interfaces (GUIs) with Swing/AWT CSE 143 Event-driven Programming and Graphical User Interfaces (GUIs) with Swing/AWT slides created by Marty Stepp based on materials by M. Ernst, S. Reges, D. Notkin, R. Mercer, Wikipedia http://www.cs.washington.edu/331/

More information

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

Graphics programming. COM6516 Object Oriented Programming and Design Adam Funk (originally Kirill Bogdanov & Mark Stevenson) Graphics programming COM6516 Object Oriented Programming and Design Adam Funk (originally Kirill Bogdanov & Mark Stevenson) Overview Aims To provide an overview of Swing and the AWT To show how to build

More information

Chapter 12 GUI Basics. Motivations. The design of the API for Java GUI programming

Chapter 12 GUI Basics. Motivations. The design of the API for Java GUI programming Chapter 12 GUI Basics 1 Motivations The design of the API for Java GUI programming is an excellent example of how the object-orientedoriented principle is applied. In the chapters that follow, you will

More information

Tool Kits, Swing. Overview. SMD158 Interactive Systems Spring Tool Kits in the Abstract. An overview of Swing/AWT

Tool Kits, Swing. Overview. SMD158 Interactive Systems Spring Tool Kits in the Abstract. An overview of Swing/AWT INSTITUTIONEN FÖR Tool Kits, Swing SMD158 Interactive Systems Spring 2005 Jan-28-05 2002-2005 by David A. Carr 1 L Overview Tool kits in the abstract An overview of Swing/AWT Jan-28-05 2002-2005 by David

More information

CS111: PROGRAMMING LANGUAGE II

CS111: PROGRAMMING LANGUAGE II CS111: PROGRAMMING LANGUAGE II Computer Science Department Lecture 10(b): Working with Controls Agenda 2 Case study: TextFields and Labels Combo Boxes buttons List manipulation Radio buttons and checkboxes

More information

Contents Introduction 1

Contents Introduction 1 SELF-STUDY iii Introduction 1 Course Purpose... 1 Course Goals...1 Exercises... 2 Scenario-Based Learning... 3 Multimedia Overview... 3 Assessment... 3 Hardware and Software Requirements... 4 Chapter 1

More information

CS 251 Intermediate Programming GUIs: Components and Layout

CS 251 Intermediate Programming GUIs: Components and Layout CS 251 Intermediate Programming GUIs: Components and Layout Brooke Chenoweth University of New Mexico Fall 2017 import javax. swing.*; Hello GUI public class HelloGUI extends JFrame { public HelloGUI ()

More information

Dr. Hikmat A. M. AbdelJaber

Dr. Hikmat A. M. AbdelJaber Dr. Hikmat A. M. AbdelJaber JWindow: is a window without a title bar or move controls. The program can move and resize it, but the user cannot. It has no border at all. It optionally has a parent JFrame.

More information

Introduction p. 1 JFC Architecture p. 5 Introduction to JFC p. 7 The JFC 1.2 Extension p. 8 Swing p. 9 Drag and Drop p. 16 Accessibility p.

Introduction p. 1 JFC Architecture p. 5 Introduction to JFC p. 7 The JFC 1.2 Extension p. 8 Swing p. 9 Drag and Drop p. 16 Accessibility p. Introduction p. 1 JFC Architecture p. 5 Introduction to JFC p. 7 The JFC 1.2 Extension p. 8 Swing p. 9 Drag and Drop p. 16 Accessibility p. 17 MVC Architecture p. 19 The MVC Architecture p. 20 Combined

More information

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

Introduction to Graphical User Interfaces (GUIs) Lecture 10 CS2110 Fall 2008 Introduction to Graphical User Interfaces (GUIs) Lecture 10 CS2110 Fall 2008 Announcements A3 is up, due Friday, Oct 10 Prelim 1 scheduled for Oct 16 if you have a conflict, let us know now 2 Interactive

More information

BASICS OF GRAPHICAL APPS

BASICS OF GRAPHICAL APPS CSC 2014 Java Bootcamp Lecture 7 GUI Design BASICS OF GRAPHICAL APPS 2 Graphical Applications So far we ve focused on command-line applications, which interact with the user using simple text prompts In

More information

TTTK Program Design and Problem Solving Tutorial 3 (GUI & Event Handlings)

TTTK Program Design and Problem Solving Tutorial 3 (GUI & Event Handlings) TTTK1143 - Program Design and Problem Solving Tutorial 3 (GUI & Event Handlings) Topic: JApplet and ContentPane. 1. Complete the following class to create a Java Applet whose pane s background color is

More information

Java Programming Lecture 6

Java Programming Lecture 6 Java Programming Lecture 6 Alice E. Fischer Feb 15, 2013 Java Programming - L6... 1/32 Dialog Boxes Class Derivation The First Swing Programs: Snow and Moving The Second Swing Program: Smile Swing Components

More information

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

12/22/11. Copyright by Pearson Education, Inc. All Rights Reserved. } Radio buttons (declared with class JRadioButton) are similar to checkboxes in that they have two states selected and not selected (also called deselected). } Radio buttons normally appear as a group

More information

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

CSE 331. Event-driven Programming and Graphical User Interfaces (GUIs) with Swing/AWT CSE 331 Event-driven Programming and Graphical User Interfaces (GUIs) with Swing/AWT slides created by Marty Stepp based on materials by M. Ernst, S. Reges, D. Notkin, R. Mercer, Wikipedia http://www.cs.washington.edu/331/

More information

Sri Vidya College of Engineering & Technology

Sri Vidya College of Engineering & Technology UNIT-V TWO MARKS QUESTION & ANSWER 1. What is the difference between the Font and FontMetrics class? Font class is used to set or retrieve the screen fonts.the Font class maps the characters of the language

More information

Introduction. Introduction

Introduction. Introduction Introduction Many Java application use a graphical user interface or GUI (pronounced gooey ). A GUI is a graphical window or windows that provide interaction with the user. GUI s accept input from: the

More information

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

Command-Line Applications. GUI Libraries GUI-related classes are defined primarily in the java.awt and the javax.swing packages. 1 CS257 Computer Science I Kevin Sahr, PhD Lecture 14: Graphical User Interfaces Command-Line Applications 2 The programs we've explored thus far have been text-based applications A Java application is

More information

Packages: Putting Classes Together

Packages: Putting Classes Together Packages: Putting Classes Together 1 Introduction 2 The main feature of OOP is its ability to support the reuse of code: Extending the classes (via inheritance) Extending interfaces The features in basic

More information

Graphic User Interfaces. - GUI concepts - Swing - AWT

Graphic User Interfaces. - GUI concepts - Swing - AWT Graphic User Interfaces - GUI concepts - Swing - AWT 1 What is GUI Graphic User Interfaces are used in programs to communicate more efficiently with computer users MacOS MS Windows X Windows etc 2 Considerations

More information

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

All the Swing components start with J. The hierarchy diagram is shown below. JComponent is the base class. Q1. If you add a component to the CENTER of a border layout, which directions will the component stretch? A1. The component will stretch both horizontally and vertically. It will occupy the whole space

More information

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

CONTENTS. Chapter 1 Getting Started with Java SE 6 1. Chapter 2 Exploring Variables, Data Types, Operators and Arrays 13 CONTENTS Chapter 1 Getting Started with Java SE 6 1 Introduction of Java SE 6... 3 Desktop Improvements... 3 Core Improvements... 4 Getting and Installing Java... 5 A Simple Java Program... 10 Compiling

More information

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

CSE 331. Event- driven Programming and Graphical User Interfaces (GUIs) with Swing/AWT CSE 331 Event- driven Programming and Graphical User Interfaces (GUIs) with Swing/AWT Lecturer: Michael Hotan slides created by Marty Stepp based on materials by M. Ernst, S. Reges, D. Notkin, R. Mercer,

More information

Java. GUI building with the AWT

Java. GUI building with the AWT Java GUI building with the AWT AWT (Abstract Window Toolkit) Present in all Java implementations Described in most Java textbooks Adequate for many applications Uses the controls defined by your OS therefore

More information

Window Interfaces Using Swing Objects

Window Interfaces Using Swing Objects Chapter 12 Window Interfaces Using Swing Objects Event-Driven Programming and GUIs Swing Basics and a Simple Demo Program Layout Managers Buttons and Action Listeners Container Classes Text I/O for GUIs

More information

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

What is Widget Layout? Laying Out Components. Resizing a Window. Hierarchical Widget Layout. Interior Design for GUIs What is Widget Layout? Laying Out Components Positioning widgets in their container (typically a JPanel or a JFrame s content pane) Basic idea: each widget has a size and position Main problem: what if

More information

Part I: Learn Common Graphics Components

Part I: Learn Common Graphics Components OOP GUI Components and Event Handling Page 1 Objectives 1. Practice creating and using graphical components. 2. Practice adding Event Listeners to handle the events and do something. 3. Learn how to connect

More information

Graphical User Interface (GUI)

Graphical User Interface (GUI) Graphical User Interface (GUI) Layout Managment 1 Hello World Often have a static method: createandshowgui() Invoked by main calling invokelater private static void createandshowgui() { } JFrame frame

More information

Summary Chapter 25 GUI Components: Part 2

Summary Chapter 25 GUI Components: Part 2 1040 Chapter 25 GUI Components: Part 2 ponent on the line. TheJTextField is added to the content pane with a call to our utility method addcomponent (declared at lines 79 83). MethodaddComponent takes

More information

Object-Oriented Programming Design. Topic : User Interface Components with Swing GUI Part III

Object-Oriented Programming Design. Topic : User Interface Components with Swing GUI Part III Electrical and Computer Engineering Object-Oriented Topic : User Interface Components with Swing GUI Part III Maj Joel Young Joel.Young@afit.edu 17-Sep-03 Maj Joel Young Creating GUI Apps The Process Overview

More information

What Is an Event? Some event handler. ActionEvent. actionperformed(actionevent e) { }

What Is an Event? Some event handler. ActionEvent. actionperformed(actionevent e) { } CBOP3203 What Is an Event? Events Objects that describe what happened Event Sources The generator of an event Event Handlers A method that receives an event object, deciphers it, and processes the user

More information

China Jiliang University Java. Programming in Java. Java Swing Programming. Java Web Applications, Helmut Dispert

China Jiliang University Java. Programming in Java. Java Swing Programming. Java Web Applications, Helmut Dispert Java Programming in Java Java Swing Programming Java Swing Design Goals The overall goal for the Swing project was: To build a set of extensible GUI components to enable developers to more rapidly develop

More information

Agenda. Container and Component

Agenda. Container and Component Agenda Types of GUI classes/objects Step-by-step guide to create a graphic user interface Step-by-step guide to event-handling PS5 Problem 1 PS5 Problem 2 Container and Component There are two types of

More information

Laying Out Components. What is Widget Layout?

Laying Out Components. What is Widget Layout? Laying Out Components Interior Design for GUIs What is Widget Layout? Positioning widgets in their container (typically a JPanel or a JFrame s content pane) Basic idea: each widget has a size and position

More information

CPS122 Lecture: Graphical User Interfaces and Event-Driven Programming

CPS122 Lecture: Graphical User Interfaces and Event-Driven Programming CPS122 Lecture: Graphical User Interfaces and Event-Driven Programming Objectives: Last revised March 2, 2017 1. To introduce the notion of a component and some basic Swing components (JLabel, JTextField,

More information

Programming graphics

Programming graphics Programming graphics Need a window javax.swing.jframe Several essential steps to use (necessary plumbing ): Set the size width and height in pixels Set a title (optional), and a close operation Make it

More information

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

Course Status Networking GUI Wrap-up. CS Java. Introduction to Java. Andy Mroczkowski 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

More information

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

Goals. Lecture 7 More GUI programming. The application. The application D&D 12. CompSci 230: Semester JFrame subclass: ListOWords Goals By the end of this lesson, you should: Lecture 7 More GUI programming 1. Be able to write Java s with JTextField, JList, JCheckBox and JRadioButton components 2. Be able to implement a ButtonGroup

More information

JBuilder 8.0 JFC and Swing Programming

JBuilder 8.0 JFC and Swing Programming TEAMFLY JBuilder 8.0 JFC and Swing Programming Chuck Easttom Wordware Publishing, Inc. Library of Congress Cataloging-in-Publication Data Easttom, Chuck. JBuilder 8.0 JFC and Swing programming / by Chuck

More information

JAVA NOTES GRAPHICAL USER INTERFACES

JAVA NOTES GRAPHICAL USER INTERFACES 1 JAVA NOTES GRAPHICAL USER INTERFACES Terry Marris 24 June 2001 5 TEXT AREAS 5.1 LEARNING OUTCOMES By the end of this lesson the student should be able to understand how to get multi-line input from the

More information

Window Interfaces Using Swing Objects

Window Interfaces Using Swing Objects Chapter 12 Window Interfaces Using Swing Objects Event-Driven Programming and GUIs Swing Basics and a Simple Demo Program Layout Managers Buttons and Action Listeners Container Classes Text I/O for GUIs

More information

The AWT Package, An Overview

The AWT Package, An Overview Richard G Baldwin (512) 223-4758, baldwin@austin.cc.tx.us, http://www2.austin.cc.tx.us/baldwin/ The AWT Package, An Overview Java Programming, Lecture Notes # 110, Revised 02/21/98. Preface Introduction

More information

Lecture 18 Java Graphics and GUIs

Lecture 18 Java Graphics and GUIs CSE 331 Software Design and Implementation The plan Today: introduction to Java graphics and Swing/AWT libraries Then: event-driven programming and user interaction Lecture 18 Java Graphics and GUIs None

More information

CHAPTER 2. Java Overview

CHAPTER 2. Java Overview Networks and Internet Programming (0907522) CHAPTER 2 Java Overview Instructor: Dr. Khalid A. Darabkh Objectives The objectives of this chapter are: To discuss the classes present in the java.awt package

More information

Graphical User Interfaces

Graphical User Interfaces Graphical User Interfaces CSCI 136: Fundamentals CSCI 136: Fundamentals of Computer of Science Computer II Science Keith II Vertanen Keith Vertanen Copyright 2011 Overview Command line versus GUI apps

More information

Lecture 5: Java Graphics

Lecture 5: Java Graphics Lecture 5: Java Graphics CS 62 Spring 2019 William Devanny & Alexandra Papoutsaki 1 New Unit Overview Graphical User Interfaces (GUI) Components, e.g., JButton, JTextField, JSlider, JChooser, Containers,

More information

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

Topic 9: Swing. Swing is a BIG library Goal: cover basics give you concepts & tools for learning more Swing = Java's GUI library Topic 9: Swing Swing is a BIG library Goal: cover basics give you concepts & tools for learning more Assignment 5: Will be an open-ended Swing project. "Programming Contest"

More information

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!

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! Swing = Java's GUI library Topic 9: Swing Swing is a BIG library Goal: cover basics give you concepts & tools for learning more Why are we studying Swing? 1. Useful & fun! 2. Good application of OOP techniques

More information

Graphics. Lecture 18 COP 3252 Summer June 6, 2017

Graphics. Lecture 18 COP 3252 Summer June 6, 2017 Graphics Lecture 18 COP 3252 Summer 2017 June 6, 2017 Graphics classes In the original version of Java, graphics components were in the AWT library (Abstract Windows Toolkit) Was okay for developing simple

More information

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

Java Swing. based on slides by: Walter Milner. Java Swing Walter Milner 2005: Slide 1 Java Swing based on slides by: Walter Milner Java Swing Walter Milner 2005: Slide 1 What is Swing? A group of 14 packages to do with the UI 451 classes as at 1.4 (!) Part of JFC Java Foundation Classes

More information

Introduction to Graphical Interface Programming in Java. Introduction to AWT and Swing

Introduction to Graphical Interface Programming in Java. Introduction to AWT and Swing Introduction to Graphical Interface Programming in Java Introduction to AWT and Swing GUI versus Graphics Programming Graphical User Interface (GUI) Graphics Programming Purpose is to display info and

More information

Containers and Components

Containers and Components Containers and Components container A GUI has many components in containers. A container contains other components. A container is also a component; so a container may contain other containers. component

More information

To gain experience using GUI components and listeners.

To gain experience using GUI components and listeners. Lab 5 Handout 7 CSCI 134: Fall, 2017 TextPlay Objective To gain experience using GUI components and listeners. Note 1: You may work with a partner on this lab. If you do, turn in only one lab with both

More information

CSE 331 Software Design & Implementation

CSE 331 Software Design & Implementation CSE 331 Software Design & Implementation Hal Perkins Winter 2018 Java Graphics and GUIs 1 The plan Today: introduction to Java graphics and Swing/AWT libraries Then: event-driven programming and user interaction

More information

Widgets. Widgets Widget Toolkits. User Interface Widget

Widgets. Widgets Widget Toolkits. User Interface Widget Widgets Widgets Widget Toolkits 2.3 Widgets 1 User Interface Widget Widget is a generic name for parts of an interface that have their own behavior: buttons, drop-down menus, spinners, file dialog boxes,

More information

Systems Programming Graphical User Interfaces

Systems Programming Graphical User Interfaces Systems Programming Graphical User Interfaces Julio Villena Román (LECTURER) CONTENTS ARE MOSTLY BASED ON THE WORK BY: José Jesús García Rueda Systems Programming GUIs based on Java

More information

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

Parts of a Contract. Contract Example. Interface as a Contract. Wednesday, January 30, 13. Postcondition. Preconditions. Parts of a Contract Syntax - Method signature Method name Parameter list Return type Semantics - Comments Preconditions: requirements placed on the caller Postconditions: what the method modifies and/or

More information

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

Datenbank-Praktikum. Universität zu Lübeck Sommersemester 2006 Lecture: Swing. Ho Ngoc Duc 1 Datenbank-Praktikum Universität zu Lübeck Sommersemester 2006 Lecture: Swing Ho Ngoc Duc 1 Learning objectives GUI applications Font, Color, Image Running Applets as applications Swing Components q q Text

More information

CSE 1325 Project Description

CSE 1325 Project Description CSE 1325 Summer 2016 Object-Oriented and Event-driven Programming (Using Java) Instructor: Soumyava Das Graphical User Interface (GUI), Event Listeners and Handlers Project IV Assigned On: 07/28/2016 Due

More information

Top-Level Containers

Top-Level Containers 1. Swing Containers Swing containers can be classified into three main categories: Top-level containers: JFrame, JWindow, and JDialog General-purpose containers: JPanel, JScrollPane,JToolBar,JSplitPane,

More information

Basicsof. JavaGUI and SWING

Basicsof. JavaGUI and SWING Basicsof programming3 JavaGUI and SWING GUI basics Basics of programming 3 BME IIT, Goldschmidt Balázs 2 GUI basics Mostly window-based applications Typically based on widgets small parts (buttons, scrollbars,

More information

IS311 Programming Concepts. GUI Building with Swing

IS311 Programming Concepts. GUI Building with Swing IS311 Programming Concepts GUI Building with Swing 1 Agenda Java GUI Support AWT Swing Creating GUI Applications Layout Managers 2 ต องม พ นความร ต อไปน ก อน Classes / Objects Method Overloading Inheritance

More information

Agenda. GUI Building with Swing ต องม พ นความร ต อไปน ก อน. Java Graphical User Interfaces. IS311 Programming Concepts

Agenda. GUI Building with Swing ต องม พ นความร ต อไปน ก อน. Java Graphical User Interfaces. IS311 Programming Concepts IS311 Programming Concepts GUI Building with Swing Agenda Java GUI Support AWT Swing Creating GUI Applications Layout Managers 1 2 ต องม พ นความร ต อไปน ก อน Classes / Objects Method Overloading Inheritance

More information

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

Lab 4. D0010E Object-Oriented Programming and Design. Today s lecture. GUI programming in Lab 4 D0010E Object-Oriented Programming and Design Lecture 9 Lab 4: You will implement a game that can be played over the Internet. The networking part has already been written. Among other things, the

More information

Building Java Programs Bonus Slides

Building Java Programs Bonus Slides Building Java Programs Bonus Slides Graphical User Interfaces Copyright (c) Pearson 2013. All rights reserved. Graphical input and output with JOptionPane JOptionPane An option pane is a simple dialog

More information

Resizing a Window. COSC 3461: Module 5B. What is Widget Layout? Size State Transitions. What is Widget Layout? Hierarchical Widget Layout.

Resizing a Window. COSC 3461: Module 5B. What is Widget Layout? Size State Transitions. What is Widget Layout? Hierarchical Widget Layout. COSC 3461: Module 5B Resizing a Window Widgets II What has changed? scrollbar added menu has wrapped toolbar modified (buttons lost) 2 What is Widget Layout? Size State Transitions Recall: each widget

More information

import javax.swing.*; public class Sample { JFrame f; Sample(){ f=new JFrame(); JButton b=new JButton("click"); b.setbounds(130,100,100, 40); f.add(b); f.setsize(400,500); f.setlayout(null); f.setvisible(true);

More information

CSSE 220 Day 19. Object-Oriented Design Files & Exceptions. Check out FilesAndExceptions from SVN

CSSE 220 Day 19. Object-Oriented Design Files & Exceptions. Check out FilesAndExceptions from SVN CSSE 220 Day 19 Object-Oriented Design Files & Exceptions Check out FilesAndExceptions from SVN A practical technique OBJECT-ORIENTED DESIGN Object-Oriented Design We won t use full-scale, formal methodologies

More information

Swing Programming Example Number 2

Swing Programming Example Number 2 1 Swing Programming Example Number 2 Problem Statement (Part 1 and 2 (H/w- assignment) 2 Demonstrate the use of swing Label, TextField, RadioButton, CheckBox, Listbox,Combo Box, Toggle button,image Icon

More information

DM550 / DM857 Introduction to Programming. Peter Schneider-Kamp

DM550 / DM857 Introduction to Programming. Peter Schneider-Kamp DM550 / DM857 Introduction to Programming Peter Schneider-Kamp petersk@imada.sdu.dk http://imada.sdu.dk/~petersk/dm550/ http://imada.sdu.dk/~petersk/dm857/ GRAPHICAL USER INTERFACES 2 HelloWorld Reloaded

More information

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

The Java Programming Language Basics. Identifiers, Keywords, and Types. Expressions and Flow Control. Object-Oriented Programming. Objects and Classes Building GUIs 8 Course Map This module covers setup and layout of graphical user interfaces. It introduces the Abstract Windowing Toolkit, a package of classes from which GUIs are built. Getting Started

More information

GUI in Java TalentHome Solutions

GUI in Java TalentHome Solutions 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

More information

CSSE 220 Day 19. Object-Oriented Design Files & Exceptions. Check out FilesAndExceptions from SVN

CSSE 220 Day 19. Object-Oriented Design Files & Exceptions. Check out FilesAndExceptions from SVN CSSE 220 Day 19 Object-Oriented Design Files & Exceptions Check out FilesAndExceptions from SVN A practical technique OBJECT-ORIENTED DESIGN Object-Oriented Design We won t use full-scale, formal methodologies

More information

EVENTS, EVENT SOURCES AND LISTENERS

EVENTS, EVENT SOURCES AND LISTENERS Java Programming EVENT HANDLING Arash Habibi Lashkari Ph.D. Candidate of UTM University Kuala Lumpur, Malaysia All Rights Reserved 2010, www.ahlashkari.com EVENTS, EVENT SOURCES AND LISTENERS Important

More information

Chapter 7: A First Look at GUI Applications

Chapter 7: A First Look at GUI Applications Chapter 7: A First Look at GUI Applications Starting Out with Java: From Control Structures through Objects Fourth Edition by Tony Gaddis Addison Wesley is an imprint of 2010 Pearson Addison-Wesley. All

More information

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

CSE Lab 8 Assignment Note: This is the last lab for CSE 1341 CSE 1341 - Lab 8 Assignment Note: This is the last lab for CSE 1341 Pre-Lab : There is no pre-lab this week. Lab (100 points) The objective of Lab 8 is to get familiar with and utilize the wealth of Java

More information

Java 1.9 Swing Index

Java 1.9 Swing Index One Introduction to Java 2 Usage of Java 3 Structure of Java 4 Flexibility of Java Programming 5 Swing and AWT in Java 6 Two Using Java in DOS 9 Using the DOS window 10 DOS Operating System Commands 11

More information

Using Several Components

Using Several Components Ch. 16 pt 2 GUIs Using Several Components How do we arrange the GUI components? Using layout managers. How do we respond to event from several sources? Create separate listeners, or determine the source

More information

SD Module-1 Advanced JAVA

SD Module-1 Advanced JAVA Assignment No. 4 SD Module-1 Advanced JAVA R C (4) V T Total (10) Dated Sign Title: Transform the above system from command line system to GUI based application Problem Definition: Write a Java program

More information

Announcements. Introduction. Lecture 18 Java Graphics and GUIs. Announcements. CSE 331 Software Design and Implementation

Announcements. Introduction. Lecture 18 Java Graphics and GUIs. Announcements. CSE 331 Software Design and Implementation CSE 331 Software Design and Implementation Lecture 18 Java Graphics and GUIs Announcements Leah Perlmutter / Summer 2018 Announcements Quiz 6 due Thursday 8/2 Homework 7 due Thursday 8/2 Regression testing

More information