Question: CREATE BOTH OF THE DIAGRAMS AND ADD THE CODE: Do some investigation into the Swing framework and write a short paragraph describing the purpose of

CREATE BOTH OF THE DIAGRAMS AND ADD THE CODE:
Do some investigation into the Swing framework and write a short paragraph describing the
purpose of the Swing framework. Submit a class diagram of the components of Swing.
Look through the example code in the GitHub repository and explain how this example
implements the MVC pattern. How does it differ from the conventional MVC pattern
described in the lectures?
In the repository there is another Java file that is named Scanner. This Class emulates the
scanning of a product by generating a UPC code. If you press on the Scan button you will see
that it prints out the "12345" code to the console. Consider now coding a "Cash Register"
application leveraging the Swing MVC model. Even though the Scanner Class appears like a
View you should consider it as a Controller creating UPC codes for the Cash register that
behaves as the model. The view in this case would simply output the name and the price of
the product which the cash register reads from a file with the following information.
Using the Swing MVC model create an implementation of the Cash Register so that when
the Scan button is pressed the product name and price will appear in the View. The TA
should be able to execute your main Java file and press the Scan button and see the result in
the UI view.
Create a sequence diagram of your design for the scenario presented in question 3.
import java.awt.BorderLayout;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
public class Scanner {
// Scanner uses Swing framework to create a UPC code
private JFrame frame;
private JPanel scannerPanel;
private JButton scanButton;
public Scanner(){
frame = new JFrame("Scanner");
frame.getContentPane().setLayout(new BorderLayout());
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(100,100);
frame.setLocation(300,50);
frame.setVisible(true); // Create UI elements
scanButton = new JButton("Scan");
scannerPanel = new JPanel();
// Add UI element to frame
scannerPanel.add(scanButton);
frame.getContentPane().add(scannerPanel);
scanButton.addActionListener(e -> generateUPC());
}
private int generateUPC(){
int upcCode =12345;
System.out.println(upcCode);
return upcCode;
}
public JFrame getFrame(){ return frame; }
public void setFrame(JFrame frame){ this.frame = frame; }
public JPanel getScannerPanel(){ return scannerPanel; }
public void setScannerPanel(JPanel scannerPanel)\ this.scannerPanel = scannerPanel; }
public JButton getScanButton(){ return scanButton; }
public void setScanButton(JButton scanButton){ this.scanButton = scanButton; }
}
CREATE BOTH OF THE DIAGRAMS AND ADD THE CODE: Do

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!