Swing Programming Example Number 2

Size: px
Start display at page:

Download "Swing Programming Example Number 2"

Transcription

1 1 Swing Programming Example Number 2

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 and Table with suitable example Extend the application to support the use of saving data in class [Design hint] Design the same application using Applet[Saturday] and doubt clearance

3 Required GUI-I 3

4 Required GUI-II 4

5 Required classes to be imported.. 5 import java.awt.*; import java.awt.event.*; import javax.swing.*; import javax.swing.event.*; import javax.swing.table.defaulttablemodel;

6 Our main class 6 public class SwingExample2 { public static void main(string[] args) { SwingUtilities.invokeLater(new Runnable() { public void run(){new SwingDemoEx2();}} ); } } //to create a thread which takes off responsibility from main thread

7 Our test class.. 7 class SwingDemoEx2 { public SwingDemoEx2 () { JFrameDemo2 frame=new JFrameDemo2(); frame.setdefaultcloseoperation(jframe.exit_on_close); frame.setvisible(true); } NH/Swing }// Programming create /2012/CS-A/SIT (customized)jframe class s object and sets visibility.

8 Customized JFrame (class extends JFrame) 8 class JFrameDemo2 extends JFrame {

9 Our Frame (Declaration..) 9 Container contentpane; JPanel p,p1,p2,p3,p4,p5,p6,p7; JLabel lbl1; JTabbedPane Tab1;

10 Our Frame (Declaration..) [Buttons,Togglebutton, TextField,Radio Button,Check Box,List,Table,Combo,Scrollpane] 10 JTextField t1,t2,t3,t4,t5,t6,tname,tusn; JToggleButton Tbtn1; JButton btn1; JRadioButton rbtn1, rbtn2; JCheckBox c1,c2; List<String> list1; JComboBox<String> cmbo1; JScrollPane jsp1,jsp2; DefaultTableModel model; JTable table;

11 Our Frame (Listener interface reference variables 11 ActionListener acl1; //buttons events ItemListener iteml1; //Toggle buttons events ListSelectionListener lstact; //list box events //any other declaration here

12 Any other declaration 12 StudentSwing std; //declare StudentSwing

13 Panel creation another member method of our frame 13 void createpaneles() //user defined methods to create as many panels { p=new JPanel(); //General p1=new JPanel(); //Textbox-Name p2=new JPanel(); //Radio Button-Section p3=new JPanel(); //Check box-education p4=new JPanel(); //Combobox-Electives 1 p5=new JPanel(); //Listbox-Electives 1 p6=new JPanel(); //Table -Display Data p7=new JPanel(); //Buttons-Actions-Save,Exit,Show }

14 AddTabs: member of our class (user defined method to add panes,tab name to tab.] 14 void AddTabs(JTabbedPane Jtab,String Title,JPanel p) { Jtab.addTab(Title, p); }

15 User defined method to add Label, textfield to panel setting editable property. 15 JTextField AddTextFieldLabel(String title,jpanel p, int size,boolean flag) { p.add(new JLabel(title)); JTextField txtfield=new JTextField(size); txtfield.seteditable(flag); p.add(txtfield); return(txtfield); }

16 Our frame s constructor 16 public JFrameDemo2() { settitle("swing Demonstration <Unit 4> "); //setting title setsize(400,450); /Setting size of window

17 Creating content pane,setting its layout, creating panels, creating TabedPane 17 contentpane = getcontentpane(); contentpane.setlayout(new GridLayout(3,1)); createpanles(); Tab1 = new JTabbedPane();

18 Creating object of events class extend interface Action:button, ItemListener: Toggle, ListSelection:List 18 acl1=new CommandActionButton(); lstact=new ListSelection(); iteml1=new CommandActionToggleButton();

19 Adding editable TextField and Label to first tab 19 t1=addtextfieldlabel("name:",p1,10,true); AddTabs(Tab1,"Name",p1);

20 After adding tab and panel GUI look like.. 20

21 Adds textfield, grouped Radio button [Under 2 nd tab] Sets command and registers for events 21 t2=addtextfieldlabel("section:",p2,10,false); ButtonGroup group = new ButtonGroup(); rbtn1 = new JRadioButton("A"); rbtn2 = new JRadioButton("B"); group.add(rbtn1); group.add(rbtn2); rbtn1.setactioncommand("a"); rbtn2.setactioncommand("b"); rbtn1.addactionlistener(acl1); rbtn2.addactionlistener(acl1); p2.add(rbtn1); p2.add(rbtn2); AddTabs(Tab1,"Section",p2);

22 After adding tab and panel GUI look like.. 22

23 Add check box under 3 rd Tab set command and register events 23 t3=addtextfieldlabel("education:",p3,10,false); c1 = new JCheckBox("PU"); c2 = new JCheckBox("DIP"); c1.setactioncommand("pu"); c2.setactioncommand("dip"); c1.addactionlistener(acl1); c2.addactionlistener(acl1); p3.add(c1); p3.add(c2); AddTabs(Tab1,"Education",p3);

24 After adding tab and panel GUI look like.. 24

25 Add combo box under 4th tab 25 t4=addtextfieldlabel("elective I:",p4,10,false); String[] El1={"ADBMS","DSP","Java","DM","MC","NN"}; cmbo1=new JComboBox<String> (El1); cmbo1.setactioncommand("el1"); cmbo1.addactionlistener(acl1); p4.add(cmbo1); AddTabs(Tab1,"Elective I:",p4);

26 After adding tab and panel GUI look like.. 26

27 Add list box with under 5th tab 27 t5=addtextfieldlabel("elective II:",p5,10,false); String[] El2 ={".Net","DIP","GT","AI","VLSI","FL"}; list1=new JList<String> (El2); list1.addlistselectionlistener(lstact); jsp1=new JScrollPane(list1); jsp1.setpreferredsize(new Dimension(120,70)); AddTabs(Tab1,"Elective II:",p5); p5.add(jsp1);

28 After adding tab and panel GUI look like.. 28

29 Create table and set and name 5 columns 29 model = new DefaultTableModel(); table = new JTable(model); model.addcolumn("name"); model.addcolumn("section"); model.addcolumn("edu"); model.addcolumn("el1"); model.addcolumn("el2");

30 Add scroll pane to hold table 30 jsp2 = new JScrollPane(table); jsp2.setpreferredsize(new Dimension(300,100)); p6.add(jsp2);

31 After adding tab and panel GUI look like.. 31

32 Add toggle button and register events-item listener 32 lbl1=new JLabel(""); Tbtn1=new JToggleButton("Save"); Tbtn1.addItemListener(iteml1);

33 Add a button, set image, register events 33 btn1=new JButton("Exit"); ImageIcon imagebox=new ImageIcon(getClass().getResource("Power.gif")); btn1.seticon(imagebox); btn1.setactioncommand("exit"); btn1.addactionlistener(acl1);

34 Add toggle button and abstract button 34 p7.add(lbl1); p7.add(tbtn1); p7.add(btn1);

35 Add tab to general panel add remaining panels container 35 p.add(tab1); contentpane.add(p); contentpane.add(p6); contentpane.add(p7); } //end of our frame s constructor

36 Extend event handling (topics of 3 rd Unit) 36 //nested inner class for our frame private class CommandActionButton implements ActionListener //for JButton { public void actionperformed(actionevent ae) {

37 Based on command (retrieved after click) define functionality to components 37 switch ((String)ae.getActionCommand()) {

38 Define function for radio button click 38 case "A": case "B": //to set section A t2.settext("a"); break; //to set section B t2.settext("b"); break;

39 Define functionalities for check box 39 case "PU": case "DIP": String br1="",br2=""; if (c1.isselected()) br1="pu "; if (c2.isselected()) br2=" DIP"; t3.settext(br1+br2); break;

40 Define function for combobox 40 case "El1": t4.settext((string)cmbo1.getselecteditem()); break;

41 Function to stop application 41 case "Exit": System.exit(0); break; } } }

