H:\CSC120\Java\lec09\src\MUPanel.java
  1 /* CSC 120 Lecture # 8 & 9
  2  * Blase B. Cindric
  3  * 
  4  *
  5  * Project Description:
  6  *    a sample program showing how operators work with various
  7  *    data types
  8  *
  9  */
 10 import java.awt.*;
 11 import javax.swing.*;
 12 
 13 public class MUPanel extends JPanel {
 14 
 15     // 1. Declare private objects here:
 16     
 17     private Integer x, y, z, average;
 18     private Double m, n, q;
 19     private String word;
 20 
 21     // constructor method
 22     public MUPanel() {
 23         setLayout(null);
 24         setPreferredSize(new Dimension(800, 100));
 25         setName("Mount Union Java Program");
 26         setUp();
 27         setBackground(Color.WHITE);
 28 
 29         // 2. Instantiate objects here by calling "new":
 30         
 31         x = 47;
 32         y = x + 2;
 33         z = x - 39;
 34         
 35         m = 15.5;
 36         n = 2*m;
 37         
 38         word = "Aardvark";
 39         
 40         m = Math.sqrt(100);
 41         
 42         System.out.print("x = ");
 43         System.out.println(x);
 44         System.out.print("y = ");
 45         System.out.println(y);
 46         System.out.print("z = ");
 47         System.out.println(z);
 48         System.out.print("m = ");
 49         System.out.println(m);
 50         System.out.print("n = ");
 51         System.out.println(n);
 52         System.out.print("word = ");
 53         System.out.println(word);
 54         
 55         System.out.println("====================");
 56         
 57         System.out.print("3 / 5 = ");
 58         System.out.println( 3/5 );
 59         System.out.print("3 % 5 = ");
 60         System.out.println( 3%5 );
 61         
 62         System.out.println();
 63         
 64         System.out.print("3.0 / 5 = ");
 65         System.out.println( 3.0 / 5);
 66         
 67         z = 1500/3;
 68         System.out.println(z + " * 3 = " + z*3);
 69         
 70         System.out.println();
 71         
 72         System.out.println("The average of " + x + " and "
 73                 + y + " is " + ( (x+y)/2 ));
 74         
 75     } // end of constructor
 76     
 77     
 78     @Override
 79     public void paintComponent(Graphics g) {
 80         super.paintComponent(g); // This line must be first in this method!
 81 
 82         // 3. Call methods of objects here:
 83 
 84                 
 85     } // end of paintComponent()
 86     
 87     
 88     
 89        
 90     
 91     
 92     
 93     /***********************************************
 94      * Do NOT change or delete anything below here!
 95      ***********************************************/
 96     public void setUp() {
 97         for (Component c: getComponents())
 98             c.setSize(c.getPreferredSize());
 99         JFrame f = new JFrame(getName());
100         f.setContentPane(this);
101         f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
102         f.pack();
103         f.setVisible(true);    
104     }
105 
106     public static void main(String args[]){new MUPanel();}
107 
108 } // end of class MUPanel
109