Skip to main content
Code Review

Return to Question

Question Protected by Sᴀᴍ Onᴇᴌᴀ
Tweeted twitter.com/StackCodeReview/status/1353356913367535616
deleted 25 characters in body
Source Link
Jamal
  • 35.2k
  • 13
  • 134
  • 238

The Word Processor Iword processor I've had in mind would be similar to Microsoft's wordMicrosoft Word and OpenOffice. I am trying to keep my logic separated from the Useruser Interface and that separated from the controller, basically using the MVC (model view controllerModel View Controller).

Other things I would like reviewed would be code layout,: should I try to abstract the code more? Am I using the correct writing surface (JTextArea) so that I can later implement a font style, size change on run time? Also, should I be doing something about thread safety (I understand that JFrame'ss are not thread safe, and I am going to be honest and say that I don't fully understand what this really means, but I am sure it has to do with a single thread running for the user input, graphics and business logic).

This is the controller :Controller:

This is the model :Model:

This is the view :View:

and finally this is the Main classMain class:

The Word Processor I had in mind would be similar to Microsoft's word and OpenOffice. I am trying to keep my logic separated from the User Interface and that separated from the controller, basically using the MVC (model view controller). Other things I would like reviewed would be code layout, should I try to abstract the code more? Am I using the correct writing surface (JTextArea) so that I can later implement a font style, size change on run time? Also should I be doing something about thread safety (I understand that JFrame's are not thread safe, I am going to be honest I don't fully understand what this really means, but I am sure it has to do with a single thread running for the user input, graphics and business logic).

This is the controller :

This is the model :

This is the view :

and finally this is the Main class

The word processor I've had in mind would be similar to Microsoft Word and OpenOffice. I am trying to keep my logic separated from the user Interface and that separated from the controller, basically using the MVC (Model View Controller).