42 Events (Inner class) to handle selection from list 42 private class ListSelection implements ListSelectionListener { public void valuechanged(listselectionevent ae) { t5.settext(list1.getselectedvalue()); } }

43 Events (Inner class) to handle toggling 43 private class CommandActionToggleButton implements ItemListener { public void itemstatechanged(itemevent ae) { if (Tbtn1.isSelected()) { Tbtn1.setText("Show"); lbl1.settext("status:saving..."); } else { Tbtn1.setText("Save"); lbl1.settext("status:display..."); model.addrow(new String[] { t1.gettext(),t2.gettext(),t3.gettext(),t4.gettext(),t5.gettext() } ); } } } }//Our frame class

44 To support external class to hold data define class StudentSwing 44 public class StudentSwing { String Name,Sec,Edu,El1, El2; public StudentSwing(String Name,String Sec,String Edu,String El1,String El2){ this.name=name; this.sec=sec; this.edu=edu; this.el1=el1; this.el2=el2; } public String getname() { return Name; } public String getsec() { return Sec; } public String getedu() { return Edu; } public String getel1() { return El1; } public String getel2() { return El2 } } Back to declaration Part

45 Create class when Save is clicked Display data into table 45????????????????

46 2 line editing 46 Tbtn1.setText("Show"); lbl1.settext("status:saving..."); std=new StudentSwing(t1.getText(),t2.getText(),t3.getText(),t4.getText(),t5.getText()); //add above line creates StudentSwing objects lbl1.settext("status:display..."); model.addrow( new String[]{std.getName(),std.getSec(),std.getEdu(),std.getEl1(),std.getEl2()});

