Assignment #3 (Due 4/4/2017)

Similar documents
Adding Buttons to StyleOptions.java

import javax.swing.jframe; import javax.swing.joptionpane;

Name: Checked: Learn about listeners, events, and simple animation for interactive graphical user interfaces.

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

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

CSIS 10A Assignment 7 SOLUTIONS

MIT AITI Swing Event Model Lecture 17

Chapter 4 Writing Classes

Array indexing. Before we use an array, we have to declare it. For example, int[] height=new int[11];

Selection and Repetition Revisited

AP CS Unit 11: Graphics and Events

1005ICT Object Oriented Programming Lecture Notes

Chapter. We've been using predefined classes. Now we will learn to write our own classes to define objects

Chapter 11: Exceptions Lab Exercises

SINGLE EVENT HANDLING

PROGRAMMING DESIGN USING JAVA (ITT 303) Unit 7

Java Programming Lecture 6

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

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

Homework 6 part 2: Turtle Etch-A-Sketch (40pts)

University of Cape Town Department of Computer Science. Computer Science CSC117F Solutions

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

Swing/GUI Cheat Sheet

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

Building Graphical User Interfaces. GUI Principles

Building Java Programs Bonus Slides

Building Graphical User Interfaces. Overview

Part I: Learn Common Graphics Components

Object-Oriented Programming in Java

Graphic User Interfaces. - GUI concepts - Swing - AWT

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

Graphical User Interfaces. Comp 152

Graphical Applications

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

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

Designing Classes. Where do objects come from? Where do objects come from? Example: Account datatype. Dr. Papalaskari 1

More about JOptionPane Dialog Boxes

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

Graphical User Interfaces

Chapter 12 GUI Basics

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

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

Selection and Repetition

Attempt FOUR questions Marking Scheme Time: 120 mins

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

State Application Using MVC

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

Copyright 1999 by Deitel & Associates, Inc. All Rights Reserved.

CS 209 Programming in Java #10 Exception Handling

STRUKTUR PROGRAM JAVA: //Daftar paket yang digunakan dalam program import namapaket;

Overview. Building Graphical User Interfaces. GUI Principles. AWT and Swing. Constructing GUIs Interface components GUI layout Event handling

JLayeredPane. Depth Constants in JLayeredPane

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

Designing Classes Part 2

CS180 Spring 2010 Exam 2 Solutions, 29 March, 2010 Prof. Chris Clifton

User interfaces and Swing

H212 Introduction to Software Systems Honors

Project 1. LibraryTest.java. Yuji Shimojo CMSC 335

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

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

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

GUI Basics. Object Orientated Programming in Java. Benjamin Kenwright

Systems Programming Graphical User Interfaces

Graphics. Lecture 18 COP 3252 Summer June 6, 2017

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

We are on the GUI fast track path

Arrays, Exception Handling, Interfaces, Introduction To Swing

Layouts and Components Exam

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

Control Statements: Part Pearson Education, Inc. All rights reserved.

Example: not good design. Motivation for MVC. public class BankAccount extends JPanel implements ActionListener

Introduction. Introduction

Programming graphics

An array is a type of variable that is able to hold more than one piece of information under a single variable name.

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

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

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

Programming Languages 2nd edition Tucker and Noonan"

Chapter 13 Lab Advanced GUI Applications

Packages: Putting Classes Together

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

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

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

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

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

Swing Programming Example Number 2

DM503 Programming B. Peter Schneider-Kamp.

Dr. Hikmat A. M. AbdelJaber

Introduction to the JAVA UI classes Advanced HCI IAT351

Class 16: The Swing Event Model

Graphical User Interface (GUI)

Java Interfaces Part 1 - Events Version 1.1

Example 3-1. Password Validation

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

JOptionPane Dialogs. javax.swing.joptionpane is a class for creating dialog boxes. Has both static methods and instance methods for dialogs.

Programming Languages and Techniques (CIS120)

Programming Language Concepts: Lecture 8

Systems Programming. Bachelor in Telecommunication Technology Engineering Bachelor in Communication System Engineering Carlos III University of Madrid

Course PJL. Arithmetic Operations

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

Transcription:

