Layouts and Components Exam

Similar documents
Programming graphics

DM550 / DM857 Introduction to Programming. Peter Schneider-Kamp

Chapter 13 Lab Advanced GUI Applications

Chapter 12 Advanced GUIs and Graphics

Graphic User Interfaces. - GUI concepts - Swing - AWT

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

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

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

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

CSIS 10A Assignment 7 SOLUTIONS

Attempt FOUR questions Marking Scheme Time: 120 mins

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

Java. GUI building with the AWT

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

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

Window Interfaces Using Swing Objects

Introduction. Introduction

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

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

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

DM503 Programming B. Peter Schneider-Kamp.

2110: GUIS: Graphical User Interfaces

Theory Test 3A. University of Cape Town ~ Department of Computer Science. Computer Science 1016S ~ For Official Use

User interfaces and Swing

Top-Level Containers

Window Interfaces Using Swing Objects

CHAPTER 2. Java Overview

INTRODUCTION TO (GUIS)

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

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

AP CS Unit 11: Graphics and Events

Graphical User Interface (GUI) and Object- Oriented Design (OOD)

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

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

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

CSCI 201L Written Exam #1 Fall % of course grade

JLayeredPane. Depth Constants in JLayeredPane

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

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

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

RAIK 183H Examination 2 Solution. November 10, 2014

Introduction to the JAVA UI classes Advanced HCI IAT351

import javax.swing.*; import java.awt.*; import java.awt.event.*;

DM503 Programming B. Peter Schneider-Kamp.

FirstSwingFrame.java Page 1 of 1

Java Programming Lecture 6

Dr. Hikmat A. M. AbdelJaber

Name Section. CS 21a Introduction to Computing I 1 st Semester Final Exam

This exam is closed textbook(s) and closed notes. Use of any electronic device (e.g., for computing and/or communicating) is NOT permitted.

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

CSCI 201L Written Exam #1 - SOLUTION Fall % of course grade

Queens College, CUNY Department of Computer Science. CS 212 Object-Oriented Programming in Java Practice Exam 2. CS 212 Exam 2 Study Guide

Part I: Learn Common Graphics Components

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

Systems Programming Graphical User Interfaces

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

Graphics. Lecture 18 COP 3252 Summer June 6, 2017

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

Chapter 7: A First Look at GUI Applications

Swing Programming Example Number 2

G51PRG: Introduction to Programming Second semester Applets and graphics

Graphical User Interfaces. Comp 152

Proctors are unable to respond to queries about the interpretation of exam questions. Do your best to answer exam questions as written.

RAIK 183H Examination 2 Solution. November 11, 2013

Queen s University Faculty of Arts and Science School of Computing CISC 124 Final Examination December 2004 Instructor: M. Lamb

Question 1. Show the steps that are involved in sorting the string SORTME using the quicksort algorithm given below.

Graphical User Interface (Part-3) Supplementary Material for CPSC 233

Today. cisc3120-fall2012-parsons-lectiii.3 2

CPS122 Lecture: Graphical User Interfaces and Event-Driven Programming

ANSWER KEY Exam 2 Computer Programming 230 Dr. St. John Lehman College City University of New York Thursday, 5 November 2009

CPS122 Lecture: Graphical User Interfaces and Event-Driven Programming

Dr. Hikmat A. M. AbdelJaber

JComponent. JPanel. JFrame. JFrame JDialog, JOptionPane. JPanel. JPanel

Chapter 12 GUI Basics

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

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

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

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

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

Day before tests of Java Final test. IDM institution of Bandarawela. Project for department of education

Final Examination Semester 2 / Year 2011

CSCI 201L Midterm Written Summer % of course grade

Using Several Components

The Islamic University Gaza Department of Electrical & Computer Engineering. Midterm Exam Spring 2012 Computer Programming II (Java) ECOM 2324

Adding Buttons to StyleOptions.java

MODEL UPDATES MANIPULATES USER

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

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

Proctors are unable to respond to queries about the interpretation of exam questions. Do your best to answer exam questions as written.

Proctors are unable to respond to queries about the interpretation of exam questions. Do your best to answer exam questions as written.

Final Examination Semester 2 / Year 2010

H212 Introduction to Software Systems Honors

Chapter 6: Graphical User Interfaces

Building Graphical User Interfaces. GUI Principles

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

Exam: Applet, Graphics, Events: Mouse, Key, and Focus

Proctors are unable to respond to queries about the interpretation of exam questions. Do your best to answer exam questions as written.

JAVA NOTES GRAPHICAL USER INTERFACES

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

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

Transcription:

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 component creates this event? JTextField (x, y) Describe x. one.add(two) two.add(three) Component that does not use a listener. a) If one, two, and three are components associated with menus (JMenu, JMenuBar, or JMenuItem), then which is a JMenu? b) Write code to place the JMenuBar on the panel, assuming this code is in the constructor of the panel and JMenuBar is either one, two, or three. a) Write the component class name. b) Write one property that makes this a component. a) b) a) b) john.show(fred, sally) a) What layout is this associated with? b) Describe what john is. a) b) c) Describe what sally is. c)

