A+ Work




    Write a class called point

for the 2-D environment.

Select appropriate variable(s).

Write constructors.

Write access methods for the variables.

Write a Print method to display the variables when called.

Write a test program to test it.

2)    Write a class called rectangle,

which inheres the above point class.

Select appropriate variable(s).

Write constructors.

Write access methods for the variables.

Override the inherited Print method to display variable in rectangle and point.

Write a test program to test it.


3)    Start from the following code, and add Action Listener to make it functional. (Need about 10 lines)

Note: 1 inch = .2.54 cm.

 

import javax.swing.*;

import

java.awt.GridLayout;

import

java.awt.event.*;

import

java.text.DecimalFormat;

 

public class lengthConverter extends JFrame {

  public static void

main(String[] args) {

    JFrame frame = new lengthConverter();

    frame.setTitle("Length");

    frame.setSize(200, 100);

    frame.setLocationRelativeTo(null);

    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    frame.setVisible(true);

  }

  

  public

lengthConverter() {

    JLabel lblin = new JLabel("inch",SwingConstants.CENTER);

    JLabel lblcm = new JLabel("cm",SwingConstants.CENTER);

    final

JTextField jtfin = new JTextField();

    final

JTextField jtfcm = new JTextField();

    JButton jbtLeft = new JButton("<=");

    JButton jbtRight = new JButton("=>");

  

    JPanel panel = new JPanel(new GridLayout(2, 3));

    panel.add(lblin);

    panel.add(jbtLeft);

    panel.add(lblcm);

    panel.add(jtfin);

    panel.add(jbtRight);

    panel.add(jtfcm);

    

    this.add(panel); // Add panel to the frame

    

    final

DecimalFormat dec = new DecimalFormat("#.00");

  }

}




4)    Start from the given class, and create a NewPanel class to draw a figure like below. (Need about 15 lines)

import javax.swing.*;

import

java.awt.Graphics;

import java.awt.Color;

 

public class drawPerson extends

JFrame {

  public

drawPerson() {

    add(new

NewPanel());

  }

 

  public static void

main(String[] args) {

    drawPerson frame = new drawPerson();

    frame.setTitle("Person");

    frame.setSize(200, 200);

    frame.setLocationRelativeTo(null); // Center the frame   

    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    frame.setVisible(true);    

  }

}


The circle coordinate and size is (80, 15, 20, 25).

The text coordinate is (70, 135).

The starting and ending lines coordinate are

(90, 40, 90, 80);

(60, 50, 120, 50);

(90, 80, 70, 120); and

(90, 80, 110, 120).

Color pink, with text color magenta.