HiveBrain v1.2.0
Get Started
← Back to all entries
patternjavaModerate

Making a word processor

Submitted by: @import:stackexchange-codereview··
0
Viewed 0 times
processormakingword

Problem

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:

```
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());
}

Solution

Some general note about your program.

Comments

/**
     * 
     */
    private static final long serialVersionUID = 1L;


Never leave an empty comment. Comment are already something I'm not a fan of, but an empty one is useless.

/*
     * @Version: 0.002
     * not much in terms of commenting but a lot of this stuff is very obvious
     */


You don't have to say that there isn't much to say. When I read a comment, I want to have useful information about the code, not that I won't find anything of value. I would suggest that if you have nothing to say then just say nothing.

Naming convention

JMenuItem saveMenuItem, openMenuItem, newMenuItem, exitMenuItem, FontMenuItem;


One of your variable don't respect the naming convention.
Pay close attention to that, when you don't respect convention your code is less readable.

private JMenuBar menubar;


Camel-case is not respected here.

private Font yeah = new Font(Font.SANS_SERIF, 2, textHeight);


Is yeah the name of the font ? If not, than I don't find yeah a good name. Something like defaultFont or the name of the font you'll use would be better.

Constant

private int width = 1280, height = 980;


I didn't find a place in the code where you change the width and height. Those should probably be a constant with proper definition and naming.

Suppress warnings

public static void main(String args[]){
    @SuppressWarnings("unused")
    Main m = new Main();
}


Suppress warnings is something that I take particular attention. Why have you suppress the warning ? Warning should ring a bell and raise the question : Am I doing something wrong ? In your case, the warning is probably unused variable. But is it really an unused variable ? No, the action to start the application is in the constructor. Is it a good design, I'm wondering myself. I don't find it clear when an application start in a constructor. IMHO, constructor should initialize a class, not really much. If I were you I would probably have a method to actually start the application.

But in general warning should pop the question, am I doing something wrong? A suppress warning should be the last option to that though process. In many case, it's acceptable to have a @SupressWarning but sometimes it's just an easy solution that could lead to maintenance problem later on. (Bad design decision etc..)

Code Snippets

/**
     * 
     */
    private static final long serialVersionUID = 1L;
/*
     * @Version: 0.002
     * not much in terms of commenting but a lot of this stuff is very obvious
     */
JMenuItem saveMenuItem, openMenuItem, newMenuItem, exitMenuItem, FontMenuItem;
private JMenuBar menubar;
private Font yeah = new Font(Font.SANS_SERIF, 2, textHeight);

Context

StackExchange Code Review Q#42651, answer score: 12

Revisions (0)

No revisions yet.