Assignment #3 (Due 4/4/2017) As a follow up to Assignment #2, modify the CheckingAccount class to add the following instance members: an array (self-expanding type) or ArrayList of Transaction objects and a int variable transcount (incremented each time a new Transaction object is created). Create a Transaction class that stores an int transnumber (will be the current value of transcount), an int transid (1 = check, 2 = deposit 3 = service charge) and a double transamt. Prompt the user for the choice of a) entering a transaction, b) listing all transations, c) listing all checks, d) listing all deposits.(implement these options with JFrame,JLabel, JRadioButton, ButtonGroup, and a listener) The listings must go to a Dialog box. Add instance methods to the CheckingAccount class like addtrans (put a trans into the account), gettrans (get a transaction from the array) gettranscount(get the current value of transcount class variable) and any other methods you wish to implement. This program is event-driven. You cannot put all the processing steps/logic in main. You can put them in helper methods in the Main class, in the GUI objects class, or in the CheckingAccount class, so they can be called by the listener method. Suggested Reading in Textbook: Chapter 4.7 4.9, 5.6 5.8, 7.1 7.11, 8.1 8.6, 8.8 8.9 Sample Run Download Assignment3SampleRun.pdf from the class website. Code Template The following code template will help with this assignment: New data and methods for the CheckingAccount Class --------------------------------------------------------------------------- private ArrayList<Transaction> translist; // keeps a list of Transaction objects for the account private int transcount; // the count of Transaction objects and used as the ID for each transaction public void addtrans( Transaction newtrans) // adds a transaction object to the translist public int gettranscount() //returns the current value of transcount; public Transaction gettrans(int i) // returns the i-th Transaction object in the list 1

New Transaction class -------------------------------------------------------------------------- public class Transaction private int transnumber; private int transid; private double transamt; public Transaction(int number, int id, double amount) transnumber = number; transid = id; transamt = amount; public int gettransnumber() return transnumber; public int gettransid() return transid; public double gettransamount() return transamt; Sample Code //******************************************************************** // EOptionsPanel.java Author: // Demonstrates the use of radio buttons to capture input options. // and listener to call methods to process the options //******************************************************************** import javax.swing.*; 2

import java.awt.*; import java.awt.event.*; public class EOptionsPanel extends JPanel private JLabel prompt; private JRadioButton one, two, three; //----------------------------------------------------------------- // Sets up a panel with a label and a set of radio buttons // that present options to the user. //----------------------------------------------------------------- public EOptionsPanel() prompt = new JLabel ("Choose your input option?"); prompt.setfont (new Font ("Helvetica", Font.BOLD, 24)); one = new JRadioButton ("input element"); one.setbackground (Color.green); two = new JRadioButton ("list all elements"); two.setbackground (Color.green); three = new JRadioButton ("show element count"); three.setbackground (Color.green); ButtonGroup group = new ButtonGroup(); group.add (one); group.add (two); group.add (three); EOptionListener listener = new EOptionListener(); one.addactionlistener (listener); two.addactionlistener (listener); three.addactionlistener (listener); // add the components to the JPanel add (prompt); add (one); add (two); add (three); 3

setbackground (Color.green); setpreferredsize (new Dimension(400, 100)); //***************************************************************** // Represents the listener for the radio buttons //***************************************************************** private class EOptionListener implements ActionListener //-------------------------------------------------------------- // Calls the method to process the option for which radio // button was pressed. //-------------------------------------------------------------- public void actionperformed (ActionEvent event) Object source = event.getsource(); if (source == one) MyElements2.inputElements(); else if (source == two) MyElements2.listElements(); else String message; message = "The number of elements processed was "+ ChemicalElement.getNumOfElements(); JOptionPane.showMessageDialog (null, message); // MyElements2 Author: // Demonstrates the use of radio buttons with listener // and multiple dialog boxes for user interaction. // Demonstrates the use of the JOptionPane class. 4

import javax.swing.joptionpane; import javax.swing.jframe; public class MyElements2 public static JFrame frame; public static ChemicalElement[] elist; public static void main (String[] args) elist = new ChemicalElement[10]; String message; frame = new JFrame ("Chemical Elements Options"); frame.setdefaultcloseoperation (JFrame.EXIT_ON_CLOSE); EOptionsPanel panel = new EOptionsPanel(); frame.getcontentpane().add (panel); frame.pack(); frame.setvisible(true); public static void listelements() String message, ntabs; int num; System.out.println("\nNumber"+"\t"+"Name"+"\t\t"+"Symbol"+"\t" +"AtomicNumber"+"\n"); for ( num=0; num < ChemicalElement.getNumOfElements();num++) if (elist[num].getname().length() < 8) ntabs="\t\t"; else ntabs="\t"; message = num + "\t"+elist[num].getname()+ntabs+elist[num].getsymbol()+ "\t"+elist[num].getnumber(); System.out.println(message); 5

public static void inputelements() String name, symbol, numstr, message; int number, again, index; frame.setvisible(false); do name = JOptionPane.showInputDialog ("Enter the Element name: "); symbol = JOptionPane.showInputDialog ("Enter the Element symbol: "); numstr = JOptionPane.showInputDialog ("Enter the Element number: "); number = Integer.parseInt(numStr); index = ChemicalElement.getNumOfElements(); elist[index] = new ChemicalElement(name,symbol,number); message = elist[index].tostring(); JOptionPane.showMessageDialog (null, message); again = JOptionPane.showConfirmDialog (null, "Input Another?"); while (again == JOptionPane.YES_OPTION); frame.setvisible(true); // Method added to ChemicalElement class public String tostring() String message; message = "The element name is "+nameofelement+"\n" + "Its atomic symbol is "+chemicalsymbol+"\n" + "Its atomic number is "+atomicnumber; return message; 6