Comp103 - Java


Random App


Authority.java

 /* Michael Beck
  * Lab 6 05/08/07
  */


import java.awt.*;
import javax.swing.*;
import java.text.DecimalFormat; // allows decimalformat to be used

public class Authority{ // Creates a few coloured panels displaying the value of pi 
  
  public static void main (String[] args){
    
    JFrame frame = new JFrame ("Authority"); // creates a new panel
    
    frame.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE);
    
    double pi;                                               //-------------------------
                                                             // formats the mathematical
    pi = Math.PI;                                            // constant 'pi' to 7 
                                                             // decimal places
    DecimalFormat fmt = new DecimalFormat ("0.#######");     //-------------------------
    
    JPanel secondary = new JPanel();       // makes a blue subpanel
    secondary.setBackground (Color.blue);
    secondary.setPreferredSize (new Dimension(250, 75));
    JLabel label1 = new JLabel ("The value of Pi is");
    secondary.add (label1);

    
    JPanel tertiary = new JPanel();        // makes an orange subpanel
    tertiary.setBackground (Color.orange);
    tertiary.setPreferredSize (new Dimension(250, 75));
    JLabel label2 = new JLabel ("" + fmt.format(pi));
    tertiary.add (label2);
    
    JPanel primary = new JPanel();             // makes a yellow panel on which 
    primary.setBackground (Color.yellow);      // the subpanels are displayed
    primary.setPreferredSize (new Dimension(250, 150));
    primary.add (secondary);
    primary.add (tertiary);
    
    
    frame.getContentPane().add(primary);  // displays the main panel
    frame.pack();
    frame.setVisible(true);
            
   } // end main
} // end class