Java Programming Summer 2008 LAB. Thursday 8/21/2008

Similar documents
* To change this license header, choose License Headers in Project Properties.

* To change this license header, choose License Headers in Project Properties.

JAVA CODE JAVA CODE: BINOMIAL TREES OPTION PRICING BINOMIALTREE CLASS PAGE 1

Answer on question #61311, Programming & Computer Science / Java

/** Creates new form NewJFrame */ public NewJFrame() { initcomponents(); initblogsearch(); //initializes Index List box }

jlabel14 = new javax.swing.jlabel(); jlabel15 = new javax.swing.jlabel(); jlabel16 = new javax.swing.jlabel(); jlabel17 = new javax.swing.

Appendix I: Software Coding

I.1 Introduction Matisse GUI designer I.2 GroupLayout Basics Sequential and Parallel Arrangements sequential horizontal orientation

CHAPTER 8 INFERENCE. The concept of Inference would be explained in the following chapter, as the CTBN

Travel Agency. Khateeb Engineering Classes. Mini Project. Khateeb Engineering Classes: / Technology to be used

Role-Coll Role Based Collaboration Software

Hanley s Survival Guide for Visual Applications with NetBeans 2.0 Last Updated: 5/20/2015 TABLE OF CONTENTS

INSTITUTO POLITÉCNICO NACIONAL ESCUELA SUPERIOR DE CÓMPUTO

/* * MoraDrill.java * Version last updated 6 April 2010 * Written by John K. Estell * Created on November 30, 2008, 10:22 PM */

DAFTAR LAMPIRAN. Source Code Java Aplikasi Keyword to Image Renamer Split

privateint m, n, smithitemcount, raitaitemcount;

グラフを表すデータ構造 JAVA での実装

TECHNICAL DOCUMENTATION

Project Helpine Report BANQUET HALL BOOKING

AP CS Unit 11: Graphics and Events

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

COMP16121 Sample Code Lecture 1

SampleApp.java. Page 1

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

// autor igre Ivan Programerska sekcija package mine;

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

We have several alternatives now, which we need to address. Here is a list of them: 1. How to get HTML interpreted correctly.

Java, Swing, and Eclipse: The Calculator Lab.

APPENDIX. public void cekroot() { System.out.println("nilai root : "+root.data); }

The class definition is not a program by itself. It can be used by other programs in order to create objects and use them.

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

CSIS 10A Assignment 7 SOLUTIONS

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

Lampiran A. SOURCE CODE PROGRAM

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

Graphical User Interface

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

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

Multiple Choice Questions: Identify the choice that best completes the statement or answers the question. (15 marks)

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

Part I: Learn Common Graphics Components

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

JFrame & JLabel. By Iqtidar Ali

FirstSwingFrame.java Page 1 of 1

Points Missed on Page page 1 of 8

LAMPIRAN PERANGKAT LUNAK

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

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

SWING - GROUPLAYOUT CLASS

Java Swing Introduction

AnimatedImage.java. Page 1

AP CS Unit 12: Drawing and Mouse Events

CSCI 201L Midterm Written Summer % of course grade

GUI (Graphic User Interface) Programming. Part 2 (Chapter 8) Chapter Goals. Events, Event Sources, and Event Listeners. Listeners

Swing - JLabel. Adding a text (and HTML) labels to a GUI

This is the java code for generating coördinates of molecules numerically using the CDNT framework with real-time input and diagramatic output.

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.

To gain experience using GUI components and listeners.

Advanced Java Unit 6: Review of Graphics and Events

3/18/2015. Chapter 19 Sorting and Searching SELECTION SORT SORTING AN ARRAY OF INTEGERS SORTING AN ARRAY OF INTEGERS FILE SELECTIONSORTER.

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

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

H212 Introduction to Software Systems Honors

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

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

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

First Name: AITI 2004: Exam 2 July 19, 2004

PlaniSphere. Creating a plug-in for PlaniSphere.

AppBisect > PrBisect > class Functie. AppBisect > PrBisect > class Punct. public class Functie { double x(double t) { return t;

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

Constructing an Index Fund Using Interior Point Primal Dual Method

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

Object-Oriented Software Engineering Re-exam, 2012 (Also Object-Oriented Analysis, Design and Programming, Re-exam, 2012)

COSC 123 Computer Creativity. Graphics and Events. Dr. Ramon Lawrence University of British Columbia Okanagan

GUI Applications. Let s start with a simple Swing application in Java, and then we will look at the same application in Jython. See Listing 16-1.

Final Examination Semester 2 / Year 2010

Graphical User Interfaces (GUIs)

More about GUIs GEEN163

Exercice G02 (v2) File: MovingBall.java Project: G02-Smileys_v2 1GGE

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

!"# $ %&# %####' #&() % # # # #&* # ## +, # -

MIT AITI Swing Event Model Lecture 17

Programming Languages and Techniques (CIS120)

Advanced Programming - CS239

This document shows the whole program for the implementation of the Withdraw operation specication.

First Name: AITI 2004: Exam 2 July 19, 2004

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

CSCI 201L Midterm Written SOLUTION Summer % of course grade

Dr. Hikmat A. M. AbdelJaber

CSCI 136 Written Exam #2 Fundamentals of Computer Science II Spring 2015

Class 14: Introduction to the Swing Toolkit

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

package As7BattleShip;

Example: Building a Java GUI

University of Cape Town Department of Computer Science Computer Science CSC1017F

Example: Building a Java GUI

Swing - JButton. Adding buttons to the main window

HomeWork 3. In this homework, an ArchJava application that allows one to query one s scores in a networked environment is presented.

DESIGN AND IMPLEMENTATION OF A PUZZLE GAME USING JAVA SE 1. University Politehnica Timisoara, Faculty Engineering Hunedoara, ROMANIA

Transcription:

LAB Thursday 8/21/2008 Design and implement the program that contains a timer. When the program starts, the timer shows 00:00:00. When we click the Start button, the timer starts. When we click the Stop button, the timer pauses, showing the elapsed time. When we click the Start button again, the timer resumes. Clicking the Reset button resets the elapsed time to 00:00:00. Use NetBeans for design and implementation of this program. / To change this template, choose Tools Templates and open the template in the editor. package my.timer; / @author Taehyung public class Controller { private TimerUI ui; private Timer timer; public static enum State {RUN, STARTUP, MANUAL, RESET, OFF; private State state; public Controller (TimerUI ui, Timer timer) { this.ui = ui; 1

this.timer = timer; timer.setcontroller (this); ui.setcontroller(this); setstateoff(); public void setstateon() { state = State.RUN; timer.start(); public void setstateoff() { state = State.OFF; timer.stop(); public void startupstate() { timer.start(); public void reset() { ui.setruntime(0); timer.reset(); public void updateclock (int seconds) { ui.setruntime(seconds); / To change this template, choose Tools Templates and open the template in the editor. package my.timer; / @author Taehyung public class Timer implements Runnable{ private int secondselapsed = 0; 2

private static final int clockupdateinterval = 1000; private boolean isrunning; private Controller controller; public void setcontroller (Controller controller) { this.controller = controller; public void run() { while (isrunning) { // update the timer and // sleep. ++secondselapsed; public void start() { isrunning = true; // create a clocktread and start it. public void stop() { isrunning = false; public void reset(){ //reset timer. isrunning = false; / TimerUI.java Created on August 16, 2008, 1:06 PM package my.timer; 3

import java.text.decimalformat; import java.awt.; import javax.swing.; / @author Taehyung public class TimerUI extends javax.swing.jframe { private Controller controller; / Creates new form TimerUI public TimerUI() { super("timer"); initcomponents(); / This method is called from within the constructor to initialize the form. WARNING: Do NOT modify this code. The content of this method is always regenerated by the Form Editor. // <editor fold defaultstate="collapsed" desc="generated Code"> private void initcomponents() { jpanel1 = new javax.swing.jpanel(); jlabel1 = new javax.swing.jlabel(); jbutton1 = new javax.swing.jbutton(); jbutton2 = new javax.swing.jbutton(); jbutton3 = new javax.swing.jbutton(); setdefaultcloseoperation(javax.swing.windowconstants.exit_on_close); jpanel1.setborder(javax.swing.borderfactory.createetchedborder()); jlabel1.setbackground(new java.awt.color(255, 255, 255)); jlabel1.setfont(new java.awt.font("dialog", 1, 36)); jlabel1.sethorizontalalignment(javax.swing.swingconstants.center); jlabel1.settext("00:00:00"); jlabel1.setopaque(true); jbutton1.setfont(new java.awt.font("dialog", 1, 24)); jbutton1.settext("start"); 4

jbutton1.addactionlistener(new java.awt.event.actionlistener() { public void actionperformed(java.awt.event.actionevent evt) { jbutton1actionperformed(evt); ); jbutton2.setfont(new java.awt.font("dialog", 1, 24)); jbutton2.settext("stop"); jbutton2.addactionlistener(new java.awt.event.actionlistener() { public void actionperformed(java.awt.event.actionevent evt) { jbutton2actionperformed(evt); ); jbutton3.setfont(new java.awt.font("dialog", 1, 24)); jbutton3.settext("reset"); jbutton3.addactionlistener(new java.awt.event.actionlistener() { public void actionperformed(java.awt.event.actionevent evt) { jbutton3actionperformed(evt); ); javax.swing.grouplayout jpanel1layout = new javax.swing.grouplayout(jpanel1); jpanel1.setlayout(jpanel1layout); jpanel1layout.sethorizontalgroup( jpanel1layout.createparallelgroup(javax.swing.grouplayout.alignment.leadin G).addGroup(jPanel1Layout.createSequentialGroup().addGap(37, 37, 37).addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignme nt.trailing).addgroup(jpanel1layout.createsequentialgroup().addcomponent(jbutton3).addpreferredgap(javax.swing.layoutstyle.componentplacement.unrelated).addcomponent(jbutton2).addgap(18, 18, 18).addComponent(jButton1)).addComponent(jLabel1, javax.swing.grouplayout.preferred_size, 312, javax.swing.grouplayout.preferred_size)).addcontainergap(37, Short.MAX_VALUE)) 5

); jpanel1layout.setverticalgroup( jpanel1layout.createparallelgroup(javax.swing.grouplayout.alignment.leadin G).addGroup(jPanel1Layout.createSequentialGroup().addContainerGap().addComponent(jLabel1, javax.swing.grouplayout.preferred_size, 75, javax.swing.grouplayout.preferred_size).addpreferredgap(javax.swing.layoutstyle.componentplacement.related, 53, Short.MAX_VALUE).addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignme nt.baseline).addcomponent(jbutton1).addcomponent(jbutton2).addcomponent(jbutton3)).addgap(34, 34, 34)) ); javax.swing.grouplayout layout = new javax.swing.grouplayout(getcontentpane()); getcontentpane().setlayout(layout); layout.sethorizontalgroup( layout.createparallelgroup(javax.swing.grouplayout.alignment.leading).addgroup(layout.createsequentialgroup().addgap(50, 50, 50).addComponent(jPanel1, javax.swing.grouplayout.preferred_size, javax.swing.grouplayout.default_size, javax.swing.grouplayout.preferred_size).addcontainergap(48, Short.MAX_VALUE)) ); layout.setverticalgroup( layout.createparallelgroup(javax.swing.grouplayout.alignment.leading).addgroup(layout.createsequentialgroup().addgap(33, 33, 33).addComponent(jPanel1, javax.swing.grouplayout.preferred_size, javax.swing.grouplayout.default_size, javax.swing.grouplayout.preferred_size).addcontainergap(31, Short.MAX_VALUE)) ); 6

pack(); // </editor fold> public void setruntime (int runtime){ DecimalFormat formatter = new DecimalFormat ("00"); jlabel1.settext(formatter.format(runtime / 3600) + ":" + formatter.format(runtime / 60) + ":" + formatter.format(runtime % 60)); private void jbutton1actionperformed(java.awt.event.actionevent evt) { controller.setstateon(); private void jbutton3actionperformed(java.awt.event.actionevent evt) { controller.reset(); private void jbutton2actionperformed(java.awt.event.actionevent evt) { controller.setstateoff(); public void setcontroller (Controller controller) { this.controller = controller; / @param args the command line arguments public static void main(string args[]) { java.awt.eventqueue.invokelater(new Runnable() { public void run() { new TimerUI().setVisible(true); ); // Variables declaration do not modify private javax.swing.jbutton jbutton1; private javax.swing.jbutton jbutton2; private javax.swing.jbutton jbutton3; private javax.swing.jlabel jlabel1; 7

private javax.swing.jpanel jpanel1; // End of variables declaration / To change this template, choose Tools Templates and open the template in the editor. package my.timer; / @author Taehyung public class Runner { public static void main (String[] args) { Timer timer = new Timer(); TimerUI ui = new TimerUI(); Controller controller = new Controller(ui, timer); ui.setvisible(true); 8