47 Swing : Using JApplet 47 Little modification needed for the existing program

48 Note: no change in import 48 import java.awt.*; import java.awt.event.*; import javax.swing.*; import javax.swing.event.*; import javax.swing.table.defaulttablemodel;

49 Extend from JApplet 49 public class SwingExample2Applet extends JApplet { All declaration same from Container contentpane; ItemListener iteml1; ActionListener acl1; ListSelectionListener lstact; StudentSwing std;

50 Observe: NO Main thread (because it is JApplet) 50 public void init(){ try { SwingUtilities.invokeLater(new Runnable(){ public void run(){ SwingDemoEx2();}}); } catch(exception e) { } } void SwingDemoEx2() { contentpane = getcontentpane(); //starting point //Remaining code is same till end --- }//our applet ends here

51 51 END

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

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

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

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

Graphical User Interface (GUI) components in Java Applets. With Abstract Window Toolkit (AWT) we can build an applet that has the basic GUI CBOP3203 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.

More information

JRadioButton account_type_radio_button2 = new JRadioButton("Current"); ButtonGroup account_type_button_group = new ButtonGroup();

JRadioButton account_type_radio_button2 = new JRadioButton(Current); ButtonGroup account_type_button_group = new ButtonGroup(); Q)Write a program to design an interface containing fields User ID, Password and Account type, and buttons login, cancel, edit by mixing border layout and flow layout. Add events handling to the button

More information

Client-side GUI. A simple Swing-gui for searching for proudcts

Client-side GUI. A simple Swing-gui for searching for proudcts Client-side GUI A simple Swing-gui for searching for proudcts Working from a sketch to a rough GUI We make a list of the features / requirements We ll then start with a sketch of how a GUI for searching

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

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

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

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

Chapter 13 Lab Advanced GUI Applications Lab Objectives. Introduction. Task #1 Creating a Menu with Submenus

Chapter 13 Lab Advanced GUI Applications Lab Objectives. Introduction. Task #1 Creating a Menu with Submenus Chapter 13 Lab Advanced GUI Applications Lab Objectives Be able to add a menu to the menu bar Be able to use nested menus Be able to add scroll bars, giving the user the option of when they will be seen.

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

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

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

CompSci 125 Lecture 17. GUI: Graphics, Check Boxes, Radio Buttons CompSci 125 Lecture 17 GUI: Graphics, Check Boxes, Radio Buttons Announcements GUI Review Review: Inheritance Subclass is a Parent class Includes parent s features May Extend May Modify extends! Parent

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

Interfaces & Polymorphism part 2: Collections, Comparators, and More fun with Java graphics

Interfaces & Polymorphism part 2: Collections, Comparators, and More fun with Java graphics Interfaces & Polymorphism part 2: Collections, Comparators, and More fun with Java graphics 1 Collections (from the Java tutorial)* A collection (sometimes called a container) is simply an object that

More information

Chapter 4. Swing 18 marks

Chapter 4. Swing 18 marks Chapter 4 Swing 18 marks 1) Distinguish Between the Swing and AWT Ans: Swing It uses javax.swing package. It uses JApplet class Swing is light weight component It is Platform independent code Swing Support

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

