1 / 6

Java Tutorial – Application Building

Java Tutorial – Application Building. Completing our Application Daniel Bryant csm1db@surrey.ac.uk. Overview. Today we will be tidying the project from the previous Java Tutorial labs and implementing some new functionality

mio
Download Presentation

Java Tutorial – Application Building

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Java Tutorial – Application Building Completing our Application Daniel Bryant csm1db@surrey.ac.uk Java Tutorial - Daniel Bryant

  2. Overview • Today we will be tidying the project from the previous Java Tutorial labs and implementing some new functionality • Therefore, you must have completed all the work in both Lab 1 and Lab 2 before starting this sheet • You should have NetBeans set up correctly i.e. with the appropriate directories Mounted (Remember to mount the Classes directory first then the appropriate Apps directory) • You should have the latest version of the MainFrame class compiled and working. This will be a modified version of MainClass4 that you downloaded from the internet Java Tutorial - Daniel Bryant

  3. Last weeks question • The final slide of last weeks Lab asked how you would modify the Dither code to prevent the application from terminating when the user closes any window. • Therefore, this will be your first task of the day (Hint: the code you need to modify is in the Dither constructor) • Can you tell me what you have done and why this code needed to be modified? Java Tutorial - Daniel Bryant

  4. Finalising our application • You will notice that if you click on your button labelled “Dither the Image” when you haven’t specified an image an error is generated (or “thrown” in Java terminology) but the user is not informed why • It would therefore be useful to stop this error from occurring and inform our user that they should select an image. • You will need to add an “if” statement to the action listener class for that button to check if a file has been selected (Hint. the myPicture object will be equal to null if no image has been selected) • If you have stuck to my examples the class is probably called DoloadApp1 and the method you will need to modify is called • public void actionPerformed(ActionEvent e) { Java Tutorial - Daniel Bryant

  5. Adding the if statement • The code you will write to stop the error occurring will probably look something like this: if(myPicture == null) { JOptionPane.showMessageDialog(null,"Please specify an image first"); } else { //The code to open the Dither application should go here } Java Tutorial - Daniel Bryant

  6. Finalising the Application • Now our simple GUI is complete! • If you can think of any extra functionality that is needed for the coursework, either look at the tutorials at the sun website (http://java.sun.com) or ask! • The next task for the remainder of today and the next few weeks will be to implement the applications for the coursework • Today you should attempt to implement the Enlarge code from the book (Listing 5.14) using the Dither code as a template • Remember if you get stuck please ask. Java Tutorial - Daniel Bryant

More Related