Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

JAVA GUI Step 1: Getting started You are expected to do your own class design for this assignment, but there are some fairly obvious parts

JAVA GUI

Step 1: Getting started You are expected to do your own class design for this assignment, but there are some fairly obvious parts to the design: Firstly, its a GUI application with one window, so youll need a JFrame. In all our GUI applications in the lectures, we have extended that JFrame by a dedicated subclass for the application. So youll probably want to do the same here. The Swing components are all associated with the JFrame, so youll need to import the associated packages, configure the components and add them to the JFrame either directly or via their respective parent. The ListOWords and Album applications from the lectures are good examples for how to do this. Dont forget to configure the ButtonGroup to link your radio buttons! One exception is the JPanel that shows the coordinate system with the graph. As youll want to use this with the AWT graphics, its best to extend JPanel, so a more specialised subclass can take care of the drawing. Start by placing all components visibly within the JFrame you may wish to set the JPanel background colours to something a bit different so you can see where in the JFrame they end up being positioned. Remember that a larger vertical position value puts the component further down in the frame. Suggested values that work for me (but arent compulsory): ? The JFrame has size 1000 by 500. ? Ive put the JPanel with the radio buttons at position 0,0 (upper left corner of the JFrames content pane) and made it 200 wide and 100 tall. ? The JPanel subclass with the graph is at 0,100 and is 1000 wide by 325 tall. ? The coordinate system is 900 wide and 250 tall, and the ticks have length 5. Labels are positioned based on their lower left corner. The labels on the x-axis in my sample application have a horizontal position 10 less than the tick and a vertical position 20 larger than the axis. On the y-axis, the labels sit 40 to the left of the axis and 5 below the ticks. You can earn a total of 40 marks in this step: ? JFrame subclass correctly started via a class implementing Runnable & using invokeLater(): 2 marks ? Menu bar present, showing a File menu with the two required items: 4 marks. ? Menu item Quit quits the application and Menu item Open trace file opens a JFileChooser: 4 marks ? The two radio buttons are visible: 4 marks ? The radio buttons are mutually exclusive and one is selected by default: 4 marks ? The JPanel (subclass) for the graph is visible and shows a default coordinate system: 8 marks ? The coordinate system has between 8 and 24 ticks on the x-axis: 8 marks ? The ticks are labelled in intervals of 1, 2, 5, 10, 20, 50, or 100: 4 marks ? The axes are labelled with Volume [bytes] and Time [s] respectively: 2 marks In order to get the marks for positioning, no components or labels must touch each other or overlap with other components or parts the coordinate system (i.e., the JFrame and its contents must look neat and tidy).

Step 2: Design your classes Beyond the JFrame subclass and the JPanel subclass, this is really up to you. You could use classes for the trace file, the hosts (even source or destination hosts), lines, packets, graph elements you decide where you want to have your data and where you want to accommodate your functionality. You need to design and use at least two extra classes, but you will probably want more than that. There are no marks in this step, but it is a precursor to Step ###, which you should complete at the end once your design is final and you have implemented as much of it as you could.

