Getting Started with Java Development and Testing: Netbeans IDE, Ant & JUnit
|
|
- Kristin Benson
- 5 years ago
- Views:
Transcription
1 Getting Started with Java Development and Testing: Netbeans IDE, Ant & JUnit 1. Introduction These tools are all available free over the internet as is Java itself. A brief description of each follows. They are demonstrated in this example. Java 1.4.x Netbeans Ant latest version of Java. Online documentation and tutorials are also available an integrated development environment. Includes Ant. tool/classes for automated building and other tasks of software development. JUnit tool/classes for unit testing and reporting of code during development To illustrate the usage of these tools as we might want to use them in extreme Programming (tests are written first) we will introduce a simple example application. 2. Example Application The application supports the following stories. a. There shall be 4 states. Start, Finish and 2 intermediate states. b. The user may navigate between states by using 2 buttons, Next and Back. c. The interface will visually provide feedback about the current system state. A sketch of what the application s Graphical User Interface (GUI) might look like follows: Figure 1: Sketch of application s proposed user interface (GUI). > Start State 1 State 2 Finish Back Next Tools H.O. CS435, M. Wainer page 1
2 Notice that the stories are small and lack many details. The idea is that a customer is readily available for the development team to meet with to work out the details. In this example we will assume all the stories should be implemented for this iteration. The first code that should be written (aside from a spike if necessary) are the tests which help to define what your objects should do. 3. Readying the basic classes Sometimes it is hard to think about the basic objects when all you can imagine is the sketch of the GUI. However, it is commonly recognized, that the GUI and the underlying functionality are most often better implemented as separate but cooperating objects. The underlying functionality (often referred to as the model) is independent of the particular GUI used to represent and manipulate it. We can develop the model separate from the interface. This better allows porting to different window systems, development of GUI s by trained GUI designers, better used of specialized hardware, etc. There are 2 immediate advantages for us: 1. Development can proceed without needing to know GUI programming; 2. Unit tests are easily automated if you don t need to worry about the GUI. Thus we focus first on the model component. This object should be able to represent the states required. It should support state transition functions and be able to respond to queries about what state it is currently in. We call the object type, StateModel. Figure 2: The class which represents the model for the application. attributes methods StateModel curstate: keeps current state getstate(): returns current state nextstate(): go to next state backstate(): go back one state Now we can begin to write tests which confirm the behavior of the model. The tests are to be written in Java using JUnit. Writing the tests within the Netbeans environment will allow Ant to automatically, compile, execute and generate reports about the tests. To start, bring up Netbeans and start a new project.(if this is the first time that you are using Netbeans you may also be asked to specify a file to store your settings. On the Windows machines in the lab use H:NetBInfo. The H drive is networked so you will have access to your settings even when you use a different PC.) a. Use the Project menu to bring up the Project Manager. b. Create a New project (the example name used is toolex) c. Have a directory ready for your new project. Under the Netbeans Explorer you will need to mount a file system for your project. Make sure the Netbeans Explorer is in Filesystems mode. To mount your directory, use the File --> Mount Filesystem menu and specify a Filesystem which is a Local Directory. Select your project directory. d. To create Java code, you will need to be ready to define what package that the code will be in. Java relates packages to directory structure so a package name will (likely) use a subdirectory of Tools H.O. CS435, M. Wainer page 2
3 your project directory. The subdirectory is set up for you if you use File --> New and select the Template for a Java Package. We use the name cs435ex1 as the package name. e. Finally to start creating your class source code: Select File --> New using the Java class template with the cs435ex1 package and the class name StateModel. A Java source file is created to define the class StateModel. Of course, the details remain to be filled in. f. In addition to the basic class needed for your application, you also need to define a class which will carry out tests. Select File --> New again and this time use the cs435ex1 package and the class name StateModelTester. 4. Preparing To Test The purist approach to Test-First software development writes tests which will always fail at first. They fail because the code for the objects being tested hasn t been written yet so the test cannot possibly pass. Our tests will use the JUnit testing framework. Here s a start /* * StateModelTester.java * * Created on August 10, 2002, 3:58 PM */ package cs435ex1; import junit.framework.*; File name also gives class name We use the JUnit framework /** * wainer */ public class StateModelTester extends TestCase { /** Creates a new instance of StateModelTester */ public StateModelTester(String aname) { super(aname); extending the JUnit class TestCase Using reflection, tests are collected and run public static Test suite() { return new TestSuite(StateModelTester.class); public static void main(string[ ] args) { junit.textui.testrunner.run(suite()); Main will run a GUI application which performs and displays the tests Our test methods all begin with test public void testinitialstate() { StateModel model = new StateModel(); assertequals("check initial state", StateModel.START, model.getstate() ); JUnit provides assert methods for testing Figure 3: A start on the StateModelTester class which uses the JUnit framework to test the StateModel class. Tools H.O. CS435, M. Wainer page 3
4 Of course, this test will fail to even compile since the method getstate() and constant START are not even defined. A purist approach would be to try the test and let the compiler tell you what you need to fix. The advantage of this method is that you won t be implementing things unless you absolutely need them. We will go ahead and add some code to the StateModel class so at least things will compile. Our bare-bones implementation follows. /* * StateModel.java * * Created on August 10, 2002, 11:26 AM */ package cs435ex1; /** * wainer */ public class StateModel { static final int START = 1; added to allow compilation /** Creates a new instance of StateModel */ public StateModel() { public int getstate() { return 0; Figure 4: Adding just enough code to StateModel so that the first test can compile. 5. Using Ant to Compile Netbeans, like most IDEs, can automatically compile and run the software you write. If you ve developed software on UNIX systems you are probably familiar with make, an application which reads a file of dependencies and instructions to automate development tasks. You can think of Ant as a Java based make replacement. Ant isincluded with Netbeans. By default, Ant sinstructions arein afilenamedbuild.xml. Indeed, the build file is in plain text with xml formatting. It may be created by Netbeans and it is recognized with a special icon in the Netbeans Explorer window. From that window you can run any target (you specify each task of interest as a target) by double-clicking on its name. From the File --> Open window you may select an Ant build file template. If you select the empty one you will get a very small file. Replace its contents with the following. Tools H.O. CS435, M. Wainer page 4
5 Note: E:\netbeans\modules\patches\org-apache-tools-ant-module\junit.jar shown as a pathelement location in the build.xml file must give the path location of the JUnit jar file. You will need to obtain this jar file. Read the installation instructions or use the path given as an indication of where it should be placed. If you do not set this up correctly, the example will fail to compile. Create your build file within your project directory not inside your package directory (cs435ex1). <?xml version="1.0"?> <!-- build.xml, for Ant to compile Java sources, cs435ex1, Wainer --> <project basedir="." default="compile"> <target name="compile"> <javac debug="true" deprecation="true" destdir="." srcdir="." verbose="true" > <classpath> <!-- gives location of junit framework objects to java compiler --> <pathelement location="e:\netbeans\modules\patches\org-apache-tools-ant-module\junit.jar"/> </classpath> </javac> </target> </project> Assuming your build.xml file is as above (with a proper pathelement location to the junit jar file) you should see the build.xml icon in the Netbeans Explorer window. Click the show inside lever icon to its left, and the target compile should appear. Double-click on the compile target to make Ant execute that task. If all goes well your code should successfully compile. The IDE will switch to the Running window work-set. To get back to the Editing work-set click its tab or use the View --> Workspaces menu selection. 6. Using Ant to Run Tests Replace with the proper path location for your system Figure 5: An Ant build.xml file to compile the StateModel and its tester class. To run the JUnit tests the code first has to be compiled and then run. The build file will need another target; we ll call it utest. The additional text to be added is shown below. Double-click on the utest target in the Netbeans Explorer to run the unit tests. <target depends="compile" description="execute Unit Tests" name="utest"> <java classname="junit.swingui.testrunner" failonerror="true" fork="true"> <arg value = "cs435ex1/statemodeltester" /> <classpath> <pathelement location="e:\netbeans\modules\patches\org-apache-tools-ant-module\junit.jar"/> <pathelement location="."/> </classpath> </java> </target> Figure 6: Additional target to add to the build.xml file to enable running the Junit tests. Insert between the <project> </project> tags. Tools H.O. CS435, M. Wainer page 5
6 If you were successful, you will see the JUnit testing application pop-up (Figure 7). If you had problems, consult Figure 8 to make sure that your files are in the proper places. Project Directory Figure 8: The directory structure of the files used in this example as shown by the Netbeans Explorer. Double-clicking on utest should launch the testing application after making sure that the code is compiled. Figure 7: The Unit Test should compile and run but as expected will fail during execution. 7. Coding to Pass the Test Production coding (and testing) with extreme Programming is to be done with Pair Programming. That aside, the tests should drive the code. We have a test that failed so we must code what is needed to pass it. In this case, we need to maintain the state as a variable and set it properly when initialized. The state also needs to be accurately retrieved. See the modifications in Figure 9 below. Running the utest target should now result in the test passing. package cs435ex1; // make sure to include the package statement public class StateModel { static final int START = 1; private int curstate; /** Creates a new instance of StateModel */ public StateModel() { curstate = START; public int getstate() { return curstate; Figure 9: Adding code to so that the StateModel passes the test. Just enough code was added to pass the test. Tools H.O. CS435, M. Wainer page 6
7 8. Repeating the Cycle: Test Coding, Testing, Code Corrections to Pass Tests Obviously we aren t finished yet. Many cycles of writing tests, running tests and coding are needed. A cycle takes on the order of 15 minutes. Figure 10 shows tests for the back andnext navigation methods. Figure 11 shows the modified source for StateModel so that it passes the tests. Use the code in Figures 10 and 11 to further advance your implementation: testing with the code in Figure 10 before applying the code in Figure 11. public void testbasicnavigation() { StateModel model = new StateModel(); model.nextstate(); assertequals("next to State1", StateModel.STATE1, model.getstate() ); model.nextstate(); assertequals("next to State2", StateModel.STATE2, model.getstate() ); model.backstate(); assertequals("back to State1", StateModel.STATE1, model.getstate() ); model.nextstate(); // move to state2 model.nextstate(); // move to finish assertequals("next to Finish", StateModel.FINISH, model.getstate() ); model.backstate(); assertequals("back to State2", StateModel.STATE2, model.getstate() ); Figure 10: Tests for typical navigation behavior using backstate and nextstate methods. public class StateModel { static final int START = 1; static final int STATE1 = 2; static final int STATE2 = 3; static final int FINISH = 4; private int curstate; /** Creates a new instance of StateModel */ public StateModel() { curstate = START; public int getstate() { return curstate; Figure 11: Code to support typical navigation behavior using backstate and nextstate methods and a current state variable. public void nextstate() { curstate++; public void backstate() { curstate--; We should make sure to test problematic areas. For example, what should happen if we try to move back from the start state or forward from the finish state? The customer should determine Tools H.O. CS435, M. Wainer page 7
8 what sort of behavior makes sense. Part of the customer responsibility is to write tests for the stories. In this case, our rules will be that a back move from state start does nothing and a forward move from state finish does nothing. Figure 12 shows the test code for these exception cases. Your test cases should make sure to cover boundary conditions and other unusual cases which may be encountered. As Figure 13 illustrates, the exception case tests fail. public void testbndrynavigation() { StateModel model = new StateModel(); model.backstate(); assertequals("back from Start", StateModel.START, model.getstate() ); model.nextstate(); model.backstate(); model.backstate(); model.backstate(); assertequals("back again from Start", StateModel.START, model.getstate() ); // move from start to S1, S2, Finish model.nextstate(); model.nextstate(); model.nextstate(); assertequals("next to Finish", StateModel.FINISH, model.getstate() ); model.nextstate(); model.nextstate(); model.nextstate(); // and try to move further assertequals("nexts at Finish", StateModel.FINISH, model.getstate() ); Figure 12: Tests for navigation behavior at border conditions. Figure 13: Earlier tests pass, but the test for navigation at boundary conditions fails. The detail gives the assert statement which caused the failure. Figure 14: Revising the nextstate and backstate methods as shown can fix the problem. All tests now pass. public void nextstate() { if (curstate < FINISH) curstate++; public void backstate() { if (curstate > START) curstate--; Extreme Programming promotes the idea You Ain t Gonna Need It (YAGNI). Meaning that we shouldn t be spending a lot of effort designing for all future possibilities. The YAGNI principle often applies since many future plans are frequently changed or cancelled. We used that principle here to design a very simple mechanism for supporting state change. Tools H.O. CS435, M. Wainer page 8
9 9. Creating and Compiling the Application and Interface So far we have created the underlying object model and tests for that object. We need to create the actual user application which calls upon the model and supports interaction with the user. While progress is being made in automatic testing tools for GUI code, we will not consider that here. We construct a simple Swing interface for a Java application, a screen shot is shown in Figure 15. You may also use visual tools to design an interface. (Netbeans has a GUI editor. The CS Department also has Visual Cafe). In Xp you might use a spike to explore and experiment to quickly test out ideas. Any code developed as part of a spike is not consider production code (It wasn t developed test-first with pair programming). It should be discarded. Figure 15: A java application which uses Swing to provide a GUI for the statemodel. As yet it is not hooked up to the StateModel code. It also fails to provide the user with sufficient feedback since the current state is not indicated. /* * StateApp.java * * Created on August 11, 2002, 2:54 PM */ package cs435ex1; import javax.swing.*; import java.awt.*; import java.awt.event.*; Figure 16: StateApp.java, source code to create the application and interface shown in Figure 15. /** * wainer */ public class StateApp { JLabel startlabel; JLabel state1label; JLabel state2label; JLabel finishlabel; JButton nextbut; JButton backbut; public StateApp() { Tools H.O. CS435, M. Wainer page 9
10 Figure 16 continued. public static void main(string[] args) { JFrame frame = new JFrame("Example State Application GUI"); StateApp app = new StateApp(); // Create Buttons app.nextbut = new JButton("Next"); app.nextbut.addactionlistener(new ActionListener() { public void actionperformed(actionevent e) { // make the button click do something ); app.backbut = new JButton("Back"); app.backbut.addactionlistener(new ActionListener() { public void actionperformed(actionevent e) { // make the button click do something ); // group the buttons in a JPanel JPanel buttonpane = new JPanel(); // uses default flow layout buttonpane.add(app.nextbut); buttonpane.add(app.backbut); // Create the labels and have them align at their horizontal centers app.startlabel = new JLabel("Start"); app.startlabel.sethorizontalalignment(jlabel.center); app.state1label= new JLabel("State 1"); app.state1label.sethorizontalalignment(jlabel.center); app.state2label= new JLabel("State 2"); app.state2label.sethorizontalalignment(jlabel.center); app.finishlabel= new JLabel("Finish"); app.finishlabel.sethorizontalalignment(jlabel.center); JPanel labelpane = new JPanel(); // group the labels in a JPanel // Use a GridLayout to align the labels in a single column labelpane.setlayout(new GridLayout(4,1)); labelpane.add(app.startlabel); labelpane.add(app.state1label); labelpane.add(app.state2label); labelpane.add(app.finishlabel); // Place the buttons and labels into the frame frame.getcontentpane().add(buttonpane,borderlayout.south); frame.getcontentpane().add(labelpane,borderlayout.center); frame.addwindowlistener(new WindowAdapter() { // so app exits upon window closing public void windowclosing(windowevent e) { System.exit(0); ); //Finish setting up the frame, and show it. frame.pack(); frame.setsize(340,300); frame.setvisible(true); Tools H.O. CS435, M. Wainer page 10
11 The source code for StateApp.java must be added to the project directory. To compile, build.xml should be modified to add another target for Ant. Insert the following to create a run target within your build.xml file. <target depends="compile" description="run the Application" name="run"> <java classname="cs435ex1.stateapp" failonerror="true" fork="true"> <classpath> <pathelement location="."/> </classpath> </java> </target> Figure 17: Ant target to compile and run the application. 10. Connecting the Application to the Model The basic idea is to make the application act as a wrapper around the functionality of the model. The application should instantiate a model object. It queries the object and reflects the object s state in its interface. User interaction should be passed from the application to the model. In a more sophisticated application we would probably use a Model-View-Controller pattern. Following the YAGNI idea we just keep it simple here. The following code fragments can be added to the StateApp source to produce the connected working application. public void updatelabels(statemodel m) { // set all to unselected - black startlabel.setforeground(color.black); state1label.setforeground(color.black); state2label.setforeground(color.black); finishlabel.setforeground(color.black); // query the model to find and show the current state int thestate = m.getstate(); switch (thestate) { case StateModel.START: startlabel.setforeground(color.red); break; case StateModel.STATE1: state1label.setforeground(color.red); break; case StateModel.STATE2: state2label.setforeground(color.red); break; case StateModel.FINISH: finishlabel.setforeground(color.red); break; model.backstate(); // for back button only model.nextstate(); // for next button only app.updatelabels(model); //Make sure the true initial state is shown app.updatelabels(model); Define another method for StateApp. updatelabels is responsible for making sure that the interface reflects the state of the model. Red letters indicate the current state. Put final in front of the declaration for app andaddalinetodeclarea model object. final StateModel model = new StateModel(); The button handlers act on the model and then query the model s state. (add to both button s actionperformed methods) To make sure the initial state is visualized correctly, query the model s state. (add before frame.pack() ) Figure 18: Code to add to StateApp.java to create the application and interface which utilizes the model. Tools H.O. CS435, M. Wainer page 11
12 11. What Next? If automatic tests aren t used to check the application/interface, manual tests are used. These tests may be associated with the stories and are provided by the customer (or by closely working with the customer to establish the tests). Developers should also get frequent feedback from the customer about the interface design and appearance. At some point, suggestions must be expressed as new stories and the customer must make the business decisions about which stories have higher priorities. (Fixing bugs/glitches are necessarily compared with the value of adding new features.) 12. Refactoring After a while, changes in code build up and you often realize that things are more complicated than they should be. The code is said to start to smell and it starts to become more error prone and difficult to maintain. Refactoring is the process of reorganizing the code. One way to tell if refactoring is appropriate is to notice if you have nearly identical code which repeats itself several times. In our example, creating JLabels uses several calls which are nearly identical for each label. A refactoring might create a new method which consolidates those calls. Figure 19 shows such a method and how it might be used. // add this method in StateApp public JLabel initlabel(string text) { JLabel lab = new JLabel(text); lab.sethorizontalalignment(jlabel.center); return lab; // Creating Labels is now much simpler labelpane.add(app.startlabel = app.initlabel("start")); labelpane.add(app.state1label = app.initlabel("state 1")); labelpane.add(app.state2label = app.initlabel("state 2")); labelpane.add(app.finishlabel = app.initlabel("finish")); Figure 19: An example of refactoring that applies to StateApp. The code which creates new JLabels has been simplified by introducing a new method. 13. Deployment Since it is important for your customer to run your application, you must consider how they will be able to do this with a minimum amount of fuss. This is how to make a java application doubleclickable on a Windows machine. It assumes that Java and any necessary class libraries are already loaded. It also assumes that the PATH variable includes the java binaries directory. Italics below show my values for the example application. The javaw.exe executable runs a java class file (with a main entry point) without opening a command window. a. Create a shortcut for the StateApp file. Place it in your project directory b. Edit the properties of the shortcut. Change the Target: to run javaw C:\WINNT\SYSTEM32\javaw.exe -classpath "." cs435ex1.stateapp Change the Start in: field to your project directory. E:\AANewJava\MyCodeTests\ToolsHO c. Change the name of the modified shortcut to something sensible like Run StateApp Tools H.O. CS435, M. Wainer page 12
13 Common Problems Extra subdirectories appear Make sure you have included the package statement in your source files. Check the relative positions of your files (see Figure 8) Can t compile test code Make sure the JUnit files are installed and the path element in your build file is given for its location. Annoying glyphs appear in the source editor The editor is scanning the files and if it can t find a particular package (like JUnit) all the functions from that file will be flagged with a red boxed x. You can tell the editor where the package is located, the scan will succeed and the glyphs will go away. From the main window open the Tools Menu and select Options (see Figure below). You ll want to pick the Expert tab of the Java Sources section and set the Parser Class Path so it gives the location of the package which the IDE can t find. You may have to exit and restart the IDE before it notices that the statements can be parsed and removes the glyph. Update this path Tools H.O. CS435, M. Wainer page 13
Getting Started with Java Development and Testing: Netbeans IDE, Ant & JUnit
Getting Started with Java Development and Testing: Netbeans IDE, Ant & JUnit 1. Introduction These tools are all available free over the internet as is Java itself. A brief description of each follows.
More informationState Application Using MVC
State Application Using MVC 1. Getting ed: Stories and GUI Sketch This example illustrates how applications can be thought of as passing through different states. The code given shows a very useful way
More informationPrototyping a Swing Interface with the Netbeans IDE GUI Editor
Prototyping a Swing Interface with the Netbeans IDE GUI Editor Netbeans provides an environment for creating Java applications including a module for GUI design. Here we assume that we have some existing
More informationCore XP Practices with Java and Eclipse: Part 1
1. Introduction Core XP Practices with Java and Eclipse: Part 1 This tutorial will illustrate some core practices of Extreme Programming(XP) while giving you a chance to get familiar with Java and the
More informationControl 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 informationGUI 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 informationSwing 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 informationEclipsing Your IDE. Figure 1 The first Eclipse screen.
Eclipsing Your IDE James W. Cooper I have been hearing about the Eclipse project for some months, and decided I had to take some time to play around with it. Eclipse is a development project (www.eclipse.org)
More informationThe 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 informationSwing from A to Z Using Focus in Swing, Part 2. Preface
Swing from A to Z Using Focus in Swing, Part 2 By Richard G. Baldwin Java Programming, Lecture Notes # 1042 November 27, 2000 Preface Introduction Sample Program Interesting Code Fragments Summary What's
More informationClass 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 informationGraphical 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 informationCS56 final (E03) W15, Phill Conrad, UC Santa Barbara Wednesday, 03/18/2015. Name: Umail umail.ucsb.edu. Circle one: 4pm 5pm 6pm
CS56 final (E03) W15, Phill Conrad, UC Santa Barbara Wednesday, 03/18/2015 Name: Umail Address: @ umail.ucsb.edu Circle one: 4pm 5pm 6pm Please write your name only on this page. That allows me to grade
More informationTopic 9: Swing. Swing is a BIG library Goal: cover basics give you concepts & tools for learning more
Swing = Java's GUI library Topic 9: Swing Swing is a BIG library Goal: cover basics give you concepts & tools for learning more Assignment 5: Will be an open-ended Swing project. "Programming Contest"
More informationTopic 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!
Swing = Java's GUI library Topic 9: Swing Swing is a BIG library Goal: cover basics give you concepts & tools for learning more Why are we studying Swing? 1. Useful & fun! 2. Good application of OOP techniques
More informationBeyond CSE143. What s Left To Do? Templates. Using Templates. A Template Class. A Problem with Reusing Code CSE 143
What s Left To Do? Beyond CSE143 Templates Modern Software Development Windows and Java 143 Wrapup Beyond the C++ covered in this course Many topics, many more details of topics we did cover Main omission:
More informationBuilding a GUI in Java with Swing. CITS1001 extension notes Rachel Cardell-Oliver
Building a GUI in Java with Swing CITS1001 extension notes Rachel Cardell-Oliver Lecture Outline 1. Swing components 2. Building a GUI 3. Animating the GUI 2 Swing A collection of classes of GUI components
More informationBuilding 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 informationInterfaces & 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 informationOutline. Topic 9: Swing. GUIs Up to now: line-by-line programs: computer displays text user types text AWT. A. Basics
Topic 9: Swing Outline Swing = Java's GUI library Swing is a BIG library Goal: cover basics give you concepts & tools for learning more Assignment 7: Expand moving shapes from Assignment 4 into game. "Programming
More informationCSEN401 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 informationMIT 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 informationExample 3-1. Password Validation
Java Swing Controls 3-33 Example 3-1 Password Validation Start a new empty project in JCreator. Name the project PasswordProject. Add a blank Java file named Password. The idea of this project is to ask
More informationCS415 Human Computer Interaction
CS415 Human Computer Interaction Lecture 5 HCI Design Methods (GUI Builders) September 18, 2015 Sam Siewert A Little Humor on HCI Sam Siewert 2 WIMP GUI Builders The 2D GUI is the Killer App for WIMP Floating
More informationFrames, GUI and events. Introduction to Swing Structure of Frame based applications Graphical User Interface (GUI) Events and event handling
Frames, GUI and events Introduction to Swing Structure of Frame based applications Graphical User Interface (GUI) Events and event handling Introduction to Swing The Java AWT (Abstract Window Toolkit)
More informationTo 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 informationModule Road Map. 7. Version Control with Subversion Introduction Terminology
Module Road Map 1. Overview 2. Installing and Running 3. Building and Running Java Classes 4. Refactoring 5. Debugging 6. Testing with JUnit 7. Version Control with Subversion Introduction Terminology
More information(Incomplete) History of GUIs
CMSC 433 Programming Language Technologies and Paradigms Spring 2004 Graphical User Interfaces April 20, 2004 (Incomplete) History of GUIs 1973: Xerox Alto 3-button mouse, bit-mapped display, windows 1981:
More informationIntroduction 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 informationCS Exam 1 Review Suggestions
CS 235 - Fall 2015 - Exam 1 Review Suggestions p. 1 last modified: 2015-09-30 CS 235 - Exam 1 Review Suggestions You are responsible for material covered in class sessions, lab exercises, and homeworks;
More informationEvent Driven Programming
Event Driven Programming Part 1 Introduction Chapter 12 CS 2334 University of Oklahoma Brian F. Veale 1 Graphical User Interfaces So far, we have only dealt with console-based programs Run from the console
More informationBuilding 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 informationCalculator 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 information1005ICT Object Oriented Programming Lecture Notes
1005ICT Object Oriented Programming Lecture Notes School of Information and Communication Technology Griffith University Semester 2, 2015 1 20 GUI Components and Events This section develops a program
More informationG51PGP 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 informationGraphics 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 informationWindow 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 informationStoring and Managing Code with CVS
Storing and Managing Code with CVS One of the most important things you do, as a software developer, is version source code and other project files. What does it mean to version a file? According to Merriam
More informationTask-Oriented Solutions to Over 175 Common Problems. Covers. Eclipse 3.0. Eclipse CookbookTM. Steve Holzner
Task-Oriented Solutions to Over 175 Common Problems Covers Eclipse 3.0 Eclipse CookbookTM Steve Holzner Chapter CHAPTER 6 6 Using Eclipse in Teams 6.0 Introduction Professional developers frequently work
More informationCSE 70 Final Exam Fall 2009
Signature cs70f Name Student ID CSE 70 Final Exam Fall 2009 Page 1 (10 points) Page 2 (16 points) Page 3 (22 points) Page 4 (13 points) Page 5 (15 points) Page 6 (20 points) Page 7 (9 points) Page 8 (15
More informationLab 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 informationPart 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 informationAssignment 1. Application Development
Application Development Assignment 1 Content Application Development Day 1 Lecture The lecture provides an introduction to programming, the concept of classes and objects in Java and the Eclipse development
More informationProgramming Languages and Techniques (CIS120e)
Programming Languages and Techniques (CIS120e) Lecture 29 Nov. 19, 2010 Swing I Event- driven programming Passive: ApplicaHon waits for an event to happen in the environment When an event occurs, the applicahon
More informationCPS122 Lecture: Graphical User Interfaces and Event-Driven Programming
CPS122 Lecture: Graphical User Interfaces and Event-Driven Programming Objectives: Last revised 1/15/10 1. To introduce the notion of a component and some basic Swing components (JLabel, JTextField, JTextArea,
More informationJava Swing Introduction
Course Name: Advanced Java Lecture 18 Topics to be covered Java Swing Introduction What is Java Swing? Part of the Java Foundation Classes (JFC) Provides a rich set of GUI components Used to create a Java
More informationJava 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 informationContinuous Integration (CI) with Jenkins
TDDC88 Lab 5 Continuous Integration (CI) with Jenkins This lab will give you some handson experience in using continuous integration tools to automate the integration periodically and/or when members of
More informationWindow 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 informationpublic class Foo { private int var; public int Method1() { // var accessible anywhere here } public int MethodN() {
Scoping, Static Variables, Overloading, Packages In this lecture, we will examine in more detail the notion of scope for variables. We ve already indicated that variables only exist within the block they
More informationCreating Flex Applications with IntelliJ IDEA
Creating Flex Applications with IntelliJ IDEA In this tutorial you will: 1. Create an IntelliJ IDEA project with Flex-enabled module 2. Create Ant build configuration to compile and run Flex application
More informationOverview. Building Graphical User Interfaces. GUI Principles. AWT and Swing. Constructing GUIs Interface components GUI layout Event handling
Overview Building Graphical User Interfaces Constructing GUIs Interface components GUI layout Event handling 4.1 GUI Principles AWT and Swing Components: GUI building blocks. Buttons, menus, sliders, etc.
More informationGraphic 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 informationChapter Two Bonus Lesson: JavaDoc
We ve already talked about adding simple comments to your source code. The JDK actually supports more meaningful comments as well. If you add specially-formatted comments, you can then use a tool called
More informationWe are on the GUI fast track path
We are on the GUI fast track path Chapter 13: Exception Handling Skip for now Chapter 14: Abstract Classes and Interfaces Sections 1 9: ActionListener interface Chapter 15: Graphics Skip for now Chapter
More informationGUI Program Organization. Sequential vs. Event-driven Programming. Sequential Programming. Outline
Sequential vs. Event-driven Programming Reacting to the user GUI Program Organization Let s digress briefly to examine the organization of our GUI programs We ll do this in stages, by examining three example
More informationJavadocing in Netbeans (rev )
Javadocing in Netbeans (rev. 2011-05-20) This note describes how to embed HTML-style graphics within your Javadocs, if you are using Netbeans. Additionally, I provide a few hints for package level and
More informationAP 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 informationNetBeans IDE Java Quick Start Tutorial
NetBeans IDE Java Quick Start Tutorial Welcome to NetBeans IDE! This tutorial provides a very simple and quick introduction to the NetBeans IDE workflow by walking you through the creation of a simple
More informationIntroduction to Programming in C Department of Computer Science and Engineering. Lecture No. #17. Loops: Break Statement
Introduction to Programming in C Department of Computer Science and Engineering Lecture No. #17 Loops: Break Statement (Refer Slide Time: 00:07) In this session we will see one more feature that is present
More informationCOMP-202 Unit 10: Basics of GUI Programming (Non examinable) (Caveat: Dan is not an expert in GUI programming, so don't take this for gospel :) )
COMP-202 Unit 10: Basics of GUI Programming (Non examinable) (Caveat: Dan is not an expert in GUI programming, so don't take this for gospel :) ) Course Evaluations Please do these. -Fast to do -Used to
More informationIntroduction. Overview of the Course on Java. Overview of Part 1 of the Course
Introduction Michael B. Spring Department of Information Science and Telecommunications University of Pittsburgh spring@imap.pitt.edu http://www.sis.pitt.edu /~spring Overview of the Course on Java Part
More informationThe NetBeans IDE is a big file --- a minimum of around 30 MB. After you have downloaded the file, simply execute the file to install the software.
Introduction to Netbeans This document is a brief introduction to writing and compiling a program using the NetBeans Integrated Development Environment (IDE). An IDE is a program that automates and makes
More informationGUI 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.
GUI Applications The C implementation of Python comes with Tkinter for writing Graphical User Interfaces (GUIs). The GUI toolkit that you get automatically with Jython is Swing, which is included with
More informationHello! ios Development
SAMPLE CHAPTER Hello! ios Development by Lou Franco Eitan Mendelowitz Chapter 1 Copyright 2013 Manning Publications Brief contents PART 1 HELLO! IPHONE 1 1 Hello! iphone 3 2 Thinking like an iphone developer
More informationProgramming 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 informationPHY Microprocessor Interfacing Techniques LabVIEW Tutorial - Part X File Output and Input
PHY 406 - Microprocessor Interfacing Techniques LabVIEW Tutorial - Part X File Output and Input Introduction File I/O tends to be complex - simply because there are a myriad of things that you might want
More informationIntroduction to Extreme Programming. Extreme Programming is... Benefits. References: William Wake, Capital One Steve Metsker, Capital One Kent Beck
Introduction to Extreme Programming References: William Wake, Capital One Steve Metsker, Capital One Kent Beck Extreme Programming is... Lightweight software development method used for small to medium-sized
More informationSWING - GROUPLAYOUT CLASS
SWING - GROUPLAYOUT CLASS http://www.tutorialspoint.com/swing/swing_grouplayout.htm Copyright tutorialspoint.com Introduction The class GroupLayout hierarchically groups components in order to position
More informationObject-Oriented Programming: Revision. Revision / Graphics / Subversion. Ewan Klein. Inf1 :: 2008/09
Object-Oriented Programming: Revision / Graphics / Subversion Inf1 :: 2008/09 Breaking out of loops, 1 Task: Implement the method public void contains2(int[] nums). Given an array of ints and a boolean
More informationCOMP220/285 Lab sessions 1-3
COMP220/285 Lab sessions 1-3 Contents General Notes... 2 Getting started... 2 Task 1 Checking your ANT install... 2 Task 2 Checking your JUnit install... 2 Task 3 JUnit documention review... 4 Task 4 Ant
More informationGraphical 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 informationJava.net - the Source for Java(tm) Technology Collaboration
java.net > All Articles > http://today.java.net/pub/a/today/2006/02/21/building-guis-with-swixml.html Building GUIs with SwiXml by Joshua Marinacci 02/21/2006 Contents The Layout Problem What is SwiXml?
More informationCS 251 Intermediate Programming GUIs: Components and Layout
CS 251 Intermediate Programming GUIs: Components and Layout Brooke Chenoweth University of New Mexico Fall 2017 import javax. swing.*; Hello GUI public class HelloGUI extends JFrame { public HelloGUI ()
More informationName: Checked: Learn about listeners, events, and simple animation for interactive graphical user interfaces.
Lab 15 Name: Checked: Objectives: Learn about listeners, events, and simple animation for interactive graphical user interfaces. Files: http://www.csc.villanova.edu/~map/1051/chap04/smilingface.java http://www.csc.villanova.edu/~map/1051/chap04/smilingfacepanel.java
More informationExample Programs. COSC 3461 User Interfaces. GUI Program Organization. Outline. DemoHelloWorld.java DemoHelloWorld2.java DemoSwing.
COSC User Interfaces Module 3 Sequential vs. Event-driven Programming Example Programs DemoLargestConsole.java DemoLargestGUI.java Demo programs will be available on the course web page. GUI Program Organization
More informationGetting Started With Android Feature Flags
Guide Getting Started With Android Feature Flags INTRO When it comes to getting started with feature flags (Android feature flags or just in general), you have to understand that there are degrees of feature
More informationStarting 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 informationSINGLE EVENT HANDLING
SINGLE EVENT HANDLING Event handling is the process of responding to asynchronous events as they occur during the program run. An event is an action that occurs externally to your program and to which
More informationKF5008 Program Design & Development. Lecture 1 Usability GUI Design and Implementation
KF5008 Program Design & Development Lecture 1 Usability GUI Design and Implementation Types of Requirements Functional Requirements What the system does or is expected to do Non-functional Requirements
More informationPhase 2: Due 05/02/18 The Gui now stores and displays a graph in response to user mouse clicks on the screen.
Spring 2018 CS313 Project Implementation of a GUI to work with Graphs. Reminder: This is a pass/fail assignment, you must pass it to pass the course. You do not have to do a perfect job to pass the assignment,
More informationCMSC 150 Lab 8, Part II: Little PhotoShop of Horrors, Part Deux 10 Nov 2015
CMSC 150 Lab 8, Part II: Little PhotoShop of Horrors, Part Deux 10 Nov 2015 By now you should have completed the Open/Save/Quit portion of the menu options. Today we are going to finish implementing the
More informationIntroduction to Extreme Programming
Introduction to Extreme Programming References: William Wake, Capital One Steve Metsker, Capital One Kent Beck Robert Martin, Object Mentor Ron Jeffries,et.al. 12/3/2003 Slide Content by Wake/Metsker 1
More informationProgramming Language Concepts: Lecture 8
Programming Language Concepts: Lecture 8 Madhavan Mukund Chennai Mathematical Institute madhavan@cmi.ac.in http://www.cmi.ac.in/~madhavan/courses/pl2009 PLC 2009, Lecture 8, 11 February 2009 GUIs and event
More informationSoftware Development. COMP220/COMP285 Seb Coope Ant: Structured Build
Software Development COMP220/COMP285 Seb Coope Ant: Structured Build These slides are mainly based on Java Development with Ant - E. Hatcher & S.Loughran. Manning Publications, 2003 Imposing Structure
More informationWindows XP. A Quick Tour of Windows XP Features
Windows XP A Quick Tour of Windows XP Features Windows XP Windows XP is an operating system, which comes in several versions: Home, Media, Professional. The Windows XP computer uses a graphics-based operating
More informationChapter 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 informationJava, Swing, and Eclipse: The Calculator Lab.
Java, Swing, and Eclipse: The Calculator Lab. ENGI 5895. Winter 2014 January 13, 2014 1 A very simple application (SomeimageswerepreparedwithanearlierversionofEclipseandmaynotlookexactlyasthey would with
More informationQueen s University Faculty of Arts and Science School of Computing CISC 124 Final Examination December 2004 Instructor: M. Lamb
Queen s University Faculty of Arts and Science School of Computing CISC 124 Final Examination December 2004 Instructor: M. Lamb HAND IN Answers recorded on Examination paper This examination is THREE HOURS
More informationMarthon User Guide. Page 1 Copyright The Marathon developers. All rights reserved.
1. Overview Marathon is a general purpose tool for both running and authoring acceptance tests geared at the applications developed using Java and Swing. Included with marathon is a rich suite of components
More informationConstruction: version control and system building
Construction: version control and system building Paul Jackson School of Informatics University of Edinburgh The problem of systems changing Systems are constantly changing through development and use
More informationITEC 120 4/14/11. Review. Need. Objectives. GUI basics JFrame JPanel JLabel, JButton, JTextField Layout managers. Lecture 38 GUI Interactivity
Review ITEC 120 Lecture 38 GUI GUI basics JFrame JPanel JLabel, JButton, JTextField Layout managers Flow / Box Border / Grid Objectives Need Add interactivity When you click on a button How does your code
More informationDEMYSTIFYING PROGRAMMING: CHAPTER SIX METHODS (TOC DETAILED) CHAPTER SIX: METHODS 1
DEMYSTIFYING PROGRAMMING: CHAPTER SIX METHODS (TOC DETAILED) CHAPTER SIX: METHODS 1 Objectives 1 6.1 Methods 1 void or return 1 Parameters 1 Invocation 1 Pass by value 1 6.2 GUI 2 JButton 2 6.3 Patterns
More informationEmbedding Graphics in JavaDocs (netbeans IDE)
Embedding Graphics in JavaDocs (netbeans IDE) This note describes how to embed HTML-style graphics within your JavaDocs, if you are using Netbeans. Additionally, I provide a few hints for package level
More information2IS45 Programming
Course Website Assignment Goals 2IS45 Programming http://www.win.tue.nl/~wsinswan/programmeren_2is45/ Rectangles Learn to use existing Abstract Data Types based on their contract (class Rectangle in Rectangle.
More informationS A M P L E C H A P T E R
S AMPLE CHAPTER Ant in Action Steve Loughran and Erik Hatcher Sample Chapter 2 Copyright 2007 Manning Publications brief contents 1 Introducing Ant 5 2 A first Ant build 19 3 Understanding Ant datatypes
More informationJava Help Files. by Peter Lavin. May 22, 2004
Java Help Files by Peter Lavin May 22, 2004 Overview Help screens are a necessity for making any application user-friendly. This article will show how the JEditorPane and JFrame classes, along with HTML
More informationGraphical User Interface (GUI)
Graphical User Interface (GUI) Layout Managment 1 Hello World Often have a static method: createandshowgui() Invoked by main calling invokelater private static void createandshowgui() { } JFrame frame
More informationJAVA 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 informationFirst Name: AITI 2004: Exam 2 July 19, 2004
First Name: AITI 2004: Exam 2 July 19, 2004 Last Name: Standard Track Read Instructions Carefully! This is a 3 hour closed book exam. No calculators are allowed. Please write clearly if we cannot understand
More information