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

Introduction This assignment is an introduction to computer graphics using Java.

ID: 3883145 • Letter: I

Question

Introduction This assignment is an introduction to computer graphics using Java. This assignment will provide you with a preview of future assignments in this course. Java is the preferred general-purpose computer language used for web based graphics, animation, audio, and other applications. Requirements Make a Java program. The output is a single window containing a graphic area. A suggested is the following image. Shapes by Julio Cesar igreenluraClear Circle Rectangle Triangle The distance w is 1600 pixels (or more). The distance h is 900 pixels or more. It is nice to maintain the 16:9 aspect ratio, but this is not a requirement.

Explanation / Answer

import java.awt.event.*; import java.awt.geom.*; import javax.swing.*; import java.awt.*; public class CircleComponent extends JPanel { Ellipse2D.Double circle; public CircleComponent(int radius) { circle = new Ellipse2D.Double(0, 0, radius, radius); setOpaque(false); } public Dimension getPreferredSize() { Rectangle bounds = circle.getBounds(); return new Dimension(bounds.width, bounds.height); } public void paintComponent(Graphics g) { super.paintComponent(g); Graphics2D g2 = (Graphics2D) g; g2.setColor( getForeground() ); g2.fill(circle); } /* public int getWidth(int aWidth) { width = aWidth; return width; } */ public static void main(String[] args) { // Create a panel using a null layout so we can add components at random positions final JPanel center = new JPanel(); center.setLayout(null); JButton button = new JButton("Draw"); button.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent event) { String x = JOptionPane.showInputDialog("X Coordinate", "Enter an x coordinate"); int xCoord = Integer.parseInt(x); String y = JOptionPane.showInputDialog("Y Coordinate", "Enter a y coordinate"); int yCoord = Integer.parseInt(y); String width = JOptionPane.showInputDialog("Radius", "Enter the length of the radius"); int radius = Integer.parseInt(width); CircleComponent component = new CircleComponent(radius); component.setLocation(xCoord,yCoord); component.setSize(component.getPreferredSize()); center.add(component); center.repaint(); } }); JFrame frame = new JFrame(); frame.add(center, BorderLayout.CENTER); frame.add(button, BorderLayout.NORTH); frame.setSize(500, 500); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setVisible(true); } }

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