// This is part of the program used in lab exercise 01 // This part does not include the code generated by Netbeans // Please read the slides and watch the video for explanation // // This file is for reference only. It is your responsibility // to write a functional program. // // Yung-Hsiang Lu, ECE Purdue // class ShapePanel extends javax.swing.JPanel { java.awt.Color spColor; boolean spCircle; public ShapePanel() { setSize(300, 300); spColor = Color.blue; spCircle = true; } public void setShape(boolean isCircle) { spCircle = isCircle; repaint(); } public void setColor(Color c) { spColor = c; repaint(); } @@Override public void paintComponent(Graphics gfx) { gfx.setColor(spColor); if (spCircle) { gfx.fillOval(100, 100, 50, 50); } else { gfx.fillRect(100, 100, 50, 50); } } } public class NewJFrame extends javax.swing.JFrame { public NewJFrame() { initComponents(); sp = new ShapePanel(); add(sp); } private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) { sp.setColor(Color.green); } private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) { sp.setColor(Color.blue); } private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) { sp.setShape(true); } private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) { sp.setShape(false); } ShapePanel sp; }