Question
Drawing in JPanel Create a drawing that displays a picture. Draw your picture using methods from the classes Color, Font, and Graphics. Abridged UML Diagrams
Drawing in JPanel Create a drawing that displays a picture.
Draw your picture using methods from the classes Color, Font, and Graphics.
Abridged UML Diagrams of the Color, Font, and Graphics classes.
See the Drawing Example in the drawing example class.(I cannot add any zip files so here is an example from those zip files):
// Project: Drawing // No modules defined in project // Source code file: MyFrame.java // Define MyFrame from Swing class JFrame.
import javax.swing.*; import java.awt.*;
public class MyFrame extends JFrame { private MyPanel p = null; public MyFrame() { // Set caption in title bar to "Drawing Project" super("Drawing Project");
// Create and add panel to frame. p = new MyPanel(); p.setLayout(new FlowLayout()); setContentPane(p);
// Configure frame. setSize(400, 500); setVisible(true); } }
// Project: Drawing // No modules defined in project // Source code file: MyPanel.java // Define MyPanel class derived from Swing class JPanel. // Use Graphics methods to draw on panel.
import javax.swing.*; import java.awt.*; public class MyPanel extends JPanel {
public MyPanel( ) { setBackground(Color.white); }
public void paintComponent(Graphics g) { super.paintComponent(g);
// The paintComponent method is invoked // whenever paint event occurs. This occurs // when the panel is // (1) first displayed. // (2) restored after being minimized. // (3) exposed after being hidden.
// Print title. g.setFont(new Font("arial", Font.BOLD, 30)); g.setColor(Color.red); g.drawString("Java Art", 60, 60);
// Draw circle. g.setColor(Color.cyan); g.fillOval(30, 90, 200, 200); g.setColor(Color.black); g.drawOval(30, 90, 200, 200);
// Draw square. g.setColor(Color.yellow); g.fillRect(130, 190, 200, 200); g.setColor(Color.black); g.drawRect(130, 190, 200, 200); } }
// Project: Drawing // No modules defined in project // Source code file: Main.java // Instantiate a MyFrame object derived from the // JFrame class. The MyFrame object contains a JPanel // object that displays a Swing drawing using Graphics // methods.
public class Main {
public static void main(String[] args) { new MyFrame(); } }
Submit a zip file of the IntelliJ project.
Grading Breakdown: Functionality: 55%; Creativity/Originality: 15%; Comments: 10%; Indentation: 10%; Submitted Correctly: 10% This project needs to be done by the 27th, after which I cannot submit it. I hope this helps
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started