Thread: Java programming assignment

Results 1 to 2 of 2
  1. #1 Java programming assignment 
    Registered Member

    Join Date
    Apr 2016
    Posts
    309
    Thanks given
    294
    Thanks received
    64
    Rep Power
    275
    Hey fellas, got this assignment due tonight at midnight. I couldn't manage to complete it and am really stuck. Workload is piling up so was not able to spend all of my time on this. Any help is appreciated.


    Create a graphic application that will display data from the classes that implemented TableMember and TableData.


    VERY IMPORTANT: This table implements the TableData interface. So, if you build one graphical panel for one table, and if the panel is modularized and parametrized, this panel is automatically ready to display any other table that implements TableData. This is because if one panel knows how to handle and display one TableData interface, it knows how to handle and display any class that implements the TableData interface.
    The graphics don't have to look exactly like that but the general structure should be like the schema below. You will use JLabels and/or JButtons for the basic units of display.

    All these classes belong to View.

    View creates the InitialPanel, the first and enclosing pane
    InitialPanel has one other panel (in future assignments it will have more panels)
    CenterPanel.java
    with a row of buttons with the headers from the table
    each attribute name in its own button
    the number of buttons depend on the size of the array returned by getHeaders( )
    with a row of buttons with the lines from the table
    each attribute value in its own button
    the number of lines depend on the value of the attribute linesBeingDisplayed

    Functionality
    There is a new class in this project, CenterPanel.Java

    CenterPanel
    it is the panel in charge of displaying the data
    it has a row of buttons or labels to display the headers. This row should be graphically distinct from the lines below it. This can be done by using labels, and/or by using a different background and/or a different font.
    it has also a number of lines to display the table data. These lines should be graphically distinct from the headers
    it needs a layout, most likely a GridLayout

    Displayable.java
    public int getFirstLineToDisplay();
    public void setFirstLineToDisplay(int firstLine);
    these first two methods are about an int attribute that will hold the number of the first line to be displayed. The number represents the index of an element in the array of the class that implements the TableData interface.
    public int getLineToHighlight();
    public void setLineToHighlight(int highlightedLine);
    the two methods above are about an int attribute that will hold the number of the line on the screen that should be highlighted. It will be used only in a later assignment but it is part of the interface and needs to be implemented even if it is not fully functional yet.
    public int getLastLineToDisplay();
    public void setLastLineToDisplay(int lastLine);
    these two methods are about an int attribute that will hold the number of the last line to be displayed. The number represents the index of an element in the array of the class that implements the TableData interface.
    public int getLinesBeingDisplayed();
    public void setLinesBeingDisplayed(int numberOfLines);
    these two methods are about an int attribute that will hold the number of the lines that will appear on the screen at one time. It will be most likely 20 but it should a variable. The application should work with any number of lines. So if this number is set to 10 or 15, this is the number of lines that should appear on the screen.

    FAQ - Frequently Asked Questions
    Updating Graphics
    If you make changes in the layout or add and remove one or many components at once, then you might force the Panel to be updated using the method validate().

    validate( ) recalculates the layout after some changes are made.

    You may also need to repaint().

    repaint( ) forces the screen to be refreshed.

    For instance,

    add(p1);
    add(p2);
    ...
    remove(p1);
    remove (p2);
    add(p3);
    add(p4);
    validate();
    repaint();

    Code:
     //SoccerData.java
    package Model;
    
    import java.beans.XMLDecoder;
    import java.io.BufferedInputStream;
    import java.io.FileInputStream;
    import java.util.ArrayList;
    
    import javax.swing.JButton;
    import javax.swing.JLabel;
    
    public class SoccerData extends SoccerPlayer implements TableData, Displayable {
    
        private ArrayList<SoccerPlayer> players;
        
    	/**
    	 * Represents an array of buttons
    	 */
    	private ArrayList<JButton> buttonArray;
    	
    	/**
    	 * Represents an array of labels
    	 */
    	private ArrayList<JLabel> labelArray;
    
        public SoccerData() {
            players = new ArrayList<>();
            loadTable();
        }
    
        public void readPlayersFromXML() {
            try {
                SoccerPlayer fp;
                XMLDecoder decoder;
                decoder = new XMLDecoder(new BufferedInputStream(new FileInputStream("FifaSoccer19.xml")));
                fp = new SoccerPlayer();
                while (fp != null) {
                    try {
                        fp = (SoccerPlayer) decoder.readObject();
                        players.add(fp);
                    } catch (ArrayIndexOutOfBoundsException theend) {
                        //System.out.println("end of file");
                        break;
                    }
                }
                decoder.close();
            } catch (Exception xx) {
                xx.printStackTrace();
            }
        }
    
        public ArrayList<SoccerPlayer> getPlayers() {
            return players;
        }
    
        public void setPlayers(ArrayList<SoccerPlayer> players) {
            this.players = players;
        }
    
        @Override
        public void loadTable() {
            this.readPlayersFromXML();
        }
    
        @Override
        public ArrayList<SoccerPlayer> getTable() {
            ArrayList<SoccerPlayer> table = new ArrayList<>();
            for (int i = 0; i < getPlayers().size(); i++) {
                table.add(players.get(i));
            }
            return table;
        }
    
        @Override
        public ArrayList<String> getHeaders() {
            ArrayList<String> headers = new ArrayList<>();
            for (int i = 0; i < 10; i++) {
                headers.add(getAttributeName(i));
            }
            return headers;
        }
    
        @Override
        public ArrayList<String> getLine(int line) {
            ArrayList<String> lines = new ArrayList<>();
            SoccerPlayer sp = players.get(line);
            for (int i = 0; i < 10; i++) {
                lines.add(sp.getAttribute(i));
            }
            return lines;
        }
    
        @Override
        public ArrayList<ArrayList<String>> getLines(int firstLine, int lastLine) {
            ArrayList<ArrayList<String>> multiLines = new ArrayList<>();
            for (int i = firstLine; i <= lastLine; i++) {
                multiLines.add(getLine(i));
    
            }
            return multiLines;
        }
    
    	/* (non-Javadoc)
    	 * @see Model.Displayable#getFirstLineToDisplay()
    	 */
    	@Override
    	public int getFirstLineToDisplay() {
    		return getLine(0).size();
    	}
    
    	/* (non-Javadoc)
    	 * @see Model.Displayable#getLineToHighlight()
    	 */
    	@Override
    	public int getLineToHighlight() {
    		// TODO Auto-generated method stub
    		return 0;
    	}
    
    	/* (non-Javadoc)
    	 * @see Model.Displayable#getLastLineToDisplay()
    	 */
    	@Override
    	public int getLastLineToDisplay() {
    		return getLine(10).size();
    	}
    
    	/* (non-Javadoc)
    	 * @see Model.Displayable#getLinesBeingDisplayed()
    	 */
    	@Override
    	public int getLinesBeingDisplayed() {
    		// TODO Auto-generated method stub
    		return 0;
    	}
    
    	/* (non-Javadoc)
    	 * @see Model.Displayable#setFirstLineToDisplay(int)
    	 */
    	@Override
    	public void setFirstLineToDisplay(int firstLine) {
    		// TODO Auto-generated method stub
    		
    	}
    
    	/* (non-Javadoc)
    	 * @see Model.Displayable#setLineToHighlight(int)
    	 */
    	@Override
    	public void setLineToHighlight(int highlightedLine) {
    		// TODO Auto-generated method stub
    		
    	}
    
    	/* (non-Javadoc)
    	 * @see Model.Displayable#setLastLineToDisplay(int)
    	 */
    	@Override
    	public void setLastLineToDisplay(int lastLine) {
    		// TODO Auto-generated method stub
    		
    	}
    
    	/* (non-Javadoc)
    	 * @see Model.Displayable#setLinesBeingDisplayed(int)
    	 */
    	@Override
    	public void setLinesBeingDisplayed(int numberOfLines) {
    		// TODO Auto-generated method stub
    		
    	}
    
    }
    Code:
    //Displayable.java
    package Model;
    
    
    public interface Displayable {
    	
    	public int getFirstLineToDisplay();
    
    	public int getLineToHighlight();
    
    	public int getLastLineToDisplay();
    
    	public int getLinesBeingDisplayed();
    
    	public void setFirstLineToDisplay(int firstLine);
    
    	public void setLineToHighlight(int highlightedLine);
    
    	public void setLastLineToDisplay(int lastLine);
    
    	public void setLinesBeingDisplayed(int numberOfLines);
    
    }
    Code:
    //Controller.java
    package Controller;
    
    import java.awt.GridLayout;
    import java.util.ArrayList;
    
    import javax.swing.*;
    
    import Model.Model;
    import View.View;
    
    /**
    
     *
     * @Since Oct 27, 2019
     */
    public class Controller {
    	
    	/**
    	 * Represents the model
    	 */
    	private Model model;
    	
    	/**
    	 * Represents the view
    	 */
    	private View view;
    	
    	public Controller(Model model, View view) {
    		this.model = model;
    		this.view = view;
    		
    		view.getInitialframe().setLayout(new GridLayout(10, 10));
    		
    		view.getInitialframe().add(new JButton(model.getScData().getLines(0, 10).toString()));
    		view.getInitialframe().add(new JLabel(model.getScData().getLines(0, 10).toString()));
    		
    	//	view.CenterInitialSetup(model.getScData().getLinesBeingDisplayed(), model.getFpData().getHeaders().size());
    		//  view.CenterUpdate(model.getScData().getLines(model.getScData().getFirstLineToDisplay(), 
    		   //           model.getScData().getLastLineToDisplay()), model.getScData().getHeaders());
    		
    		model.getScData().setFirstLineToDisplay(0);
    		model.getScData().setLinesBeingDisplayed(10);
    
    		
    	}
    }
    Reply With Quote  
     

  2. #2  
    Donator
    Tojad's Avatar
    Join Date
    Oct 2010
    Posts
    141
    Thanks given
    0
    Thanks received
    8
    Rep Power
    0
    Quote Originally Posted by Trickk View Post
    Hey fellas, got this assignment due tonight at midnight. I couldn't manage to complete it and am really stuck. Workload is piling up so was not able to spend all of my time on this. Any help is appreciated.


    Create a graphic application that will display data from the classes that implemented TableMember and TableData.


    VERY IMPORTANT: This table implements the TableData interface. So, if you build one graphical panel for one table, and if the panel is modularized and parametrized, this panel is automatically ready to display any other table that implements TableData. This is because if one panel knows how to handle and display one TableData interface, it knows how to handle and display any class that implements the TableData interface.
    The graphics don't have to look exactly like that but the general structure should be like the schema below. You will use JLabels and/or JButtons for the basic units of display.

    All these classes belong to View.

    View creates the InitialPanel, the first and enclosing pane
    InitialPanel has one other panel (in future assignments it will have more panels)
    CenterPanel.java
    with a row of buttons with the headers from the table
    each attribute name in its own button
    the number of buttons depend on the size of the array returned by getHeaders( )
    with a row of buttons with the lines from the table
    each attribute value in its own button
    the number of lines depend on the value of the attribute linesBeingDisplayed

    Functionality
    There is a new class in this project, CenterPanel.Java

    CenterPanel
    it is the panel in charge of displaying the data
    it has a row of buttons or labels to display the headers. This row should be graphically distinct from the lines below it. This can be done by using labels, and/or by using a different background and/or a different font.
    it has also a number of lines to display the table data. These lines should be graphically distinct from the headers
    it needs a layout, most likely a GridLayout

    Displayable.java
    public int getFirstLineToDisplay();
    public void setFirstLineToDisplay(int firstLine);
    these first two methods are about an int attribute that will hold the number of the first line to be displayed. The number represents the index of an element in the array of the class that implements the TableData interface.
    public int getLineToHighlight();
    public void setLineToHighlight(int highlightedLine);
    the two methods above are about an int attribute that will hold the number of the line on the screen that should be highlighted. It will be used only in a later assignment but it is part of the interface and needs to be implemented even if it is not fully functional yet.
    public int getLastLineToDisplay();
    public void setLastLineToDisplay(int lastLine);
    these two methods are about an int attribute that will hold the number of the last line to be displayed. The number represents the index of an element in the array of the class that implements the TableData interface.
    public int getLinesBeingDisplayed();
    public void setLinesBeingDisplayed(int numberOfLines);
    these two methods are about an int attribute that will hold the number of the lines that will appear on the screen at one time. It will be most likely 20 but it should a variable. The application should work with any number of lines. So if this number is set to 10 or 15, this is the number of lines that should appear on the screen.

    FAQ - Frequently Asked Questions
    Updating Graphics
    If you make changes in the layout or add and remove one or many components at once, then you might force the Panel to be updated using the method validate().

    validate( ) recalculates the layout after some changes are made.

    You may also need to repaint().

    repaint( ) forces the screen to be refreshed.

    For instance,

    add(p1);
    add(p2);
    ...
    remove(p1);
    remove (p2);
    add(p3);
    add(p4);
    validate();
    repaint();

    Code:
     //SoccerData.java
    package Model;
    
    import java.beans.XMLDecoder;
    import java.io.BufferedInputStream;
    import java.io.FileInputStream;
    import java.util.ArrayList;
    
    import javax.swing.JButton;
    import javax.swing.JLabel;
    
    public class SoccerData extends SoccerPlayer implements TableData, Displayable {
    
        private ArrayList<SoccerPlayer> players;
        
    	/**
    	 * Represents an array of buttons
    	 */
    	private ArrayList<JButton> buttonArray;
    	
    	/**
    	 * Represents an array of labels
    	 */
    	private ArrayList<JLabel> labelArray;
    
        public SoccerData() {
            players = new ArrayList<>();
            loadTable();
        }
    
        public void readPlayersFromXML() {
            try {
                SoccerPlayer fp;
                XMLDecoder decoder;
                decoder = new XMLDecoder(new BufferedInputStream(new FileInputStream("FifaSoccer19.xml")));
                fp = new SoccerPlayer();
                while (fp != null) {
                    try {
                        fp = (SoccerPlayer) decoder.readObject();
                        players.add(fp);
                    } catch (ArrayIndexOutOfBoundsException theend) {
                        //System.out.println("end of file");
                        break;
                    }
                }
                decoder.close();
            } catch (Exception xx) {
                xx.printStackTrace();
            }
        }
    
        public ArrayList<SoccerPlayer> getPlayers() {
            return players;
        }
    
        public void setPlayers(ArrayList<SoccerPlayer> players) {
            this.players = players;
        }
    
        @Override
        public void loadTable() {
            this.readPlayersFromXML();
        }
    
        @Override
        public ArrayList<SoccerPlayer> getTable() {
            ArrayList<SoccerPlayer> table = new ArrayList<>();
            for (int i = 0; i < getPlayers().size(); i++) {
                table.add(players.get(i));
            }
            return table;
        }
    
        @Override
        public ArrayList<String> getHeaders() {
            ArrayList<String> headers = new ArrayList<>();
            for (int i = 0; i < 10; i++) {
                headers.add(getAttributeName(i));
            }
            return headers;
        }
    
        @Override
        public ArrayList<String> getLine(int line) {
            ArrayList<String> lines = new ArrayList<>();
            SoccerPlayer sp = players.get(line);
            for (int i = 0; i < 10; i++) {
                lines.add(sp.getAttribute(i));
            }
            return lines;
        }
    
        @Override
        public ArrayList<ArrayList<String>> getLines(int firstLine, int lastLine) {
            ArrayList<ArrayList<String>> multiLines = new ArrayList<>();
            for (int i = firstLine; i <= lastLine; i++) {
                multiLines.add(getLine(i));
    
            }
            return multiLines;
        }
    
    	/* (non-Javadoc)
    	 * @see Model.Displayable#getFirstLineToDisplay()
    	 */
    	@Override
    	public int getFirstLineToDisplay() {
    		return getLine(0).size();
    	}
    
    	/* (non-Javadoc)
    	 * @see Model.Displayable#getLineToHighlight()
    	 */
    	@Override
    	public int getLineToHighlight() {
    		// TODO Auto-generated method stub
    		return 0;
    	}
    
    	/* (non-Javadoc)
    	 * @see Model.Displayable#getLastLineToDisplay()
    	 */
    	@Override
    	public int getLastLineToDisplay() {
    		return getLine(10).size();
    	}
    
    	/* (non-Javadoc)
    	 * @see Model.Displayable#getLinesBeingDisplayed()
    	 */
    	@Override
    	public int getLinesBeingDisplayed() {
    		// TODO Auto-generated method stub
    		return 0;
    	}
    
    	/* (non-Javadoc)
    	 * @see Model.Displayable#setFirstLineToDisplay(int)
    	 */
    	@Override
    	public void setFirstLineToDisplay(int firstLine) {
    		// TODO Auto-generated method stub
    		
    	}
    
    	/* (non-Javadoc)
    	 * @see Model.Displayable#setLineToHighlight(int)
    	 */
    	@Override
    	public void setLineToHighlight(int highlightedLine) {
    		// TODO Auto-generated method stub
    		
    	}
    
    	/* (non-Javadoc)
    	 * @see Model.Displayable#setLastLineToDisplay(int)
    	 */
    	@Override
    	public void setLastLineToDisplay(int lastLine) {
    		// TODO Auto-generated method stub
    		
    	}
    
    	/* (non-Javadoc)
    	 * @see Model.Displayable#setLinesBeingDisplayed(int)
    	 */
    	@Override
    	public void setLinesBeingDisplayed(int numberOfLines) {
    		// TODO Auto-generated method stub
    		
    	}
    
    }
    Code:
    //Displayable.java
    package Model;
    
    
    public interface Displayable {
    	
    	public int getFirstLineToDisplay();
    
    	public int getLineToHighlight();
    
    	public int getLastLineToDisplay();
    
    	public int getLinesBeingDisplayed();
    
    	public void setFirstLineToDisplay(int firstLine);
    
    	public void setLineToHighlight(int highlightedLine);
    
    	public void setLastLineToDisplay(int lastLine);
    
    	public void setLinesBeingDisplayed(int numberOfLines);
    
    }
    Code:
    //Controller.java
    package Controller;
    
    import java.awt.GridLayout;
    import java.util.ArrayList;
    
    import javax.swing.*;
    
    import Model.Model;
    import View.View;
    
    /**
    
     *
     * @Since Oct 27, 2019
     */
    public class Controller {
    	
    	/**
    	 * Represents the model
    	 */
    	private Model model;
    	
    	/**
    	 * Represents the view
    	 */
    	private View view;
    	
    	public Controller(Model model, View view) {
    		this.model = model;
    		this.view = view;
    		
    		view.getInitialframe().setLayout(new GridLayout(10, 10));
    		
    		view.getInitialframe().add(new JButton(model.getScData().getLines(0, 10).toString()));
    		view.getInitialframe().add(new JLabel(model.getScData().getLines(0, 10).toString()));
    		
    	//	view.CenterInitialSetup(model.getScData().getLinesBeingDisplayed(), model.getFpData().getHeaders().size());
    		//  view.CenterUpdate(model.getScData().getLines(model.getScData().getFirstLineToDisplay(), 
    		   //           model.getScData().getLastLineToDisplay()), model.getScData().getHeaders());
    		
    		model.getScData().setFirstLineToDisplay(0);
    		model.getScData().setLinesBeingDisplayed(10);
    
    		
    	}
    }
    Point out the question tldr; lollllll
    Attached image
    Reply With Quote  
     


Thread Information
Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)


User Tag List

Similar Threads

  1. Java Program Assignment
    By Schuba in forum Buying
    Replies: 3
    Last Post: 03-05-2017, 10:30 PM
  2. CIS-2 Java Programming Assignment 3
    By VeRoCo in forum Application Development
    Replies: 16
    Last Post: 12-04-2010, 02:09 AM
  3. [PROPER] Best Java Programer
    By Alex in forum Voting
    Replies: 60
    Last Post: 06-21-2008, 06:52 PM
  4. Helpful server hadnlers & .java programs
    By pureowner in forum Tutorials
    Replies: 7
    Last Post: 01-10-2008, 01:10 PM
  5. Fundamentals of 3D Java Programming
    By Fallen Azn SinZ in forum Tutorials
    Replies: 21
    Last Post: 01-05-2008, 07:47 AM
Posting Permissions
  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •