1 Java Swing Application Flow By mr. Hanley 11/7/2005.

Slides:



Advertisements
Similar presentations
Exceptions Session 21. Memory Upload Creating Exceptions Using exceptions to control object creation and validation.
Advertisements

Multi-threaded applications SE SE-2811 Dr. Mark L. Hornick 2 What SE1011 students are told… When the main() method is called, the instructions.
CS 2430 Day 22. Announcements Prog4 test document and Rational Junit tests are due this Friday at 2 PM Quiz 3 this Friday Quiz 4 next Friday Exam 2: 4/3/13.
Exceptions Any number of exceptional circumstances may arise during program execution that cause trouble import java.io.*; class IOExample { public static.
 It is possible to declare names for object references and not assign object references to them.  Such names literally refer to nothing at all.  It.
Exceptions Three categories of errors: Syntax errors Runtime errors Logic errors Syntax errors: rules of the language have not been followed. Runtime error:
Java Exceptions. Intro to Exceptions  What are exceptions? –Events that occur during the execution of a program that interrupt the normal flow of control.
1 Event Driven Programming with Graphical User Interfaces (GUIs) A Crash Course © Rick Mercer.
Graphical User Interfaces
Saturday May 02 PST 4 PM. Saturday May 02 PST 10:00 PM.
CSE 115 Week 4 February 4 - 8, Monday Announcements Software installation fest Tuesday & Wednesday 4-7 in Baldy 21. Software installation fest Tuesday.
Java Exceptions. Intro to Exceptions  What are exceptions? –Events that occur during the execution of a program that interrupt the normal flow of control.
1 Class 8. 2 Chapter Objectives Use Swing components to build the GUI for a Swing program Implement an ActionListener to handle events Add interface components.
Developing User Interfaces (DUI) Chris North cs3724: HCI.
16-Aug-15 Java Puzzlers From the book Java Puzzlers by Joshua Bloch and Neal Gafter.
CIS3023: Programming Fundamentals for CIS Majors II Summer 2010 Ganesh Viswanathan Graphical User Interface (GUI) Design using Swing Course Lecture Slides.
Georgia Institute of Technology Speed part 3 Barb Ericson Georgia Institute of Technology May 2006.
Exception Handling. Exceptions and Errors When a problem encounters and unexpected termination or fault, it is called an exception When we try and divide.
Conditional If Week 3. Lecture outcomes Boolean operators – == (equal ) – OR (||) – AND (&&) If statements User input vs command line arguments.
1 Event Driven Programming wirh Graphical User Interfaces (GUIs) A Crash Course © Rick Mercer.
CS 584 Lecture 18 l Assignment » Glenda assignment extended to the Java RMI Deadline » No Java RMI Assignment l Test » Friday, Saturday, Monday.
Learn about the types of Graphics that are available Develop a basic Graphics applet Develop a basic Graphics application Review the Java API and use.
Week 3, Day 1: Processes & Threads Return Quiz Processes Threads Lab: Quiz Lab 3: Strategy & Factory Patterns! SE-2811 Slide design: Dr. Mark L. Hornick.
Lesson 27: Introduction to the Java GUI. // helloworldbutton.java import java.awt.*; import javax.swing.*; class HelloButton{ public static void main.
Lab 6: Shapes & Picture Extended Ellipse & Rectangle Classes Stand-Alone GUI Applications.
Intro to Java Java Applications Swing Class Graphics.
1 Event Driven Programs Rick Mercer. 2 So what happens next?  You can layout a real pretty GUI  You can click on buttons, enter text into a text field,
Object Oriented Programming Lecture 1: Introduction.
Week 3, Day 1: Processes & Threads Processes Threads SE-2811 Slide design: Dr. Mark L. Hornick Content: Dr. Hornick Errors: Dr. Yoder 1.
Exceptions. Exception Abnormal event occurring during program execution Examples –Manipulate nonexistent files FileReader in = new FileReader("mumbers.txt“);
1 Block1 – unit 2 (The Case study in Budd 5-6).  create a small application that uses the Abstract Windowing Toolkit (AWT)  Swing packages to simulate.
Graphic User Interface. Graphic User Interface (GUI) Most of us interact with computers using GUIs. GUIs are visual representations of the actions you.
 2003 Joel C. Adams. All Rights Reserved. Calvin CollegeDept of Computer Science(1/15) MVC and Swing Joel Adams and Jeremy Frens Calvin College.
CSC1401 Classes - 2. Learning Goals Computing concepts Adding a method To show the pictures in the slide show Creating accessors and modifiers That protect.
 GUI – Graphic User Interface  Up to now in the programs we have written all output has been sent to the standard output device i.e.: the DOS console.
Java - Classes JPatterson. What is a class? public class _Alpha { public static void main(String [] args) { } You have been using classes all year – you.
Java GUI. Graphical User Interface (GUI) a list a button a text field a label combo box checkbox.
WEEK 2 Introduction to Java II CSE 252 Principles of Programming Languages LAB SECTION.
Recitation 8 User Defined Classes Part 2. Class vs. Instance methods Compare the Math and String class methods that we have used: – Math.pow(2,3); – str.charAt(4);
Bank Account Example public class BankAccount { private double balance; public static int totalAccounts = 0; public BankAccount() { balance = 0; totalAccounts++;
Objects and Classes Start on Slide 30 for day 2 Java Methods A & AB Object-Oriented Programming and Data Structures Maria Litvin ● Gary Litvin Much of.
Question of the Day completes starts  What word completes the 1 st word & starts the 2 nd one: DON???CAR.
Swing GUI Components So far, we have written GUI applications which can ‘ draw ’. These applications are simple, yet typical of all Java GUI applications.
Threads b A thread is a flow of control in a program. b The Java Virtual Machine allows an application to have multiple threads of execution running concurrently.
import java.util.Scanner; class myCode { public static void main(String[] args) { Scanner input= new Scanner(System.in); int num1; System.out.println(“Enter.
Methods What is a method? Main Method the main method is where a stand alone Java program normally begins execution common compile error, trying.
Georgia Institute of Technology Making Text for the Web part 2 Barb Ericson Georgia Institute of Technology March 2006.
Daily Math Review September 2-6, Monday Solve the following problems with strategies and/or algorithms 5, = 9, = 3, =
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.
5-1 GUIs and Events Rick Mercer. 5-2 Event-Driven Programming with Graphical user Interfaces  Most applications have graphical user interfaces to respond.
© 2004 Pearson Addison-Wesley. All rights reserved September 5, 2007 Packages & Random and Math Classes ComS 207: Programming I (in Java) Iowa State University,
Throw, Throws & Try-Catch Statements Explanations and Pictures from: Reference:
Exceptions and Error Handling. Exceptions Errors that occur during program execution We should try to ‘gracefully’ deal with the error Not like this.
Section 3.3 Exceptional Situations. 3.3 Exceptional Situations Exceptional situation Associated with an unusual, sometimes unpredictable event, detectable.
ENUMERATED TYPES Java Basics. Enumerated Type Topics Why use them? Defining an enumerated type Using an enumerated type Advanced features.
PART OF SPEECH DEFINITION SYNONYM SENTENCE NAME TEACHER AND DATE1 WORDS OF THE WEEK.
PART OF SPEECH DEFINITION SYNONYM SENTENCE NAME TEACHER AND DATE1 WORDS OF THE WEEK.
Import javax.swing.*; class Check { public static void main(String[] args) { JFrame frame = new JFrame("Check"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);//DO_NOTHING_ON_CLOSE.
1 Event Driven Programming with Graphical User Interfaces (GUIs) A Crash Course © Rick Mercer.
Exceptions, Interfaces & Generics
RADE new features via JAVA
Ellen Walker Hiram College
MVC Paradigm The MVC paradigm breaks applications or interfaces into three parts: the model, the view, and the controller. A --> 25 % B --> 60 % C -->
Exception Handling in Java
Assignment 7 User Defined Classes Part 2
class PrintOnetoTen { public static void main(String args[]) {
Java Programming with Multiple Classes
Constructors, GUI’s(Using Swing) and ActionListner
Real World Scenario Sometimes it's appropriate to have exactly one instance of a class: window manager print spooler Filesystems press Ctrl-F to display.
CiS 260: App Dev I Chapter 6: GUI and OOD.
Presentation transcript:

1 Java Swing Application Flow By mr. Hanley 11/7/2005

2 How does a swing app flow? In our Swing Applications, we have used two files, an app file and a frame file Let’s take the SnowFall Assignment as an Example

3 How does a swing app flow? 1. A java application looks for a main method import java.awt.*; import javax.swing.*; public class Proj2App { public static void main(String[] args) { Proj2Frame p = new Proj2Frame(); p.setSize(500,400); p.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); p.setTitle("Project 2 Basic Mathematical Problems"); p.setVisible(true); }

4 How does a swing app flow? 2. When the first line of the main is encountered, a new Proj2Frame object is created Proj2Frame p = new Proj2Frame(); 3. Since we are creating a new object, a constructor is called –A constructor is a method with the same name of the class

5 How does a swing app flow? public Proj2Frame() { try { jbInit(); } catch (Exception ex) { ex.printStackTrace(); } 4. All global variables are created and initialized to either 0 or null 5. The constructor calls a method called jbInit, which stands for jbuilder initialize

6 How does a swing app flow? private void jbInit() throws Exception { this.getContentPane().setLayout(null); tabPane.setBounds(new Rectangle(30, 20, 348, 273)); snowAvgPAN.setLayout(null); sodaCompPAN.setLayout(null); areaCirPAN.setLayout(null); areaLBL.setText("Area"); areaLBL.setBounds(new Rectangle(24, 93, 90, 24)); areaTF.setEnabled(false); areaTF.setEditable(false); areaTF.setText(""); areaTF.setBounds(new Rectangle(23, 121, 90, 25)); cirLBL.setText("Circumference"); cirLBL.setBounds(new Rectangle(25, 164, 90, 24));

7 How does a swing app flow? cirTF.setEditable(false); cirTF.setBounds(new Rectangle(23, 190, 90, 25)); radiusLBL.setText("Radius"); radiusLBL.setBounds(new Rectangle(24, 21, 90, 24)); radiusTF.setBounds(new Rectangle(23, 50, 90, 25)); acBUT.setBounds(new Rectangle(154, 47, 90, 29)); acBUT.setText("Find A+C"); cost2lTF.setEditable(false); cost2lTF.setText(""); cost2lTF.setBounds(new Rectangle(162, 42, 112, 26)); price6packLBL.setText("Price in $ for a 6 pack"); price6packLBL.setBounds(new Rectangle(21, 82, 145, 18)); cost6packTF.setEditable(false); cost6packTF.setBounds(new Rectangle(161, 107, 112, 26)); cost2lLBL.setText("Cost in $/L"); cost2lLBL.setBounds(new Rectangle(161, 16, 145, 18)); price2lTF.setBounds(new Rectangle(23, 43, 112, 26)); cost6packLBL.setText("Cost in $/L"); cost6packLBL.setBounds(new Rectangle(160, 81, 145, 18));

8 How does a swing app flow? price2lLBL.setText("Price in $ for 2 Liter"); price2lLBL.setBounds(new Rectangle(22, 17, 145, 18)); price6packTF.setText(""); price6packTF.setBounds(new Rectangle(22, 108, 112, 26)); twolRB.setText(""); twolRB.setBounds(new Rectangle(295, 40, 107, 27)); sixPackRB.setText("jRadioButton1"); sixPackRB.setBounds(new Rectangle(295, 105, 16, 19)); includeDepCBX.setText(""); includeDepCBX.setBounds(new Rectangle(20, 154, 19, 14)); includeDepLBL.setText("Include Deposit"); includeDepLBL.setBounds(new Rectangle(48, 152, 100, 18)); compareBUT.setBackground(Color.orange); compareBUT.setBounds(new Rectangle(160, 148, 97, 26)); compareBUT.setActionCommand("compBUT"); compareBUT.setText("Compare"); monTF.setText(""); monTF.setBounds(new Rectangle(21, 32, 75, 24)); monLBL.setText("Snow Monday"); monLBL.setBounds(new Rectangle(17, 9, 88, 20));

9 How does a swing app flow? tuesTF.setBounds(new Rectangle(20, 85, 75, 24)); tuesLBL.setText("Snow Tuesday"); tuesLBL.setBounds(new Rectangle(17, 62, 88, 20)); wedTF.setBounds(new Rectangle(20, 143, 75, 24)); wedLBL.setText("Snow Wednesday"); wedLBL.setBounds(new Rectangle(18, 120, 106, 20)); thurTF.setBounds(new Rectangle(18, 197, 75, 24)); thurLBL.setText("Snow Thursday"); thurLBL.setBounds(new Rectangle(20, 174, 110, 20)); friTF.setBounds(new Rectangle(165, 32, 75, 24)); friLBL.setText("Snow Friday"); friLBL.setBounds(new Rectangle(166, 8, 88, 20)); avgBUT.setBounds(new Rectangle(160, 68, 90, 74)); avgBUT.setIcon(flakeIC); avgBUT.setText("Average"); avgTF.setEditable(false); avgTF.setBounds(new Rectangle(164, 195, 75, 24));

10 How does a swing app flow? avgLBL.setText("Average"); avgLBL.setBounds(new Rectangle(166, 172, 88, 20)); this.getContentPane().add(tabPane); snowAvgPAN.add(tuesLBL); snowAvgPAN.add(tuesTF); snowAvgPAN.add(monTF); snowAvgPAN.add(wedLBL); snowAvgPAN.add(wedTF); snowAvgPAN.add(thurLBL); snowAvgPAN.add(thurTF); snowAvgPAN.add(friTF); snowAvgPAN.add(friLBL); snowAvgPAN.add(avgBUT); snowAvgPAN.add(avgTF); snowAvgPAN.add(avgLBL); snowAvgPAN.add(monLBL); tabPane.add(areaCirPAN, "Area/Cir");

11 How does a swing app flow? areaCirPAN.add(areaTF); areaCirPAN.add(radiusTF); areaCirPAN.add(cirLBL); areaCirPAN.add(radiusLBL); areaCirPAN.add(cirTF); areaCirPAN.add(areaLBL); areaCirPAN.add(acBUT); sodaCompPAN.add(price6packLBL); sodaCompPAN.add(price2lTF); sodaCompPAN.add(price2lLBL); sodaCompPAN.add(cost2lLBL); sodaCompPAN.add(cost6packLBL); sodaCompPAN.add(cost6packTF); sodaCompPAN.add(cost2lTF); sodaCompPAN.add(price6packTF);

12 How does a swing app flow? sodaCompPAN.add(twolRB); sodaCompPAN.add(sixPackRB); sodaCompPAN.add(includeDepCBX); sodaCompPAN.add(includeDepLBL); sodaCompPAN.add(compareBUT); tabPane.add(sodaCompPAN, "Compare Sodas"); tabPane.add(snowAvgPAN, "Snow Fall"); acBUT.addActionListener(this); compareBUT.addActionListener(this); avgBUT.addActionListener(this); }

13 How does a swing app flow? 6, Now that the initialize method is done, the app sends various messages to the frame –P.setsize –P.setTitle –P.setVisible –P.setDefaultCloseOp

14 How does a swing app flow? 7. The application waits for user initiated events 8. These trigger the actionPerformed method 9. The app file is essentially done at this point in time