Suppose you have a GUI that contains a JButton and a JLabel. Each time the button is clicked, the GUI rearranges the letters in the label. Using Javaโs event model as a basis, explain the sequence of events that happens in order for this action to take place.
Design and implement a GUI for the CDInterest program (Fig.ย 5.18). This program should let the user input the interest rate, principal, and period and should accumulate the value of the investment.
Design and implement a GUI for the Temperature class (Fig.ย 5.5). One challenge of this design is to find a good way for the user to indicate whether a Fahrenheit or Celsius value is being input. This should also determine the order of the conversion: F to C or C to F.
Design an interface for a 16-button integer calculator that supports addition, subtraction, multiplication, and division. Implement the interface so that the label of the button is displayed in the calculatorโs displayโthat is, it doesnโt actually do the math.
Challenge: Design and implement a Calculator class to go along with the interface you developed in the previous exercise. It should function the same way as a hand calculator except it only handles integers.
Modify the Converter application so that it can convert in either direction: from miles to kilometers or from kilometers to miles. Use radio buttons in your design to let the user select one or the other alternative.
Hereโs a design problem for you. A biologist needs an interactive program that calculates the average of some field data represented as real numbers. Any real number could be a data value, so you canโt use a sentinel value, such as 9999, to indicate the end of the input. Design and implement a suitable interface for this problem.
Challenge: A dialog box is a window associated with an application that appears only when needed. Dialog boxes have many uses. An error dialog is used to report an error message. A file dialog is used to help the user search for and open a file. Creating a basic error dialog is very simple in Swing. The JOptionPane class has class methods that can be used to create the kind of dialog shown in Figureย 13.11.1.
Challenge: Design and implement a version of the game Memory. In this game you are given a two-dimensional grid of boxes that contains pairs of matching images or strings. The object is to find the matching pairs. When you click a box, its contents are revealed. You then click another box. If its contents match the first one, their contents are left visible. If not, the boxes are closed up again. The user should be able to play multiple games without getting the same arrangement every time.