Z:\Faculty\cindricbb\000work\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 import java.util.*;
 13 
 14 public class MUPanel extends JPanel {
 15 
 16     // 1. Declare private objects here:
 17     
 18     private Integer x, y, z;
 19     private Double m, n;
 20     private String word;
 21     
 22     private Scanner kbdInput;
 23 
 24     // constructor method
 25     public MUPanel() {
 26         setLayout(null);
 27         setPreferredSize(new Dimension(800, 100));
 28         setName("CSC 120 Lecture 9");
 29         setUp();
 30         setBackground(Color.WHITE);
 31         
 32         kbdInput = new Scanner(System.in);
 33 
 34         System.out.print("17 + 9 = ");
 35         System.out.println(17 + 9);
 36         System.out.print("32 - 18 = ");
 37         System.out.println(32 - 18);
 38         System.out.print("17 * 3 = ");
 39         System.out.println(17 * 3);
 40         System.out.print("5 / 3 = ");
 41         System.out.println(5 / 3);
 42         System.out.print("5 % 3 = ");
 43         System.out.println(5 % 3);
 44         System.out.println("--------------------");
 45         
 46         System.out.print("17.3 + 5 = ");
 47         System.out.println(17.3 + 5);
 48         System.out.print("1.3 + 1.7 = ");
 49         System.out.println(1.3 + 1.7);
 50         System.out.print("20 - 5.6 = ");
 51         System.out.println(20 - 5.6);
 52         System.out.print("1.1 * 8 = ");
 53         System.out.println(1.1 * 8);
 54         System.out.print("5.0 / 3 = ");
 55         System.out.println(5.0 / 3);
 56         System.out.println("--------------------");
 57 
 58 
 59         //x = 100;
 60         
 61         System.out.print("Enter an integer, please: ");
 62         x = kbdInput.nextInt();
 63         
 64         y = x + 2;
 65         z = x - 39;
 66         
 67         //m = 15.5;
 68         System.out.print("Enter a double value now: ");
 69         m = kbdInput.nextDouble();
 70         
 71         n = 2 * m;
 72         
 73         word = "Aardvark";
 74         
 75         
 76         
 77         System.out.println("x = " + x);
 78         System.out.println("y = " + y);
 79         System.out.println("z = " + z);
 80         System.out.println("m = " + m);
 81         System.out.println("n = " + n);
 82         System.out.println("word = " + word);
 83 
 84         
 85         x = 40;
 86         y = 50;
 87         z = 80;
 88         
 89         Double avg = (x + y + z) / 3.0;
 90         
 91         System.out.println();
 92         System.out.println("The average of " + x + ", " + y + " and "
 93                 + z + " = " + avg);
 94         
 95         
 96     } // end of constructor
 97     
 98     @Override
 99     public void paintComponent(Graphics g) {
100         super.paintComponent(g); // This line must be first in this method!
101 
102         // 3. Call methods of objects here:
103 
104         g.setFont( new Font("SansSerif", Font.PLAIN, 18));
105         g.drawString("Look in Java Console for answers", 100, 60);
106         
107                 
108                 
109     } // end of paintComponent()
110     
111     
112     
113        
114     
115     
116     
117     /***********************************************
118      * Do NOT change or delete anything below here!
119      ***********************************************/
120     public void setUp() {
121         for (Component c: getComponents())
122             c.setSize(c.getPreferredSize());
123         JFrame f = new JFrame(getName());
124         f.setContentPane(this);
125         f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
126         f.pack();
127         f.setVisible(true);    
128     }
129 
130     public static void main(String args[]){new MUPanel();}
131 
132 } // end of class MUPanel
133