Programming of Interactive Systems (Intro)
Lectures web site
Eclipse is an IDE (Integrated Development Environment) tailored for writing programs in Java. If you haven't done it yet, install it. Below are some useful menu items in Eclipse that you should consider using:
Edit > Show Tooltip Description: toggle the display of the tooltip containing documentation about the element on which the carret is pointing at.
Source > Organize Imports: automatically adds all the missing imports.
Source > Format: nicely reformats your source code.
Source > Generate Element Comment: inserts a javadoc block comment for the element on which the carret is pointing at.
Also, the shortcut
space gives you an auto-complete menu.
The aim of this exercise is to create a temperature converter containing:
init()in the file
TempConverter.javaby using the class
JPaneland layout managers of your choice to make the resulting window look like the pictured above.
textFieldCListenerreads a floating value in the Celsius text box when the user press "enter", convert it from Celsius to Fahrenheit, and write the result in the Fahrenheit text box. Associate this listener to the text box of the Celsius value.
textFieldFListenerin order to do the conversion from Fahrenheit to Celsius. Associate it with the text box of the Fahrenheit value.
buttonCloseListenercloses the window. Associate it to the close button.
buttonResetListenerin order to empty both text boxes. Associate it to the reset button.
enter. Use a
KeyListener(that you attach with
JTextField.addKeyListener) instead of an
KeyListenerwill be notified at each key press.
the following exercise was originally made by Nicolas Roussel and is translated here in english.
The aim of this third exercise is to build a file chooser similar to the one pictured below:
The scrollable list in the middle of the window shows the content of the current folder; sub-folder names are followed by a slash (
/). The pop-up menu at the top contains a list of all parent folders of the current folder.
FileSelector.javafile by using the classes
JButtonto build the dialog box pictured above. Make sure that the location of the widgets remains consistent when resizing the window.
Cancelbutton or the
Openbutton while a file is selected closes the dialog box.
Openbutton on a selected folder updates both the scroll list and the pop-up menu.
Note that Swing provides a class, JFileChooser, that allows to easily choose a file or a folder.
Apart from 2bis the following exercises are originally made by Nicolas Roussel and are translated here in english.
The aim of this second exercise is to build a color chooser which enables users to:
The current color is previewed in a rectangular area. The whole window looks like this:
The code of the color chooser should be decomposed in 3 parts using the MVC model. The goal of this model is to separate the internal data from the way to display these data to users and the way to enable users to interact with these data. If you don't know what the MVC model is, ask your TA for explanation!
ColorChooser.javafile by using the class
JPanelto make the resulting window look like the one pictured above. It's the View of the MVC model.
JTextField, use a
DocumentListenerthat you can attach this way:
JTextField.getDocument().addDocumentListener. What do you observe?
You can use the methods
String.substring to convert a color into an hexvalue and the method
Color.decode to do the conversion in reverse.
The aim of this exercise is to build a percentage viewer similar to the one pictured below using a MVC design pattern:
PercentageSlider) to the main class (
Application.java) in order to have the same picture as above.
Percentage_Controller.javato make the link between the Model and the views (See
TODOin the code).
TODOin the code).
The aim of this exercise is to build a drawing application in order to get familiar with 2D drawing:
GraphicalEditor.javais the graphical interface.
PersistentCanvas.javais a persistent canvas which stores the created items.
CanvasItem.javais the abstraction of one item of the canvas.
RectangleItem.javais the rectangle item class (inherited from the abstract class
GraphicalEditorclass to enable mode selection: when the user clicks on a radio button, it should change the mode and update the window title accordingly.
GraphicalEditorclass to enable shape selection: when the "Select/Move" mode is active, when the user clicks on the canvas, the shape directly under the cursor should be selected. You will also have to implement the
PersistentCanvas.getItemAt(Point p)method that handles the picking of a shape at a location
pon the 2D canvas.
Clonebuttons so that the user can delete or clone (and translate a bit) the selected shape.
GraphicalEditorclass to let users move shapes in the canvas.
PathItemclasses. They should support the same features: move, delete, color change, etc. For the path, you can use the class
java.awt.geom.GeneralPath. It is recommended to check the documentation about Shape.