logo

Object-oriented Software Development

Create a JPanel and its testing class to convert pounds to kilograms and display the result in a text area.

9 Pages1222 Words17 Views
   

Added on  2022-08-24

Object-oriented Software Development

Create a JPanel and its testing class to convert pounds to kilograms and display the result in a text area.

   Added on 2022-08-24

ShareRelated Documents
MITS4002
OBJECT-ORIENTED SOFTWARE
DEVELOPMENT
Activity 09
Due: Friday Lesson 11
50% deduction for Late Submission within one week
0 mark for Late Submission more than one week
0 mark for duplicated Submission or Shared Work
You will be marked based on your submitted zipped file on Moodle. You are
most welcome to check your file with your lab tutor before your submission.
No excuse will be accepted due to file corruption, absence from lecture or lab
classes where details of lab requirements may be given.
Please make sure that you attend Lecture EVERY WEEK as low
attendance may result in academic penalty or failure of this unit.
Student ID:
Student full name:
Total Points (20 pts):
Object-oriented Software Development_1
MITS4002 Actvity 09
Project: Converting pounds to kilograms calculator
Problem Description:
Write a JPanel (Conversion.java) and its testing class (testConversion.java) with
appropriate layout to create an user interface, as shown in the figure below. Your
program should let the user enter a value in pound and should display the anwer in
kilograms in a text area when the “Convert!” button is clicked. Note, your answers should
be expressed in three decimal places, and use append() method to append the answers to
the text area so that any previous answers won’t go away.
Useful formula: 1 pound=0.453592kilograms
Analysis/Design:
jFrame, JTextArea, JLabel, JTextField is used to create the layout of this program.
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName() is used to
create look and feel. Creating button by using JButton functions. To create the panel
JPanel is used. ActionListener is used to handle every action in this
project. .setBackground is able to set the back ground colour. append() method is used to
keep every answer in the text area.
1
Object-oriented Software Development_2
MITS4002 Actvity 09
Coding:
import java.awt.event.*;
import javax.swing.*;
import java.awt.*;
import java.text.DecimalFormat;
public class testConversion extends JFrame implements ActionListener {
// create a frame
static JFrame
f;
static JTextArea
area2;
static JLabel
l1;
// create a textfield
static JTextField
l;
// store oprerator and operands
String s0, s1, s2;
// default constrcutor
testConversion() {
s0 = s1 = s2 = "";
}
// main function
@SuppressWarnings("deprecation")
public static void main(String args[]) {
// create a frame
f = new JFrame("Conversion");
f.setDefaultCloseOperation(JFrame.
EXIT_ON_CLOSE);
try {
// set look and feel
UIManager.
setLookAndFeel(UIManager.
getSystemLookAndFeelClassName());
} catch (ClassNotFoundException | IllegalAccessException |
InstantiationException
| UnsupportedLookAndFeelException e) {
System.
err.println(e.getMessage());
}
// create a object of class
testConversion c = new testConversion();
//l1 = new JLabel("Weight In Pounds:");
// create a textfield
l = new JTextField(16);
// set the textfield to non editable
l.setEditable(true);
// create number buttons and some operators
2
Object-oriented Software Development_3

End of preview

Want to access all the pages? Upload your documents or become a member.

Related Documents
Analysis/Design: Case Study
|7
|1161
|12