Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

1. Your main method will create an array of integers which can be either read-in or hard-coded. You will create DataModel , TextView , and

1. Your main method will create an array of integers which can be either read-in or hard-coded. You will create DataModel , TextView , and GraphView objects and register listeners and observers. Make two JFrame objects. In the first frame, set its content pane to the text view and pack it. In the second frame, set the content pane to the graph view. Use setBounds to move and set the graph frame to an appropriate size.

2. The Box class takes care of packing the JTextField components vertically. Just use the add method.

3. Each JTextField object should have an actionListener which will take the appro- priate action when the text value is changed.

4. The graph view should have a MouseListener which takes the appropriate action when the mouse is clicked. You can have empty methods for the other mouse actions.

5. The DataModel class will need to use the setChanged and notifyObservers methods inherited from the Observable class when a data value is changed.

6. Give each bar in the graph view a fixed height. I used private static final int HEIGHT = 20 Then when a user clicks on the point (x,y) , the graphical view can tell the model to set the data point with index y/HEIGHT to x. You can find out which point was clicked from the MouseEvent.

You must use the Observer interface and the Observable class as follows:

public class DataModel extends Observable

{

. . .

}

public class TextView extends Box implements Observer

{

public TextView(DataModel aModel)

{

super(BoxLayout.Y_AXIS);

. . .

} // TextView constructor

. . .

} // TextView class

1

public class GraphView extends JPanel implements Observer, MouseListener

{

public void paintComponent(Graphics g)

{

super.setBackground(Color.white);

super.paintComponent(g);

Graphics2D g2 = (Graphics2D)g;

. . .

}

. . .

}

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

More Books

Students also viewed these Databases questions

Question

please dont use chat gpt or other AI 1 9 5 . .

Answered: 1 week ago