Homework 2 Solution 2

Drawlinewidth83height86width84height86

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: gle, and a Pentagon */ import java.awt.Graphics; import java.awt.Color; import javax.swing.JPanel; public class DrawPanel extends JPanel { public void paintComponent ( Graphics g ) { super.paintComponent(g); int width = getWidth(); // total width int height = getHeight(); // total height //Circle g.drawOval(25,25,75,75); //Ellipse g.drawOval ( width/5, height/5, 100, 50 ); //Filled Red Rectangle g.setColor ( Color.RED ); g.fillRect(10, 100, 30, 50); //Triangle g.setColor ( Color.BLACK ); 6 g.drawLine(150, 150, 200, 200); g.drawLine(150, 150, 100, 200); g.drawLine(100, 200, 200, 200); //Pentagon g.drawLine(((width/8)*3),((height/8)*3),((width/8)*4),((height/8)*3)); g.drawLine(((width/8)*3),((height/8)*3),((width/8)*2),((height/8)*4)); g.drawLine(((width/8)*2),((height/8)*4),((width/8)*2),((height/8)*5)); g.drawLine(((width/8)*2),((height/8)*5),((width/8)*3),((height/8)*6)); g.drawLine(((width/8)*3),((height/8)*6),((width/8)*4),((height/8)*6)); g.drawLine(((width/8)*4),((height/8)*6),((width/8)*5),((height/8)*5)); g.drawLine(((width/8)*5),((height/8)*5),((width/8)*5),((height/8)*4)); g.drawLine(((width/8)*5),((height/8)*4),((width/8)*4),((height/8)*3)); } } /* Name: Cameron Kroeker Class: CSE292 Java Hw 2: DrawPanelTest.java Desc: Test application for class DrawPanel */ import javax.swing.JFrame; public class DrawPanelTest { public static void main ( String[ ] args ) { DrawPanel panel = new DrawPanel(); JFrame apps = new JFrame(); apps.setDefaultCloseOperation ( JFrame.EXIT_ON_CLOSE ); apps.add ( panel ); apps.setSize ( 625, 500 ); apps.setVisible ( tr...
View Full Document

Ask a homework question - tutors are online