The JFrame Class Frame Windows GRAPHICAL USER INTERFACES. Five steps to displaying a frame: 1) Construct an object of the JFrame class

The JFrame Class Frame Windows GRAPHICAL USER INTERFACES. Five steps to displaying a frame: 1) Construct an object of the JFrame class CHAPTER GRAPHICAL USER INTERFACES 10 Slides by Donald W. Smith TechNeTrain.com Final Draft 10/30/11 10.1 Frame Windows Java provides classes to create graphical applications that can run on any major graphical

More information

Advanced Java Programming. Swing. Introduction to Swing. Swing libraries. Eran Werner, Tel-Aviv University Summer, 2005

Advanced Java Programming. Swing. Introduction to Swing. Swing libraries. Eran Werner, Tel-Aviv University Summer, 2005 Advanced Java Programming Swing Eran Werner, Tel-Aviv University Summer, 2005 19 May 2005 Advanced Java Programming, Summer 2005 1 Introduction to Swing The Swing package is part of the Java Foundation

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

navlakhi.com / navlakhi.education / navlakhi.mobi / navlakhi.org 1

navlakhi.com / navlakhi.education / navlakhi.mobi / navlakhi.org 1 Example 1 public class ex1 extends JApplet public void init() Container c=getcontentpane(); c.setlayout(new GridLayout(5,2)); JButton b1=new JButton("Add"); JButton b2=new JButton("Search"); JLabel l1=new

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

CSC 1214: Object-Oriented Programming

CSC 1214: Object-Oriented Programming CSC 1214: Object-Oriented Programming J. Kizito Makerere University e-mail: jkizito@cis.mak.ac.ug www: http://serval.ug/~jona materials: http://serval.ug/~jona/materials/csc1214 e-learning environment:

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

JAVA NOTES GRAPHICAL USER INTERFACES

JAVA NOTES GRAPHICAL USER INTERFACES 1 JAVA NOTES GRAPHICAL USER INTERFACES Terry Marris July 2001 8 DROP-DOWN LISTS 8.1 LEARNING OUTCOMES By the end of this lesson the student should be able to understand and use JLists understand and use

More information

Module 5 The Applet Class, Swings. OOC 4 th Sem, B Div Prof. Mouna M. Naravani

Module 5 The Applet Class, Swings. OOC 4 th Sem, B Div Prof. Mouna M. Naravani Module 5 The Applet Class, Swings OOC 4 th Sem, B Div 2016-17 Prof. Mouna M. Naravani The layout manager helps lay out the components held by this container. When you set a layout to null, you tell the

More information

GUI and its COmponent Textfield, Button & Label. By Iqtidar Ali

GUI and its COmponent Textfield, Button & Label. By Iqtidar Ali GUI and its COmponent Textfield, Button & Label By Iqtidar Ali GUI (Graphical User Interface) GUI is a visual interface to a program. GUI are built from GUI components. A GUI component is an object with

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

MIT AITI Swing Event Model Lecture 17

MIT AITI Swing Event Model Lecture 17 MIT AITI 2004 Swing Event Model Lecture 17 The Java Event Model In the last lecture, we learned how to construct a GUI to present information to the user. But how do GUIs interact with users? How do applications

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

Swing from A to Z Some Simple Components. Preface

Swing from A to Z Some Simple Components. Preface By Richard G. Baldwin baldwin.richard@iname.com Java Programming, Lecture Notes # 1005 July 31, 2000 Swing from A to Z Some Simple Components Preface Introduction Sample Program Interesting Code Fragments

More information

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

Control Flow: Overview CSE3461. An Example of Sequential Control. Control Flow: Revisited. Control Flow Paradigms: Reacting to the User CSE3461 Control Flow Paradigms: Reacting to the User Control Flow: Overview Definition of control flow: The sequence of execution of instructions in a program. Control flow is determined at run time by

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

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

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

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

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

CSIS 10A Assignment 7 SOLUTIONS