Step 3: Extract the source and destination hosts from the trace file First ensure that the combo box is invisible before you open the first trace file. Using the trace file selected by the JFileChooser, parse the file to extract the source and destination hosts. Check which radio button is active and show the respective set of hosts selected in the combo box. Hint: There are a few a little catches here: 1) Splitting lines can be done with the split() method of the String class, which takes a regular expression as its parameter. 2) The lists must not contain duplicates, so you cant simply add each lines host entry to an ArrayList and then load that ArrayList into the JComboBox. Instead, Java has a data structure quite similar to an ArrayList that doesnt allow duplicates: the HashSet class. It implements the Set interface, and for Strings, you can use it as follows: import java.util.Set; import java.util.HashSet; Set myUniqueStrings = new HashSet(); myUniqueStrings.add(aStringWeMayOrMayNotHaveSeenBefore); If aStringWeMayOrMayNotHaveSeenBefore is not yet in the hash set myUniqueStrings, it will be added. If the string is already in the set, the add() method does nothing. 3) The lists must only contain IP addresses of IP version 4 (IPv4). Some packets in the trace file are not IP packets and the entries for source and destination in the respective lines will be empty. You must skip these packets. Think regular expressions, perhaps. 4) The lists in the combo box must be sorted. To do this, you need to figure out how to sort IP addresses in Java. This can be done in a number of ways. I use Collections.sort() and store the IP addresses in a class that has an appropriate compareTo() method. Google is your friend! Once you have accomplished this, ensure that the combo box updates every time you click the other radio button and every time you open a new trace file. For this, you need to: ? Implement and add the necessary event handlers for the radio button. ? Implement the code required to (where applicable) fetch the list of hosts (should you generate these lists once when you load the file, or each time the radio buttons change?). ? Implement the code required to wipe and re-populate the combo box. Look to the Album example from the lectures for a guide here. Ensure that you get the correct list of hosts in the combo box each time. You can earn a total of 34 marks in this step: ? The combo box is invisible before the trace file is selected and opened: 2 marks ? The application shows some evidence of a trace file being opened and its contents being processed after one selects a file with the JFileChooser (e.g., plot appearing, combo box getting populated with sensible data): 8 marks ? The combo box becomes visible at this point in time: 2 marks ? The combo box contains a list of IP addresses: 5 marks ? The list contains the selected type of host addresses (192.168.0.x if source hosts are selected, 10.0.x.x for destination hosts): 4 marks ? The list does not contain duplicates: 5 marks ? The list is sorted correctly: 4 marks ? The list updates correctly when the selected radio button is chosen: 2 marks ? The list updates correctly when we open a new trace file: 2 marks

Step 4: Compute and plot the data Implement the necessary code to: ? Compute the total number of bytes that the selected source/destination host sent/received for each 2 second interval (or 1 second interval if you wish). For 2 second intervals, you should be getting the same plots as in the video. ? Compute the maximum number of bytes across all of these intervals. ? Re-draw the coordinate system with appropriate ticks and labels for the whole duration of the experiment. Appropriate means that the horizontal axis must be scaled to cover the time period of the experiment within at least one tick, that the vertical axis must be scaled so its maximum must be at most one tick above the maximum number of bytes, and that the number and format of the ticks on each axis must conform to the requirements of Step 1. The vertical axis should have between about 4 and 10 ticks again the appropriate maximum number here depends on the requirement that the labels should not touch or overlap. ? Plot the bytes data from the first bullet point in a different colour, either as a bar plot (as in the video), as a curve with lines, or as a series of markers. ? Ensure that the plot updates each time you select a new host, change between source and destination hosts, and open a new trace file. You can earn a total of 36 marks in this step: ? The application shows a data plot of sorts: 8 marks ? The data plot is actually correct (shape-wise) and corresponds to the host selected: 8 marks ? The x-axis scales correctly: 3 marks ? The x-axis has an acceptable number of ticks (8 24): 4 marks ? The x-axis is labelled correctly: 4 marks ? The y-axis scales correctly: 3 marks ? The y-axis has an acceptable number of ticks (4 10): 2 marks ? The y-axis is labelled correctly: 4 marks

Step 5: Document your classes Document your design. The documentation must consist of two parts: 1) A UML-style class diagram, which must contain all of the classes you designed (except the class implementing Runnable), including your JFrame and JPanel subclasses. The diagram must show any subclasssuperclass relationships (is-a) as arrows, and any has a (with multiplicity such as 1 or 0..* or 1..*) as lines. Each class must show its public non-inherited methods and fields. 2) Javadoc style comments for each public non-inherited method in your code (except for event handlers in anonymous classes). See Writing Doc Comments under http://www.oracle.com/technetwork/java/javase/tech/index-137868.html Your comments only need a description of what the method does and the @param and @return block tags. You can earn a total of 10 marks in this step: ? UML class diagram: 5 marks minus one mark for each un-/incorrectly documented class or relationship. ? Javadoc comments: 5 marks minus one mark for each un-/incorrectly documented method

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Real Time Database And Information Systems Research Advances

Authors: Azer Bestavros ,Victor Fay-Wolfe

1st Edition

1461377803, 978-1461377801

More Books

Students also viewed these Databases questions

Question

f. Did they change their names? For what reasons?

Answered: 1 week ago