Java GUI problem

Ok, I've corrected the application for the most part. I still have one error. 
The application has an array of apartments, and it asks a user how many 
occupance in each apartment when the store button is pressed. The quit button 
is suppose to display the apartment's statistics, that is how many occupance in 
the building, the average number of occupance in the building, the number of 
apartments with above average occupance, and the number of apartments with 
below average occupance. The 1 error I'm getting is in my ButtonHandler1 class. 
I'm not sure how to correct it. Here is the code for class ButtonHandler1.

import java.awt.event.*;

import javax.swing.*;

public class ButtonHandler1 implements ActionListener

{

public void actionPerformed(ActionEvent event)

{

do

{

GuiApartment.index = 0

GuiApartment.apartment_occupance = 
GuiApartment.apartment_size[GuiApartment.index];

GuiApartment.index++; 

}

while (GuiApartment.index <= GuiApartment.apartment_size.length - 1);

GuiApartment.occupance = GuiApartment.occupance + 
(GuiApartment.apartment_occupance);

GuiApartment.userPane.add(GuiApartment.occupance);

GuiApartment.apartment_average = GuiApartment.apartment_occupance / 
GuiApartment.apartment_size.length;

GuiApartment.average = GuiApartment.average + GuiApartment.apartment_average;

GuiApartment.userPane.add(GuiApartment.average);

do

{

GuiApartment.index = GuiApartment.apartment_size.length - 1; 

GuiApartment.above_average = 0;

if (GuiApartment.apartment_size[GuiApartment.index] > GuiApartment.average_size)

GuiApartment.above_average++;

GuiApartment.index--;

}

while (GuiApartment.apartment_size[GuiApartment.index] > 
GuiApartment.average_size);

GuiApartment.aboveAverage = GuiApartment.aboveAverage + 
GuiApartment.above_average;

GuiApartment.userPane.add(GuiApartment.aboveAverage);

do

{

GuiApartment.index = 0;

GuiApartment.below_average = 0;

if (GuiApartment.apartment_size[GuiApartment.index] < GuiApartment.average_size)

GuiApartment.below_average++;

GuiApartment.index++;

}

while (GuiApartment.apartment_size[GuiApartment.index] < 
GuiApartment.average_size);

GuiApartment.belowAverage = GuiApartment.belowAverage + 
GuiApartment.below_average;

GuiApartment.userPane.add(GuiApartment.belowAverage);

GuiApartment.userPane.remove(quit);

GuiApartment.userFrame.setVisible(true);

}

} // End of ButtonHandler1



Here is the code for class ButtonHandler.



import java.awt.event.*;

import javax.swing.*;

public class ButtonHandler implements ActionListener

{

public void actionPerformed(ActionEvent event)

{

GuiApartment.apartment_size[GuiApartment.index] = 
Integer.parseInt(GuiApartment.inputField); 

}

}



Here is the code for GuiApartment which is the driver class.



import java.awt.*;

import java.awt.event.*;

import javax.swing.*;

public class GuiApartment

{

// Field declarations

static int apartment_occupance = 0; // Number of occupance in apartment

// declare and instantiate array of apartments

static int apartment_size[] = new int[10]; 

static int index = 0; // Index of array

static int average_size = 0; // Average occupance in building

static int above_average = 0; // Number of apartments with above average 
occupance

static int below_average = 0; // Number of apartments with below average 
occupance

// Declare labels and text field

static JLabel head1 = new JLabel("Prompt", JLabel.CENTER);

static JLabel head2 = new JLabel("Input field", JLabel.CENTER);

static JLabel head3 = new JLabel("Occupance in apartment", JLabel.CENTER);

static JLabel occupance = new JLabel("Number of people in the building is: ", 
JLabel.LEFT);

static JLabel average = new JLabel("Average number of people in building is: ", 
JLabel.LEFT); 

static JLabel aboveAverage = new JLabel("Number of apartments with above 
average number of occupance is: ", JLabel.LEFT);

static JLabel belowAverage = new JLabel("Number of apartments with below 
average number of occupance is: ", JLabel.LEFT);

static JTextField inputField = new JTextField(2);


// Declare buttons

static JButton store = new JButton("Store");

static JButton quit = new JButton("Quit");

public static void main(String[] args)

{

JFrame userFrame = new JFrame();

userFrame.setSize(200, 100);

userFrame.setLocation(100, 200);

Container userPane = userFrame.getContentPane();

userPane.setLayout(new GridLayout(7, 2));

userPane.add(head1);

userPane.add(head2);

do

{

index = 0;

userPane.add(head3);

userPane.add(inputField);

store.addActionListener(new ButtonHandler()); 

userPane.add(store); 

index++;

}

while (index <= apartment_size.length - 1);

quit.addActionListener(new ButtonHandler1());

userPane.add(quit);

}

}



Here is the error I get when compiling.



C:\Users\user\Desktop\COMP268\Practice\GuiApartment\src>javac *.java
ButtonHandler1.java:11: ';' expected
GuiApartment.apartment_occupance = GuiApartment.apartment_size[G
uiApartment.index];
^
1 error
C:\Users\user\Desktop\COMP268\Practice\GuiApartment\src>



What am I doing wrong. There are cemi-colons on all my statements.



Gilbert Neiva


Other related posts: