ArrayPractice1 - /* Chapter 8 Programming Activity 1 *...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
/* Chapter 8 Programming Activity 1 * ArrayPractice1 * Anderson, Franceschi */ import java.awt.*; import javax.swing.*; import java.awt.event.*; i public class ArrayPractice1 extends JFrame { // GUI components private JButton fillValues; private JButton printArray; private JButton setValues; private JButton countFrequency; private JButton findMinimum; private ButtonHandler bh; private static int [] arr; private final int SIZE = 15; private static int current = -1; private int key; private BarChart bc; private static int counter = 0; private static ArrayPractice1 app; private Image offscreen; public ArrayPractice1( ) { super( "Choose your activity" ); Container c = getContentPane( ); c.setLayout( new FlowLayout( ) ); fillValues = new JButton( "Fill Values" ); c.add( fillValues ); printArray = new JButton( "Print Array" ); c.add( printArray ); setValues = new JButton( "Set Values" ); c.add( setValues ); countFrequency = new JButton( "Count Frequency" ); c.add( countFrequency ); findMinimum = new JButton( "Find Minimum" ); c.add( findMinimum ); bh = new ButtonHandler( ); fillValues.addActionListener( bh ); printArray.addActionListener( bh ); setValues.addActionListener( bh ); countFrequency.addActionListener( bh ); findMinimum.addActionListener( bh ); setSize( 400, 250 ); arr = new int [SIZE]; // fill with random numbers between 50 and 80
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
for ( int i = 0; i < arr.length; i++ ) { arr[i] = ( int ) ( Math.random( ) * 31 ) + 50; } bc = new BarChart( arr ); // print the array values System.out.println( "Element\tValue" ); for ( int i = 0; i < arr.length; i++ ) { System.out.println(i + "\t" + arr[i]); } setVisible( true ); offscreen = this.createImage( getSize( ).width, getSize( ).height ); } // ***** 1. The first method has been coded as an example /** Fills the array with random numbers between 50 and 80. * The instance variable arr is the integer array * to be filled with values */ public void fillValues( ) { for ( int i = 0; i < arr.length; i++ ) { arr[i] = ( int ) ( Math.random( ) * 31 ) + 50; animate( -1 ); // needed to create visual feedback } } // end of fillValues method // ***** 2. student writes this method /** Prints the array to the console with elements separated * by a space * The instance variable arr is the integer array to be printed
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 09/10/2009 for the course CS 102 taught by Professor Kanipiakins during the Spring '09 term at University of Maryland Baltimore.

Page1 / 8

ArrayPractice1 - /* Chapter 8 Programming Activity 1 *...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online