CSIS 10A Assignment 7 SOLUTIONS CSIS 10A Assignment 7 SOLUTIONS Read: Chapter 7 Choose and complete any 10 points from the problems below, which are all included in the download file on the website. Use BlueJ to complete the assignment,

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

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

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

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

CSEN401 Computer Programming Lab. Topics: Graphical User Interface Window Interfaces using Swing CSEN401 Computer Programming Lab Topics: Graphical User Interface Window Interfaces using Swing Prof. Dr. Slim Abdennadher 22.3.2015 c S. Abdennadher 1 Swing c S. Abdennadher 2 AWT versus Swing Two basic

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

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

More Swing. CS180 Recitation 12/(04,05)/08

More Swing. CS180 Recitation 12/(04,05)/08 More Swing CS180 Recitation 12/(04,05)/08 Announcements No lecture/labs next week Recitations and evening consulting hours will be held as usual. Debbie's study group on tuesday and office hours on thursday

More information

H212 Introduction to Software Systems Honors

H212 Introduction to Software Systems Honors Introduction to Software Systems Honors Lecture #19: November 4, 2015 1/14 Third Exam The third, Checkpoint Exam, will be on: Wednesday, November 11, 2:30 to 3:45 pm You will have 3 questions, out of 9,

More information

Graphical interfaces & event-driven programming

Graphical interfaces & event-driven programming Graphical interfaces & event-driven programming Lecture 12 of TDA 540 (Objektorienterad Programmering) Carlo A. Furia Alex Gerdes Chalmers University of Technology Gothenburg University Fall 2017 Pop quiz!

More information

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

Java Swing. Recitation 11/(20,21)/2008. CS 180 Department of Computer Science, Purdue University Java Swing Recitation 11/(20,21)/2008 CS 180 Department of Computer Science, Purdue University Announcements Project 8 is out Milestone due on Dec 3rd, 10:00 pm Final due on Dec 10th, 10:00 pm No classes,

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

Adding Buttons to StyleOptions.java

Adding Buttons to StyleOptions.java Adding Buttons to StyleOptions.java The files StyleOptions.java and StyleOptionsPanel.java are from Listings 5.14 and 5.15 of the text (with a couple of slight changes an instance variable fontsize is

More information

Calculator Class. /** * Create a new calculator and show it. */ public Calculator() { engine = new CalcEngine(); gui = new UserInterface(engine); }

Calculator Class. /** * Create a new calculator and show it. */ public Calculator() { engine = new CalcEngine(); gui = new UserInterface(engine); } A Calculator Project This will be our first exposure to building a Graphical User Interface (GUI) in Java The functions of the calculator are self-evident The Calculator class creates a UserInterface Class

More information

Chapter #1. Program to demonstrate applet life cycle

Chapter #1. Program to demonstrate applet life cycle Chapter #1. Program to demonstrate applet life cycle import java.applet.applet; import java.awt.*; public class LifeCycle extends Applet{ public void init(){ System.out.println(" init()"); public void

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 13. Applets and HTML. HTML Applets. Chapter 13 Java: an Introduction to Computer Science & Programming - Walter Savitch 1

Chapter 13. Applets and HTML. HTML Applets. Chapter 13 Java: an Introduction to Computer Science & Programming - Walter Savitch 1 Chapter 13 Applets and HTML HTML Applets Chapter 13 Java: an Introduction to Computer Science & Programming - Walter Savitch 1 Overview Applets: Java programs designed to run from a document on the Internet

More information

Chapter 13 Lab Advanced GUI Applications

Chapter 13 Lab Advanced GUI Applications Gaddis_516907_Java 4/10/07 2:10 PM Page 113 Chapter 13 Lab Advanced GUI Applications Objectives Be able to add a menu to the menu bar Be able to use nested menus Be able to add scroll bars, giving 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

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

Java & Graphical User Interface II. Wang Yang wyang AT njnet.edu.cn Java & Graphical User Interface II Wang Yang wyang AT njnet.edu.cn Outline Review of GUI (first part) What is Event Basic Elements of Event Programming Secret Weapon - Inner Class Full version of Event

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

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

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

Programming Languages and Techniques (CIS120)

Programming Languages and Techniques (CIS120) Programming Languages and Techniques (CIS120) Lecture 32 April 9, 2018 Swing I: Drawing and Event Handling Chapter 29 HW8: Spellchecker Available on the web site Due: Tuesday! Announcements Parsing, working

More information

Java: Graphical User Interfaces (GUI)

Java: Graphical User Interfaces (GUI) Chair of Software Engineering Carlo A. Furia, Marco Piccioni, and Bertrand Meyer Java: Graphical User Interfaces (GUI) With material from Christoph Angerer The essence of the Java Graphics API Application

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

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

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

AP CS Unit 11: Graphics and Events

AP CS Unit 11: Graphics and Events AP CS Unit 11: Graphics and Events This packet shows how to create programs with a graphical interface in a way that is consistent with the approach used in the Elevens program. Copy the following two

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

Attempt FOUR questions Marking Scheme Time: 120 mins

Attempt FOUR questions Marking Scheme Time: 120 mins Ahmadu Bello University Department of Computer Science Second Semester Examinations August 2017 COSC212: Object Oriented Programming II Marking Scheme Attempt FOUR questions Marking Scheme Time: 120 mins

More information

MODEL UPDATES MANIPULATES USER

MODEL UPDATES MANIPULATES USER 1) What do you mean by MVC architecture? Explain its role in modern applications and list its advantages(may-2013,jan-2013,nov-2011). In addition to dividing the application into three kinds of components,

