Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

[Java] The MyRectangle2D class was defined in Exercise 10.12. Write an applicati

ID: 647795 • Letter: #

Question

[Java] The MyRectangle2D class was defined in Exercise 10.12. Write an application that enables the user to specify the location and size of the rectangles and displays whether the two rectangles intersect, as shown in the following figure. Enable the user to point the mouse inside a rectangle and drag it. As the rectangle being dragged, the rectangle center coordinates in the text fields are updated.

[Java] The MyRectangle2D class was defined in Exercise 10.12. Write an application that enables the user to specify the location and size of the rectangles and displays whether the two rectangles intersect, as shown in the following figure. Enable the user to point the mouse inside a rectangle and drag it. As the rectangle being dragged, the rectangle center coordinates in the text fields are updated.

Explanation / Answer

//Program for JFrame with panels

import javax.swing.*;
import java.awt.*;
public class MyGui {
   static JTextField tx1,ty1,tx2,ty2,twidth1,twidth2,theight1,theight2;
   static JLabel lx1,ly1,lx2,ly2,lwidth1,lwidth2,lheight1,lheight2;
   static JLabel isIntersect,title1,title2;
   static JButton btnRedraw;
   static JPanel toppanel,middlepanel,bottompanel;
  
   public static void main(String[] args) {
       tx1=ty1=tx2=ty2=twidth1=twidth2=theight1=theight2=new JTextField(10);
       lx1=new JLabel("Center x: " );
       ly1=new JLabel("Center y: " );
       lx2=new JLabel("Center x: " );
       ly2=new JLabel("Center y: " );
       lwidth1=new JLabel("Width : ");
       lwidth2=new JLabel("Width : ");
       lheight1=new JLabel("Height : ");
       lheight2=new JLabel("Height : ");
       title1=new JLabel("Rectangle 1");
       title2=new JLabel("Rectangle 1");
       isIntersect=new JLabel(" Two rectangles intersect is : ");
       btnRedraw=new JButton("Redraw Rectangles");
       toppanel=new JPanel(new FlowLayout(FlowLayout.LEFT));
       middlepanel=new JPanel(new FlowLayout(FlowLayout.LEFT));
       bottompanel=new JPanel(new FlowLayout(FlowLayout.LEFT));
      
       JFrame irframe=new JFrame("Example");
       toppanel.add(isIntersect);
       bottompanel.add(btnRedraw);
       middlepanel.add(lx1);middlepanel.add(tx1);
       middlepanel.add(lx2);middlepanel.add(tx2);
       middlepanel.add(ly1);middlepanel.add(ty1);
       middlepanel.add(ly2);middlepanel.add(ty2);
       middlepanel.add(lheight1);middlepanel.add(theight1);
       middlepanel.add(lheight2);middlepanel.add(theight2);
       middlepanel.add(lwidth1);middlepanel.add(twidth1);
       middlepanel.add(lwidth2);middlepanel.add(twidth2);
       middlepanel.add(btnRedraw);
       irframe.getContentPane().add(toppanel);
       irframe.getContentPane().add(middlepanel);
       irframe.getContentPane().add(bottompanel);
       irframe.setVisible(true);
       irframe.setSize(500,500);
       irframe.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
              
}
}

//Partially finished

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote