Section 64 – Manipulating Data Using Methods – Java Swing Chapter 3 Section 64 – Manipulating Data Using Methods – Java Swing
Chapter Objectives Use Swing components to build the GUI for a Swing program Use the exit() method to close a Swing program Implement an ActionListener to handle events
Using Swing Components Make a copy of your BodyMass.java program. Right click on BodyMass.java and select copy Paste a copy – Right click on bodymasscalculator
Using Swing Components Import the javax.swing.JOptionPane class Contains methods to create dialog boxes for input, confirmation, and messages Delete the IOException and BufferedReader code The swing dialog boxes buffer data from the user and handle IO errors
Swing Dialog Boxes Dialog boxes are created with the JOptionPane “show” methods The showInputDialog() and showConfirmDialog return a String containing the user input
Swing Dialog Boxes
Closing Programs that use Swing System.exit() terminates an application that displays a GUI The command prompt window closes when this method is called System.exit accepts an integer argument that serves as a status code 0 indicates successful termination 1 indicates abnormal termination
Saving, Compiling, and Running the Swing Version Compile the source code Test with the same sample data for all versions to compare output results If incorrect or unrealistic data is entered by the user, errors will occur Errors and exception handling will be discussed in a later chapter
Summary Java Swing code allows the programmer to easily display pop up windows to get input and to display output.
Rest of Today Complete the swing version of the Bass Mass Calculator Test your results Show me the program when it is complete