..\CSC120\Java\lec32_f22\src\MUFrame.java
  1 /* CSC 120 Lecture 32
  2  *
  3  * Project Description: Processing Some or All elements in an array
  4  *
  5  */
  6 
  7 import java.awt.*;
  8 import javax.swing.*;
  9 
 10 public class MUFrame extends javax.swing.JFrame {
 11 
 12     private MUPanel muPanel;
 13     
 14     // declare private data here
 15     
 16     
 17     
 18     // constructor method
 19     public MUFrame() {
 20         initComponents();
 21         muPanel = new MUPanel();
 22         drawingPanel.add(muPanel);
 23         
 24         
 25         
 26         
 27     } // end of constructor
 28     
 29     // declare other methods here
 30     
 31     
 32     
 33     
 34 
 35     /** This method is called from within the constructor to
 36      * initialize the form.
 37      * WARNING: Do NOT modify this code. The content of this method is
 38      * always regenerated by the Form Editor.
 39      */
 40     @SuppressWarnings("unchecked")
 41     // <editor-fold defaultstate="collapsed" desc="Generated Code">                          
 42     private void initComponents() {
 43 
 44         drawingPanel = new javax.swing.JPanel();
 45         moveForwardButton = new javax.swing.JButton();
 46         turnAroundButton = new javax.swing.JButton();
 47         moveLowerForwardButton = new javax.swing.JButton();
 48         turnOuterAroundButton = new javax.swing.JButton();
 49 
 50         setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
 51         setPreferredSize(new Dimension(990, 600));
 52 
 53         drawingPanel.setPreferredSize(new Dimension(800, 520));
 54 
 55         javax.swing.GroupLayout drawingPanelLayout = new javax.swing.GroupLayout(drawingPanel);
 56         drawingPanel.setLayout(drawingPanelLayout);
 57         drawingPanelLayout.setHorizontalGroup(
 58             drawingPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
 59             .addGap(0, 801, Short.MAX_VALUE)
 60         );
 61         drawingPanelLayout.setVerticalGroup(
 62             drawingPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
 63             .addGap(0, 519, Short.MAX_VALUE)
 64         );
 65 
 66         moveForwardButton.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
 67         moveForwardButton.setText("Move Forward");
 68         moveForwardButton.addActionListener(new java.awt.event.ActionListener() {
 69             public void actionPerformed(java.awt.event.ActionEvent evt) {
 70                 moveForwardButtonActionPerformed(evt);
 71             }
 72         });
 73 
 74         turnAroundButton.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
 75         turnAroundButton.setText("Turn Around");
 76         turnAroundButton.addActionListener(new java.awt.event.ActionListener() {
 77             public void actionPerformed(java.awt.event.ActionEvent evt) {
 78                 turnAroundButtonActionPerformed(evt);
 79             }
 80         });
 81 
 82         moveLowerForwardButton.setFont(new java.awt.Font("Tahoma", 0, 10)); // NOI18N
 83         moveLowerForwardButton.setText("Lower-only Forward");
 84         moveLowerForwardButton.addActionListener(new java.awt.event.ActionListener() {
 85             public void actionPerformed(java.awt.event.ActionEvent evt) {
 86                 moveLowerForwardButtonActionPerformed(evt);
 87             }
 88         });
 89 
 90         turnOuterAroundButton.setText("Outer-only Turn");
 91         turnOuterAroundButton.addActionListener(new java.awt.event.ActionListener() {
 92             public void actionPerformed(java.awt.event.ActionEvent evt) {
 93                 turnOuterAroundButtonActionPerformed(evt);
 94             }
 95         });
 96 
 97         javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
 98         getContentPane().setLayout(layout);
 99         layout.setHorizontalGroup(
100             layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
101             .addGroup(layout.createSequentialGroup()
102                 .addComponent(drawingPanel, javax.swing.GroupLayout.PREFERRED_SIZE, 801, javax.swing.GroupLayout.PREFERRED_SIZE)
103                 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
104                     .addGroup(layout.createSequentialGroup()
105                         .addGap(28, 28, 28)
106                         .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
107                             .addComponent(moveForwardButton, javax.swing.GroupLayout.PREFERRED_SIZE, 125, javax.swing.GroupLayout.PREFERRED_SIZE)
108                             .addComponent(turnAroundButton, javax.swing.GroupLayout.PREFERRED_SIZE, 125, javax.swing.GroupLayout.PREFERRED_SIZE)
109                             .addComponent(turnOuterAroundButton, javax.swing.GroupLayout.PREFERRED_SIZE, 125, javax.swing.GroupLayout.PREFERRED_SIZE)))
110                     .addGroup(layout.createSequentialGroup()
111                         .addGap(18, 18, 18)
112                         .addComponent(moveLowerForwardButton, javax.swing.GroupLayout.PREFERRED_SIZE, 156, javax.swing.GroupLayout.PREFERRED_SIZE)))
113                 .addContainerGap(30, Short.MAX_VALUE))
114         );
115         layout.setVerticalGroup(
116             layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
117             .addGroup(layout.createSequentialGroup()
118                 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
119                     .addGroup(layout.createSequentialGroup()
120                         .addContainerGap()
121                         .addComponent(drawingPanel, javax.swing.GroupLayout.PREFERRED_SIZE, 519, javax.swing.GroupLayout.PREFERRED_SIZE))
122                     .addGroup(layout.createSequentialGroup()
123                         .addGap(85, 85, 85)
124                         .addComponent(moveForwardButton)
125                         .addGap(50, 50, 50)
126                         .addComponent(moveLowerForwardButton)
127                         .addGap(112, 112, 112)
128                         .addComponent(turnAroundButton)
129                         .addGap(42, 42, 42)
130                         .addComponent(turnOuterAroundButton)))
131                 .addContainerGap(235, Short.MAX_VALUE))
132         );
133 
134         pack();
135     }// </editor-fold>                        
136 
137     private void moveForwardButtonActionPerformed(java.awt.event.ActionEvent evt) {                                                  
138         muPanel.moveMiceForward();
139         muPanel.repaint();
140     }                                                 
141 
142     private void turnAroundButtonActionPerformed(java.awt.event.ActionEvent evt) {                                                 
143         muPanel.turnMiceAround();
144         muPanel.repaint();
145     }                                                
146 
147     private void moveLowerForwardButtonActionPerformed(java.awt.event.ActionEvent evt) {                                                       
148         muPanel.moveLowerMiceForward();
149         muPanel.repaint();
150     }                                                      
151 
152     private void turnOuterAroundButtonActionPerformed(java.awt.event.ActionEvent evt) {                                                      
153         muPanel.turnOuterMiceAround();
154         muPanel.repaint();
155     }                                                     
156 
157     /**
158      * @param args the command line arguments
159      */
160     public static void main(String args[]) {
161         java.awt.EventQueue.invokeLater(new Runnable() {
162 
163             public void run() {
164                 new MUFrame().setVisible(true);
165             }
166         });
167     }
168     // Variables declaration - do not modify                     
169     private javax.swing.JPanel drawingPanel;
170     private javax.swing.JButton moveForwardButton;
171     private javax.swing.JButton moveLowerForwardButton;
172     private javax.swing.JButton turnAroundButton;
173     private javax.swing.JButton turnOuterAroundButton;
174     // End of variables declaration                   
175 }
176