Exercise14_7 - this.filled = filled; } public void...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
/* * To change this template, choose Tools | Templates * and open the template in the editor. */ /** * * @author Danielle Green */ import java.awt.*; import javax.swing.JPanel; import javax.swing.JFrame; public class Exercise14_7 extends JFrame{ public Exercise14_7() { int [] draw = new int[9]; for(int i=0; i<9;i++) { draw[i] = (int)(Math.random() * 4); } setLayout(new GridLayout(3,3,5,5)); for(int k =0; k<9; k++) { add(new FigurePanel(draw[k])); } } public static void main(String [] args){ Exercise14_7 panel = new Exercise14_7(); panel.setSize(400,200); panel.setTitle("Exercise14_7"); panel.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); panel.setVisible(true); } class FigurePanel extends JPanel { final int NOTHING = 0; final int LINE =1; final int OVAL = 2; public int type; private boolean filled; public FigurePanel() { }
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
public FigurePanel(int type) { this.type = type; } public FigurePanel(int type, boolean filled) { this.type = type;
Background image of page 2
Background image of page 3
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: this.filled = filled; } public void paintComponent(Graphics g) { super.paintComponent(g); int width = getSize().width; int height = getSize().height; switch(type) { case NOTHING: ; break; case LINE: g.setColor(Color.BLACK); g.drawLine(10, 10, width - 10, height - 10); g.drawLine(width - 10, 10, 10, height - 10); break; case OVAL: g.setColor(Color.BLACK); if (filled) g.fillOval((int)(0.1 * width), (int)(0.1 * height), (int)(0.8 * width), (int)(0.8 * height)); else g.drawOval((int)(0.1 * width), (int)(0.1 * height), (int)(0.8 * width), (int)(0.8 * height)); } } public void setType(int type) { this.type = type; repaint(); } public int getType() { return type; } public void setFilled(boolean filled) { this.filled = filled; repaint(); } public boolean isFilled() { return filled; } public Dimension getPreferredSize() { return new Dimension(80, 80); } } }...
View Full Document

Page1 / 3

Exercise14_7 - this.filled = filled; } public void...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online