Laboratory 9

Exercise 1

Define a Swing graphical interface for a temperature converter:

  • Open the Eclipse for Java developers.
  • Create a project lab9.
  • Create package tempconv.
  • Click in the newly created package and right-click on te mouse button. Choose: New followed by Other followed by Windows Builder followed by Swing Designer and finally  Application Window.
  • Call to the type name TemperatureConverter and click on the Finish button.

The Eclipse provides a Source and a Design tab.

  • Go to the Design  tab and design the temperature converter.
    • Use the Layouts and Components pallets.
  • When the design is finished add the required behaviour to the temperature converter.
    • Right-click on the components and choose Add event handler.
    • Implement the behaviour in the Source tab.

In the end run your program as a Java application.

Good work!

Exercise 2

Consider a calculator with the following graphical interface:

The code for this calculator is available in Calculator.java (available bellow). Run it in Eclipse:

  • Create a new package named calculator inside an Eclipse Java project.
  • Put the Calculator.java source code inside this package.
  • Run it as a Java application.

Note: In this exercise we do not have the Design and Source tabs. Everything is done in the code, componentes are added and arranged by manipulating layouts directly in the code.

We intend to add to this calculator memory with capacity for a number and new buttons with the following functionalities:

  • MC (memory clear): deletes memory;
  • MS (memory store): stores in memory the number in the screen;
  • MR (memory recall): put the number stored in memory in the screen;
  • M+: sums to the number in memory the number in the screen.

The calculator should also have another screen which indicates if there is any number stored. The calculator interface sould be as:

Whenever a number is stored in memory the screen (above the MC button) should present "M". You should do this by modifying the methods makeMemoryPad() and makeCalculator() in the code made available.

Finally, change the layout of the buttons in order to put all operations in a column and the numbers as they appear in the mobile phone.

Good work!

Attachments