60 likes | 256 Views
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
E N D
Java Tutorial – Application Building Completing our Application Daniel Bryant csm1db@surrey.ac.uk Java Tutorial - Daniel Bryant
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
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
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
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
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