B. Draw what the code produces assume the libraries have been added and it runs. Please label colors. public class LayoutEx3 extends JFrame LayoutEx3() - a frame that is 600 by 600 pixels, PanelA added to the frame & visible public static void main(string[] args) LayoutEx3 le3 = new LayoutEx3(); class PanelA extends JPanel public PanelA() setlayout(new BorderLayout(5,5)); PanelB x = new PanelB(); PanelC y = new PanelC(); JPanel z = new JPanel(); //default size of a generic panel is about 10 x 10 pixels PanelC a = new PanelC(); add(x, BorderLayout.SOUTH); add(y, BorderLayout.NORTH); add(z, BorderLayout.WEST); add(a, BorderLayout.CENTER); setbackground(color.black); super.paintcomponent(g); class PanelB extends JPanel public PanelB() setlayout( new GridLayout(1,2,5,5)); add(new JButton("items")); add(new JTextArea("information", 25, 5)); setbackground(color.blue); super.paintcomponent(g); class PanelC extends JPanel public PanelC() add (new JCheckBox("select")); add (new JScrollBar(JScrollBar.VERTICAL, 50, 10, 0, 100)); add (new JRadioButton("choose")); setbackground(color.red); super.paintcomponent(g); Draw output in a 600 x 600 window. Label colors.

Draw output in a 600 x 600 window. Label colors.

C. TimeChanger Applet. Complete the code shown to create a JApplet that runs several panels as shown to the right: When TimeChanger runs the user: enters the time on his watch (his former destination time) into a text field selects a country menu item from a menu, then sees: local currency and language in a text area uses a group of radio buttons with time zone options to select the appropriate time zone (Pacific, Central, or Eastern). (Ignore exceptions: Go ahead and ignore the fact that Mexico does not have a land mass in the Eastern time region, and time zones can be further subdivided (for instance, Mountain and Atlantic zones.) the local time is calculated based on the menu item and radio button, then drawn into a big digital clock (huge font String like 12:00 written into a big rectangle) (Ignore Exception: You need not add code to use %12 so hours cannot exceed 12 or 24.) Assume the user s prior location is California. Time is calculated based on the hour portion entered in the text field; minutes stay the same. The time will always be entered in the format xx:yy with xx being the hour and yy being the minutes. Integer.parseInt(enteredText.substring(0,enteredText.indexOf( : )) returns the hour entered as an int, so a number can be added to it. Values to add are shown below. You do not need to use arrays. Country Region Hours to Add USA or Canada or Mexico Pacific 0 USA or Canada or Mexico Central 2 USA or Canada or Mexico Eastern 3 Country Currency Language USA US Dollars English Canada Canadian Dollars English or French Mexico Pesos Spanish Much code is provided for you, and you can assume the HTML file is completely written. Please add code to complete it; pseudocode helps direct your attention towards what is missing. import javax.swing.*; //This is the Applet file it is complete public class TimeChanger extends JApplet public void init() TimeChangerPanel tcp = new TimeChangerPanel(); setcontentpane(tcp);

//These are the panels - complete as indicated with pseudocode import javax.swing.*; import java.awt.*; import java.awt.event.*; public class TimeChangerPanel extends JPanel private TimePanel1 tp1; private TimePanel2 tp2; private ClockDisplay clock; public TimeChangerPanel() //instantiate TimePanel1 and TimePanel2 and add them using the required layout class TimePanel1 extends JPanel implements //fill in blank above private JTextField timeenter; private JMenuBar mb; private JMenu country; private JMenuItem us; private JMenuItem canada; private JMenuItem mexico; private ButtonGroup bg; private JRadioButton pacific; private JRadioButton central; private JRadioButton eastern; private String newtime; private String info; public TimePanel1() newtime = "00:00"; info= "Currency:, Language: "; timeenter = new JTextField("enter watch time", 20); mb = new JMenuBar(); country = new JMenu( ); //fill me in! us = new JMenuItem("USA"); canada = new JMenuItem("Canada"); mexico = new JMenuItem("Mexico"); bg = new ButtonGroup(); pacific = new JRadioButton ("Pacific"); central = new JRadioButton ("Central"); eastern = new JRadioButton ("Eastern");

//Use the space below to do three things: (1) add components to this panel in the //appropriate layout, (2) add listeners as appropriate, and (3) make it so only //one radio button can be used in the group //for the event handler method below, just fill in the lines. For Q1, just fill //in the first blank labeled Q1. For Q2, just fill in the first blank labeled Q2 //(both Q1s are similar, and all Q2s are identical). public void ( ) String timeentered = ; //line above: acquire the String from the text field int hour = 0; if(timeentered.indexof(":")!= -1) // next line is long and I wanted it on one line so it extends out hour = Integer.parseInt(timeEntered.substring(0,timeEntered.indexOf(":"))); int timetoadd = 0; if(q1 ()) //if central button picked timetoadd = 2; else if ( Q1 ()) //if eastern button picked timetoadd = 3; hour= hour + timetoadd; newtime = hour + timeentered.substring(timeentered.indexof(":")); clock.repaint(); if(q2 == us) //if us menu item was used info= "Currency: US Dollars, Language: English"; else if ( Q2 == canada) //if canada was used info = "Currency: Canadian Dollars, Language: English or French";

else if( Q2 == mexico)//if mexico was used info = "Currency: Pesos, Language: Spanish"; tp2.. ( ); //put info into the text area class TimePanel2 extends JPanel private JTextArea infoarea; //nested (1 deep) public TimePanel2() infoarea = new JTextArea(" ", 2, 20); infoarea.setlinewrap(true); //instantiate ClockDisplay then add it and a text area using the appropriate //layout class ClockDisplay extends JPanel //nested (1 deep) g.fillrect(20, 20, 150, 50); g.setcolor(color.white); Font hugefont = new Font("SansSerif", Font.BOLD, 40); g.setfont(hugefont); g.drawstring(tp1., 30, 60); //print calculated time