More information

encompass a group of features for building Graphical User Interfaces (GUI).

encompass a group of features for building Graphical User Interfaces (GUI). Java GUI (intro) JFC Java Foundation Classes encompass a group of features for building Graphical User Interfaces (GUI). javax.swing.* used for building GUIs. Some basic functionality is already there

More information

JLayeredPane. Depth Constants in JLayeredPane

JLayeredPane. Depth Constants in JLayeredPane JLayeredPane Continuing on Swing Components A layered pane is a Swing container that provides a third dimension for positioning components depth or Z order. The class for the layered pane is JLayeredPane.

More information

OOP Assignment V. For example, the scrolling text (moving banner) problem without a thread looks like:

OOP Assignment V. For example, the scrolling text (moving banner) problem without a thread looks like: OOP Assignment V If we don t use multithreading, or a timer, and update the contents of the applet continuously by calling the repaint() method, the processor has to update frames at a blinding rate. Too

More information

Jonathan Aldrich Charlie Garrod

Jonathan Aldrich Charlie Garrod Principles of Software Construction: Objects, Design, and Concurrency (Part 3: Design Case Studies) Introduction to GUIs Jonathan Aldrich Charlie Garrod School of Computer Science 1 Administrivia Homework

More information

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

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... Table of Contents Chapter 1 Getting Started with Java SE 7 1 Introduction of Java SE 7... 2 Exploring the Features of Java... 3 Exploring Features of Java SE 7... 4 Introducing Java Environment... 5 Explaining

More information

Swing - JTextField. Adding a text field to the main window (with tooltips and all)

Swing - JTextField. Adding a text field to the main window (with tooltips and all) Swing - JTextField Adding a text field to the main window (with tooltips and all) Prerequisites - before this lecture You should have seen: The lecture on JFrame The lecture on JButton Including having

More information

