Skip to main content
edited tags; edited title
Link
200_success
  • 144.8k
  • 22
  • 190
  • 476

MVC - CSV File Reader Project

edited title
Link
Grim
  • 163
  • 1
  • 8

MVC Architecture- CSV File Reader Project

Post Reopened by Jamal
added 26 characters in body
Jamal
  • 35k
  • 13
  • 134
  • 237

TryingI'm trying to focus on learning so I can get an entry level position and the best way for me to learn right now is to have someone review and provide areas of improvement. This project isn't entirely complete but almost. I am going to include the code for some of the classes but not all of them. Just a few button actions left to finish. All criticism is welcomed.

The MainPanelMainPanel Class which basically creates the main JPanelJPanel for the JFrameJFrame. This JPanelJPanel has two child panels and one menu bar.

The KeywordPanel ClassKeywordPanel class which is one of the panels for JDialogJDialog. This panel is added dynamically to a dialog based on a specific action taken by the user. public class KeywordPanel {

public class KeywordPanel {  private CSVFileController controller; private Product product; private Dialog dialog; private JPanel keywordPanel; private JTextField[] textFields; private JLabel searchLbl; private JButton close, remove; public KeywordPanel(CSVFileController controller, Dialog dialog, Product product) { this.controller = controller; this.product = product; this.dialog = dialog; createKeywordPanel(); } public void createKeywordPanel() { keywordPanel = new JPanel(new MigLayout()); searchLbl = new JLabel("KeyWords"); searchLbl.setFont(CreateAndShowUI.getFont()); keywordPanel.add(searchLbl, "wrap"); textFields = new JTextField[] { new JTextField(""), new JTextField(""), new JTextField(""), new JTextField(""), new JTextField("") }; for (JTextField textField : textFields) { textField.setFont(CreateAndShowUI.getFont()); textField.setPreferredSize(new Dimension(242, 30)); keywordPanel.add(textField, "wrap"); } remove = new JButton(new KeywordPanelController.RemoveAction("Remove", controller, product)); remove.setBackground(CreateAndShowUI.getButtonColor()); remove.setFont(CreateAndShowUI.getFont()); keywordPanel.add(remove); close = new JButton(new KeywordPanelController.SaveAndCloseAction( "Save & Close", controller, dialog, product, textFields)); close.setBackground(CreateAndShowUI.getButtonColor()); close.setFont(CreateAndShowUI.getFont()); keywordPanel.add(close, "cell 0 6, gapx 30px"); } public void setCategoryTextFields(int index, String category) { textFields[index] .addMouseListener(new KeywordPanelController.TextFieldMouseAdapter( textFields[index])); textFields[index].setEditable(false); textFields[index].setBackground(Color.WHITE); textFields[index].setText(category); } public void setLocation(int x, int y) { keywordPanel.setLocation(x, y); } public JPanel getKeywordPanel() { return keywordPanel; } } 

Main model for the application:

This is the CSVFileControllerCSVFileController class. This is used to update the model and the files based on user interaction with the view.

This is the controller for the KeywordPanel. public class KeywordPanelController{KeywordPanel:

public class KeywordPanelController {  public static class RemoveAction extends TextAction { private CSVFileController controller; private Product product; public RemoveAction(String name, CSVFileController controller, Product product) { super(name); this.controller = controller; this.product = product; } @Override public void actionPerformed(ActionEvent e) { JTextComponent textField = (JTextField) getFocusedComponent(); if (!textField.isEditable()) { product.getCategories().remove(textField.getText().trim()); product.setCategories(product.getCategories()); controller.adjustProductCategories(product); textField.setText(""); textField.setEditable(true); } } } public static class TextFieldMouseAdapter extends MouseAdapter { private JTextField textField; public TextFieldMouseAdapter(JTextField textField) { this.textField = textField; } @Override public void mouseClicked(MouseEvent evt) { textField.setSelectionColor(new Color(142, 15, 6)); textField.setSelectedTextColor(new Color(255, 255, 255)); textField.setSelectionStart(0); textField.setSelectionEnd(textField.getText().trim().length()); } } public static class SaveAndCloseAction extends AbstractAction { private JTextField[] textFields; private Product product; private CSVFileController controller; private Dialog dialog; public SaveAndCloseAction(String name, CSVFileController controller, Dialog dialog, Product product, JTextField[] textFields) { super(name); this.controller = controller; this.textFields = textFields; this.product = product; this.dialog = dialog; } @Override public void actionPerformed(ActionEvent e) { List<String> categories = new ArrayList<String>(); for (JTextField textField : textFields) { if (new ValidateString().validate(textField.getText().trim())) { categories.add(textField.getText().trim()); } } product.setCategories(categories); controller.adjustProductCategories(product); dialog.getDialog().dispose(); } } } 

The ProductProduct class which is a POJO. NotI'm not entirely sure if this should be considered a model class or not.

Trying to focus on learning so I can get an entry level position and the best way for me to learn right now is to have someone review and provide areas of improvement. This project isn't entirely complete but almost. I am going to include the code for some of the classes but not all of them. Just a few button actions left to finish. All criticism is welcomed.

The MainPanel Class which basically creates the main JPanel for the JFrame. This JPanel has two child panels and one menu bar.

The KeywordPanel Class which is one of the panels for JDialog. This panel is added dynamically to a dialog based on a specific action taken by the user. public class KeywordPanel {

 private CSVFileController controller; private Product product; private Dialog dialog; private JPanel keywordPanel; private JTextField[] textFields; private JLabel searchLbl; private JButton close, remove; public KeywordPanel(CSVFileController controller, Dialog dialog, Product product) { this.controller = controller; this.product = product; this.dialog = dialog; createKeywordPanel(); } public void createKeywordPanel() { keywordPanel = new JPanel(new MigLayout()); searchLbl = new JLabel("KeyWords"); searchLbl.setFont(CreateAndShowUI.getFont()); keywordPanel.add(searchLbl, "wrap"); textFields = new JTextField[] { new JTextField(""), new JTextField(""), new JTextField(""), new JTextField(""), new JTextField("") }; for (JTextField textField : textFields) { textField.setFont(CreateAndShowUI.getFont()); textField.setPreferredSize(new Dimension(242, 30)); keywordPanel.add(textField, "wrap"); } remove = new JButton(new KeywordPanelController.RemoveAction("Remove", controller, product)); remove.setBackground(CreateAndShowUI.getButtonColor()); remove.setFont(CreateAndShowUI.getFont()); keywordPanel.add(remove); close = new JButton(new KeywordPanelController.SaveAndCloseAction( "Save & Close", controller, dialog, product, textFields)); close.setBackground(CreateAndShowUI.getButtonColor()); close.setFont(CreateAndShowUI.getFont()); keywordPanel.add(close, "cell 0 6, gapx 30px"); } public void setCategoryTextFields(int index, String category) { textFields[index] .addMouseListener(new KeywordPanelController.TextFieldMouseAdapter( textFields[index])); textFields[index].setEditable(false); textFields[index].setBackground(Color.WHITE); textFields[index].setText(category); } public void setLocation(int x, int y) { keywordPanel.setLocation(x, y); } public JPanel getKeywordPanel() { return keywordPanel; } } 

Main model for the application

This is the CSVFileController class. This is used to update the model and the files based on user interaction with the view.

This is the controller for the KeywordPanel. public class KeywordPanelController{

 public static class RemoveAction extends TextAction { private CSVFileController controller; private Product product; public RemoveAction(String name, CSVFileController controller, Product product) { super(name); this.controller = controller; this.product = product; } @Override public void actionPerformed(ActionEvent e) { JTextComponent textField = (JTextField) getFocusedComponent(); if (!textField.isEditable()) { product.getCategories().remove(textField.getText().trim()); product.setCategories(product.getCategories()); controller.adjustProductCategories(product); textField.setText(""); textField.setEditable(true); } } } public static class TextFieldMouseAdapter extends MouseAdapter { private JTextField textField; public TextFieldMouseAdapter(JTextField textField) { this.textField = textField; } @Override public void mouseClicked(MouseEvent evt) { textField.setSelectionColor(new Color(142, 15, 6)); textField.setSelectedTextColor(new Color(255, 255, 255)); textField.setSelectionStart(0); textField.setSelectionEnd(textField.getText().trim().length()); } } public static class SaveAndCloseAction extends AbstractAction { private JTextField[] textFields; private Product product; private CSVFileController controller; private Dialog dialog; public SaveAndCloseAction(String name, CSVFileController controller, Dialog dialog, Product product, JTextField[] textFields) { super(name); this.controller = controller; this.textFields = textFields; this.product = product; this.dialog = dialog; } @Override public void actionPerformed(ActionEvent e) { List<String> categories = new ArrayList<String>(); for (JTextField textField : textFields) { if (new ValidateString().validate(textField.getText().trim())) { categories.add(textField.getText().trim()); } } product.setCategories(categories); controller.adjustProductCategories(product); dialog.getDialog().dispose(); } } } 

The Product class which is a POJO. Not entirely sure if this should be considered a model class or not.

I'm trying to focus on learning so I can get an entry level position and the best way for me to learn right now is to have someone review and provide areas of improvement. This project isn't entirely complete but almost. I am going to include the code for some of the classes but not all of them. Just a few button actions left to finish. All criticism is welcomed.

The MainPanel Class which basically creates the main JPanel for the JFrame. This JPanel has two child panels and one menu bar.

The KeywordPanel class which is one of the panels for JDialog. This panel is added dynamically to a dialog based on a specific action taken by the user.

public class KeywordPanel {  private CSVFileController controller; private Product product; private Dialog dialog; private JPanel keywordPanel; private JTextField[] textFields; private JLabel searchLbl; private JButton close, remove; public KeywordPanel(CSVFileController controller, Dialog dialog, Product product) { this.controller = controller; this.product = product; this.dialog = dialog; createKeywordPanel(); } public void createKeywordPanel() { keywordPanel = new JPanel(new MigLayout()); searchLbl = new JLabel("KeyWords"); searchLbl.setFont(CreateAndShowUI.getFont()); keywordPanel.add(searchLbl, "wrap"); textFields = new JTextField[] { new JTextField(""), new JTextField(""), new JTextField(""), new JTextField(""), new JTextField("") }; for (JTextField textField : textFields) { textField.setFont(CreateAndShowUI.getFont()); textField.setPreferredSize(new Dimension(242, 30)); keywordPanel.add(textField, "wrap"); } remove = new JButton(new KeywordPanelController.RemoveAction("Remove", controller, product)); remove.setBackground(CreateAndShowUI.getButtonColor()); remove.setFont(CreateAndShowUI.getFont()); keywordPanel.add(remove); close = new JButton(new KeywordPanelController.SaveAndCloseAction( "Save & Close", controller, dialog, product, textFields)); close.setBackground(CreateAndShowUI.getButtonColor()); close.setFont(CreateAndShowUI.getFont()); keywordPanel.add(close, "cell 0 6, gapx 30px"); } public void setCategoryTextFields(int index, String category) { textFields[index] .addMouseListener(new KeywordPanelController.TextFieldMouseAdapter( textFields[index])); textFields[index].setEditable(false); textFields[index].setBackground(Color.WHITE); textFields[index].setText(category); } public void setLocation(int x, int y) { keywordPanel.setLocation(x, y); } public JPanel getKeywordPanel() { return keywordPanel; } } 

Main model for the application:

This is the CSVFileController class. This is used to update the model and the files based on user interaction with the view.

This is the controller for the KeywordPanel:

public class KeywordPanelController {  public static class RemoveAction extends TextAction { private CSVFileController controller; private Product product; public RemoveAction(String name, CSVFileController controller, Product product) { super(name); this.controller = controller; this.product = product; } @Override public void actionPerformed(ActionEvent e) { JTextComponent textField = (JTextField) getFocusedComponent(); if (!textField.isEditable()) { product.getCategories().remove(textField.getText().trim()); product.setCategories(product.getCategories()); controller.adjustProductCategories(product); textField.setText(""); textField.setEditable(true); } } } public static class TextFieldMouseAdapter extends MouseAdapter { private JTextField textField; public TextFieldMouseAdapter(JTextField textField) { this.textField = textField; } @Override public void mouseClicked(MouseEvent evt) { textField.setSelectionColor(new Color(142, 15, 6)); textField.setSelectedTextColor(new Color(255, 255, 255)); textField.setSelectionStart(0); textField.setSelectionEnd(textField.getText().trim().length()); } } public static class SaveAndCloseAction extends AbstractAction { private JTextField[] textFields; private Product product; private CSVFileController controller; private Dialog dialog; public SaveAndCloseAction(String name, CSVFileController controller, Dialog dialog, Product product, JTextField[] textFields) { super(name); this.controller = controller; this.textFields = textFields; this.product = product; this.dialog = dialog; } @Override public void actionPerformed(ActionEvent e) { List<String> categories = new ArrayList<String>(); for (JTextField textField : textFields) { if (new ValidateString().validate(textField.getText().trim())) { categories.add(textField.getText().trim()); } } product.setCategories(categories); controller.adjustProductCategories(product); dialog.getDialog().dispose(); } } } 

The Product class which is a POJO. I'm not entirely sure if this should be considered a model class or not.

added 19455 characters in body
Grim
  • 163
  • 1
  • 8
Loading
Post Closed as "Not suitable for this site" by Jamal
Grim
  • 163
  • 1
  • 8
Loading
close