Question: based on the prev code: package labexperiment 1 ; import javax.swing. * ; import java.awt. * ; import java.awt.geom.AffineTransform;; class MyFrame extends JFrame { MyFrame

based on the prev code:
package labexperiment1;
import javax.swing.*;
import java.awt.*;
import java.awt.geom.AffineTransform;;
class MyFrame extends JFrame
{
MyFrame()
{
MyPanel Panel = new MyPanel();
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setSize(800,800);
this.add(Panel);
this.setLocationRelativeTo(null);
this.setVisible(true);
}
}
class MyPanel extends JPanel
{
MyPanel()
{
this.setSize(new Dimension(500,500));
}
private void doDrawing(Graphics G)
{
Graphics2D G2D =(Graphics2D) G.create();
G2D.setPaint(new Color(255,0,0,255));
/*G2D.fillRect(20,20,80,50);
G2D.translate(150,50);
G2D.fillRect(20,20,80,50);
//Rotation
G2D.fillRect(20,20,80,50);
G2D.translate(180,-50);
G2D.rotate(Math.PI /4);
G2D.fillRect(80,80,80,50);
//Scaling
G2D.fillRect(20,20,80,50);
AffineTransform TX1= new AffineTransform();
TX1.translate(110,22);
TX1.scale(0.5,0.5);
G2D.setTransform(TX1);
G2D.fillRect(0,0,80,50); */
//Shearing
AffineTransform TX1= new AffineTransform();
TX1.translate(50,90);
G2D.setTransform(TX1);
G2D.setPaint(Color.green);
G2D.drawRect(0,0,160,50);
AffineTransform TX2= new AffineTransform();
TX2.translate(50,90);
TX2.shear(0,1);
G2D.setTransform(TX2);
G2D.setPaint(Color.blue);
G2D.draw(new Rectangle(0,0,80,50));
AffineTransform TX3= new AffineTransform();
TX3.translate(130,10);
TX3.shear(0,1);
G2D.setTransform(TX3);
G2D.setPaint(Color.red);
G2D.drawRect(0,0,80,50);
G2D.dispose();
}
@Override
public void paintComponent(Graphics G)
{
super.paintComponent(G);
doDrawing(G);
}
}
public class LabExperiment1 extends JComponent {
public static void main(String[] args){
MyFrame Frame = new MyFrame();
}
}
Q1:
1.Write a program to create, translate, and rotate an ellipse, shape of Donut .
2.Modify the above program create variants of Donuts with different colors
Q2: Write a program to create, translate and rotate a sequence of Star shape objects as displayed below.
based on the prev code: package labexperiment 1 ;

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!