Lab 4 and Practical 4
Lab 4 and Practical 4
Surname: Mazibuko
4CPS112
Lab 4
1.
Public RectangleProgramOne() {
setTitle(“Welcome”);
setSize(WIDTH, HEIGHT);
10.
h. The method getText gets the string in the JTextField and the method
setText changes the string displayed in a JTextField.
Practical 4
Import java.awt.*;
Import javax.swing.*;
Import java.awt.event.*;
// Conversion constants
Public DistanceConversion() {
setTitle(“Distance Conversion”);
Container c = getContentPane();
c.add(centimeterLabel);
c.add(centimeterTF);
c.add(inchLabel);
c.add(inchTF);
inchTF.addActionListener(inchHandler);
setSize(WIDTH, HEIGHT);
setVisible(true);
setDefaultCloseOperation(EXIT_ON_CLOSE);
Centimeter = Double.parseDouble(centimeterTF.getText());
Inch = Double.parseDouble(inchTF.getText());
}
Public static void main(String[] args) {