Other things I would like reviewed would be code layout: should I try to abstract the code more? Am I using the correct writing surface (JTextArea) so that I can later implement a font style, size change on run time? Also, should I be doing something about thread safety (I understand that JFrames are not thread safe, and I am going to be honest and say that I don't fully understand what this really means, but I am sure it has to do with a single thread running for the user input, graphics and business logic).

Controller:

Model:

View:

Main class:

removed the "introduction", removed the thanks at the end, Capitalize every "i", punctuation, Remove noise from the title, but it still not quite good
Source Link

Making a word Processor, wondering if i am approaching it correctlyprocessor

So here is the story, i am looking to beef up my portfolio and wanting to do it for fun and a sense of accomplishment. The Word Processor iI had in mind would be similar to microsoft'sMicrosoft's word and openofficeOpenOffice. I am trying to keep my logic separated from the User Interface and that separated from the controller, basically using the MVC (model view controller). Other things iI would like reviewed would be code layout, should iI try to abstract the code more, do i need to?. Am iI using the correct writing surface (JTextAreaJTextArea) so that iI can later implement a font style, size change on run time.? Also should iI be doing something about thread safety (iI understand that JFrame'sJFrame's are not thread safe, iI am going to be honest iI don't fully understand what this really means, but iI am sure it has to do with a single thread running for the user input, graphics and business logic). I wanted to ask these question before i add anything more, i think i am asking a lot as is but i am predicting my code will bloat a lot more than it is. Anyways without further walls of text this

This is the controller :

thisThis is the model :

thisThis is the view :

i always appreciate people taking the time out to help me and welcome any critique or tips that are offered.

Making a word Processor, wondering if i am approaching it correctly

So here is the story, i am looking to beef up my portfolio and wanting to do it for fun and a sense of accomplishment. The Word Processor i had in mind would be similar to microsoft's word and openoffice. I am trying to keep my logic separated from the User Interface and that separated from the controller, basically using the MVC (model view controller). Other things i would like reviewed would be code layout, should i try to abstract the code more, do i need to?. Am i using the correct writing surface (JTextArea) so that i can later implement a font style, size change on run time. Also should i be doing something about thread safety (i understand that JFrame's are not thread safe, i am going to be honest i don't fully understand what this really means, but i am sure it has to do with a single thread running for the user input, graphics and business logic). I wanted to ask these question before i add anything more, i think i am asking a lot as is but i am predicting my code will bloat a lot more than it is. Anyways without further walls of text this is the controller

this is the model

this is the view

i always appreciate people taking the time out to help me and welcome any critique or tips that are offered.

Making a word processor

The Word Processor I had in mind would be similar to Microsoft's word and OpenOffice. I am trying to keep my logic separated from the User Interface and that separated from the controller, basically using the MVC (model view controller). Other things I would like reviewed would be code layout, should I try to abstract the code more? Am I using the correct writing surface (JTextArea) so that I can later implement a font style, size change on run time? Also should I be doing something about thread safety (I understand that JFrame's are not thread safe, I am going to be honest I don't fully understand what this really means, but I am sure it has to do with a single thread running for the user input, graphics and business logic).

This is the controller :

This is the model :

This is the view :

Source Link
tommy knocker
  • 183
  • 1
  • 1
  • 5

Making a word Processor, wondering if i am approaching it correctly

So here is the story, i am looking to beef up my portfolio and wanting to do it for fun and a sense of accomplishment. The Word Processor i had in mind would be similar to microsoft's word and openoffice. I am trying to keep my logic separated from the User Interface and that separated from the controller, basically using the MVC (model view controller). Other things i would like reviewed would be code layout, should i try to abstract the code more, do i need to?. Am i using the correct writing surface (JTextArea) so that i can later implement a font style, size change on run time. Also should i be doing something about thread safety (i understand that JFrame's are not thread safe, i am going to be honest i don't fully understand what this really means, but i am sure it has to do with a single thread running for the user input, graphics and business logic). I wanted to ask these question before i add anything more, i think i am asking a lot as is but i am predicting my code will bloat a lot more than it is. Anyways without further walls of text this is the controller

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
public class ProcessEvents {
 private WordFrame frame = new WordFrame();
 private DataStuff data = new DataStuff();
 private DialogBoxes dialogs = new DialogBoxes();
 private boolean fileSaved;
 String fileName = "";
 int fontSize = 0;
 public ProcessEvents(WordFrame frame, DataStuff data){
 this.frame = frame;
 this.data = data;
 this.frame.addListener(new wordProcessListener());
 }
 class wordProcessListener implements ActionListener{
 @SuppressWarnings("static-access")
 @Override
 public void actionPerformed(ActionEvent e) {
 if(e.getSource().equals(frame.openMenuItem)){
 frame.fileChooser.showOpenDialog(frame);
 File f = frame.fileChooser.getSelectedFile();
 
 System.out.println("Command Executed: open");
 data.loadFile(f.getAbsoluteFile());
 
 if(data.showText() != null){ 
 System.out.println(data.showText()); 
 frame.textArea.append(data.showText().toString());
 }
 }
 
 if(e.getSource().equals(frame.FontMenuItem)){
 System.out.println("font");
 }
 
 if(e.getSource().equals(frame.exitMenuItem)){
 dialogs.getConfirmDialog("exitWithoutSave");
 }
 
 if(e.getSource().equals(frame.saveMenuItem)){
 frame.fileChooser.showSaveDialog(null);
 File f = frame.fileChooser.getSelectedFile();
 String text = frame.textArea.getText();
 data.saveFile(f.getAbsolutePath()+".txt", text);
 System.out.println(f.getName());
 fileSaved = true; 
 } 
 } 
 }
}

this is the model

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
public class DataStuff {
 private File file;
 
 String text;
 String name;
 private File saveFile;
 int counter = 0;
 FileInputStream fis = null;
 FileOutputStream fout = null;
 StringBuilder sb = new StringBuilder(4096);
 int count = 0;
 public void loadFile(File fileName){
 this.file = fileName;
 try{
 fis = new FileInputStream(file);
 
 while ((counter = fis.read()) != -1) {
 System.out.print((char) counter);
 
 sb.append((char) counter);
 
 }
 
 }
 catch(IOException ex){
 System.out.println("file couldn't be opened, or was incorrect or you clicked cancel");
 }
 finally {
 try {
 if (fis != null)
 fis.close();
 } catch (IOException ex) {
 ex.printStackTrace();
 }
 }
 }
 public StringBuilder showText(){
 return sb;
 }
 public void saveFile(String name, String text) {
 this.name = name;
 
 try{ 
 fout = new FileOutputStream(name); 
 fout.write(text.getBytes());
 System.out.println("file saving worked"); 
 }
 catch(IOException e){
 System.out.println("File failed to save or something went horribly wrong");
 } 
 } 
}

this is the view

import java.awt.Font;
import java.awt.event.ActionListener;
import javax.swing.ImageIcon;
import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
public class WordFrame extends JFrame{
 /**
 * 
 */
 private static final long serialVersionUID = 1L;
 private JMenuBar menubar;
 private JMenu fileMenu, editMenu, viewMenu;
 JMenuItem saveMenuItem, openMenuItem, newMenuItem, exitMenuItem, FontMenuItem;
 JTextArea textArea = new JTextArea(1000,900);
 private int width = 1280, height = 980;
 private JScrollPane scrollbar = new JScrollPane(textArea);
 JFileChooser fileChooser = new JFileChooser();
 private int textHeight = 12;
 private Font yeah = new Font(Font.SANS_SERIF, 2, textHeight);
 public WordFrame(){
 setUI();
 addMenuBar(); 
 textArea.setFont(yeah);
 }
 
 public void setUI(){
 this.setTitle("Word Processor");
 this.setIconImage(new ImageIcon(this.getClass().getResource("Bridge.jpg")).getImage());
 this.setSize(width, height);
 this.setLocation(0,0);
 this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
 this.add(scrollbar);
 
 }
 
 public void addMenuBar(){
 menubar = new JMenuBar();
 fileMenu = new JMenu(" File ");
 editMenu = new JMenu("Edit ");
 viewMenu = new JMenu("View ");
 
 newMenuItem = new JMenuItem("New");
 fileMenu.add(newMenuItem);
 fileMenu.addSeparator();
 fileMenu.setMnemonic('f');
 
 openMenuItem = new JMenuItem("Open");
 
 fileMenu.add(openMenuItem);
 
 saveMenuItem = new JMenuItem("Save");
 fileMenu.add(saveMenuItem);
 
 fileMenu.addSeparator();
 exitMenuItem = new JMenuItem("Exit");
 fileMenu.add(exitMenuItem);
 
 FontMenuItem = new JMenuItem("Font");
 editMenu.add(FontMenuItem);
 menubar.add(fileMenu);
 menubar.add(editMenu);
 menubar.add(viewMenu); 
 
 this.setJMenuBar(menubar);
 }
 
 public void setFontSize(int i){
 this.textHeight = i;
 }
 public void addListener(ActionListener listener){
 openMenuItem.addActionListener(listener);
 exitMenuItem.addActionListener(listener);
 saveMenuItem.addActionListener(listener);
 }
}

and finally this is the Main class

public class Main {
 /*
 * @Version: 0.002
 * not much in terms of commenting but a lot of this stuff is very obvious
 */
 public Main(){
 WordFrame mainFrame = new WordFrame();
 DataStuff data = new DataStuff();
 @SuppressWarnings("unused")
 ProcessEvents process = new ProcessEvents(mainFrame, data );
 mainFrame.setVisible(true);
 }
 public static void main(String args[]){
 @SuppressWarnings("unused")
 Main m = new Main();
 }
}

i always appreciate people taking the time out to help me and welcome any critique or tips that are offered.

lang-java

AltStyle によって変換されたページ (->オリジナル) /