Hello, i have to design and implement an application that helps a museum analyze the flow of visitors for an exhibition that lasts for 3 weeks.(The museum is opened 7 days a week for 4 hours)...well getting to the point. I need to store this information in a 3d array called Visitors, and then have 3 push buttons(week, day, and hour) draw rectangles (of different heights) representing weekly, dayly, and hourly flows. The data is imported from a text file, and i'm pretty sure I did this correctly, but drawing the rectangles is where i'm stuck.

So far, i have a MainClass (with main method...sets up the frame), a MuseumArray class which sets up the 3D array, a MuseumPanel class (which has the paintComponent method to draw the rectangles), and a Box class which represents an individual rectangle to be drawn. Im pretty positive my program design is correct, but my drawWeekData method in my MuseumPanel class is where i'm receiving errors.

Heres my code so far:

import javax.swing.*;
import java.awt.*;
import java.util.Scanner;
import java.io.*;
import javax.swing.JFrame;

public class MainClass
{
    public static void main (String[] args) throws FileNotFoundException
    {
        JFrame frame = new JFrame ("Flow Of Visitors Into Museum");
        frame.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE);
        
        frame.getContentPane().add(new MuseumPanel());
        
        frame.pack();
        frame.setVisible(true);
    }    
}


import java.util.*;
import javax.swing.*;
import java.awt.*;
import java.util.Scanner;
import java.io.*;

public class MuseumArray
{
    private final int WEEK = 3;
    private final int DAY = 7;
    private final int HOUR = 4;
    private int[][][] visitors = new int[WEEK][DAY][HOUR];
    private int[] totalWeeks;
    
    public MuseumArray() throws FileNotFoundException
    {
        Scanner scan = new Scanner(new File("museumData.txt"));
        
        for(int w = 0; w < 3; w++)
        {
            for(int d = 0; d < 7; d++)
            {
                for(int h = 0; h < 4; h++)
                {
                    visitors [w][d][h] = scan.nextInt();
                }
            }
        }   
    }
    
    //Methods:
    
    public int[] getWeekVisitors ( int n)
    {
       totalWeeks = new int[1];
  
       for(int t = n-1; t < n; t++)
           for(int j = 0; j < DAY; j++)
               for(int k=0; k < HOUR; k++)
               totalWeeks[t] += visitors[t][j][k];

               return totalWeeks; 
        
    }
    
}


import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.util.*;

public class MuseumPanel extends JPanel
{
    private JLabel label;
    private JPanel buttonPanel;
    private JButton week, day, hour, output;
    private int typeA;
    private MuseumArray museumArray;
    private Box[] weekBoxes = new Box[3];
    

    public MuseumPanel()
    {
        week = new JButton ("Week");
        day = new JButton ("Day");
        hour = new JButton ("Hour");
        output = new JButton ("Output");
        
        ButtonListener listener = new ButtonListener();
        week.addActionListener (listener);
        day.addActionListener (listener);
        hour.addActionListener (listener);
        output.addActionListener (listener);
        
        label = new JLabel ("Push a button");
        
        buttonPanel = new JPanel();
        buttonPanel.setPreferredSize (new Dimension(800,40));
        buttonPanel.setBackground (Color.blue);
        buttonPanel.add (week);
        buttonPanel.add (day);
        buttonPanel.add (hour);
        buttonPanel.add (output);
        
        setPreferredSize (new Dimension(800,500));
        setBackground (Color.cyan);
        add (label);
        add (buttonPanel); 
    }
    
     public void paintComponent (Graphics page)
    {
        super.paintComponent(page);
        
        if (typeA == 1)
        drawWeekData(page);
    }
    
    public void drawWeekData (Graphics page)
    {
        int xx=10;
        int wWidth = 40;
        int[] weekArray = new int[3];
    
        for(int count=1;count<4;count++)
        {
            weekArray = museumArray.getWeekVisitors(count);
            weekBoxes[count] = new Box(xx, wWidth, weekArray);
            weekBoxes[count].draw(page);
            xx = xx + (wWidth + 10);   
        }
        
    }

    private class ButtonListener implements ActionListener
    {
        public void actionPerformed (ActionEvent event)
        {
            if (event.getSource() == week)
            {
                typeA = 1;
            }
            else if (event.getSource() == day)
            {
                typeA = 2;
                repaint();
            }    
            else if (event.getSource() == hour)
            {
                typeA = 3;
                repaint();
            }
            else
            {
                typeA = 4;
                repaint();
            }
        }
    }
}


import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class Box
{
    private int x, width, height;

    public Box(int boxX, int boxWidth, int boxHeight)
    {
        x = boxX;
        width = boxWidth;
        height = boxHeight;
    }
    
   public void draw (Graphics page)
   {
      page.setColor (Color.yellow);
      page.fillRect (x, 420 - height, width, height);
   }
}

The only class that does not compile is my MuseumPanel class. and yeah, i know have done nothing to draw the hour and day rectangles yet, but i figure if i can get the week part of it done, the hour and day will come easy. When i try to compile my MuseumPanel, i keep receiving "cannot find symbol - constructor Box(int, int, int[]) and it;s referring to the line of code "weekBoxes[count] = new Box(xx, wWidth, weekArray);". Since class Box has (int,int,int). However, i am not sure how else i can do this task. Any help would be greatly appreciated!

Like the error message says, you're trying to call a method that takes int,int,int but you're passing int,int,int[]. So either re-declare the method as taking an int[] as one of the parameters, or call the existing method correctly.

Hey, thanks for your advice. I was able to complete my tasking easier by eliminating the box class doing calling drawRect statements directly in my paintComponent instead though.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.