1.1 GUI. JFrame. import java.awt.*; import javax.swing.*; public class XXX extends JFrame { public XXX() { // XXX. init() main() public static

1.1 GUI. JFrame. import java.awt.*; import javax.swing.*; public class XXX extends JFrame { public XXX() { // XXX. init() main() public static 18 7 17 1 1.1 GUI ( ) GUI ( ) JFrame public class XXX extends JFrame { public XXX() { // XXX // init()... // ( )... init() main() public static public class XXX extends JFrame { public XXX() { // setsize(,

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

Swing/GUI Cheat Sheet

Swing/GUI Cheat Sheet General reminders To display a Swing component, you must: Swing/GUI Cheat Sheet Construct and initialize the component. Example: button = new JButton ("ButtonLabel"); Add it to the content pane of the

More information

Chapter 8. Java continued. CS Hugh Anderson s notes. Page number: 264 ALERT. MCQ test next week. This time. This place.

Chapter 8. Java continued. CS Hugh Anderson s notes. Page number: 264 ALERT. MCQ test next week. This time. This place. Chapter 8 Java continued CS3283 - Hugh Anderson s notes. Page number: 263 ALERT MCQ test next week This time This place Closed book CS3283 - Hugh Anderson s notes. Page number: 264 ALERT Assignment #2

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

Java continued. Chapter 8 ALERT ALERT. Last week. MCQ test next week. This time. This place. Closed book. Assignment #2 is for groups of 3

Java continued. Chapter 8 ALERT ALERT. Last week. MCQ test next week. This time. This place. Closed book. Assignment #2 is for groups of 3 Chapter 8 Java continued MCQ test next week This time This place Closed book ALERT CS3283 - Hugh Anderson s notes. Page number: 263 CS3283 - Hugh Anderson s notes. Page number: 264 ALERT Last week Assignment

More information

Graphical User Interface (GUI)

Graphical User Interface (GUI) Graphical User Interface (GUI) An example of Inheritance and Sub-Typing 1 Java GUI Portability Problem Java loves the idea that your code produces the same results on any machine The underlying hardware

More information

COMP Assignment #10 (Due: Monday, March 11:30pm)

COMP Assignment #10 (Due: Monday, March 11:30pm) COMP1406 - Assignment #10 (Due: Monday, March 31st @ 11:30pm) In this assignment you will practice using recursion with data structures. (1) Consider the following BinaryTree class: public class BinaryTree

More information

Building Graphical User Interfaces. GUI Principles

Building Graphical User Interfaces. GUI Principles Building Graphical User Interfaces 4.1 GUI Principles Components: GUI building blocks Buttons, menus, sliders, etc. Layout: arranging components to form a usable GUI Using layout managers. Events: reacting

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

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

G51PGP Programming Paradigms. Lecture 008 Inner classes, anonymous classes, Swing worker thread G51PGP Programming Paradigms Lecture 008 Inner classes, anonymous classes, Swing worker thread 1 Reminder subtype polymorphism public class TestAnimals public static void main(string[] args) Animal[] animals

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

GUI Forms and Events, Part II

GUI Forms and Events, Part II GUI Forms and Events, Part II Quick Start Compile step once always mkdir labs javac PropertyTax6.java cd labs Execute step mkdir 6 java PropertyTax6 cd 6 cp../5/propertytax5.java PropertyTax6.java Submit

More information

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

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

Class 16: The Swing Event Model

Class 16: The Swing Event Model Introduction to Computation and Problem Solving Class 16: The Swing Event Model Prof. Steven R. Lerman and Dr. V. Judson Harward 1 The Java Event Model Up until now, we have focused on GUI's to present

More information

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

Java Graphical User Interfaces AWT (Abstract Window Toolkit) & Swing Java Graphical User Interfaces AWT (Abstract Window Toolkit) & Swing Rui Moreira Some useful links: http://java.sun.com/docs/books/tutorial/uiswing/toc.html http://www.unix.org.ua/orelly/java-ent/jfc/

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

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

Graphics User Defined Forms, Part I

Graphics User Defined Forms, Part I Graphics User Defined Forms, Part I Quick Start Compile step once always mkdir labs javac PropertyTax5.java cd labs mkdir 5 Execute step cd 5 java PropertyTax5 cp /samples/csc/156/labs/5/*. cp PropertyTax1.java

More information

Building Graphical User Interfaces. Overview

Building Graphical User Interfaces. Overview Building Graphical User Interfaces 4.1 Overview Constructing GUIs Interface components GUI layout Event handling 2 1 GUI Principles Components: GUI building blocks. Buttons, menus, sliders, etc. Layout:

More information

CSC 1051 Data Structures and Algorithms I. Dr. Mary-Angela Papalaskari Department of Computing Sciences Villanova University

CSC 1051 Data Structures and Algorithms I. Dr. Mary-Angela Papalaskari Department of Computing Sciences Villanova University Events and Listeners CSC 1051 Data Structures and Algorithms I Dr. Mary-Angela Papalaskari Department of Computing Sciences Villanova University Course website: www.csc.villanova.edu/~map/1051/ Some slides

More information

Layouts and Components Exam

Layouts and Components Exam Layouts and Components Exam Name Period A. Vocabulary: Answer each question specifically, based on what was taught in class. Term Question Answer JScrollBar(a, b, c, d, e) Describe c. ChangeEvent What

More information