I want to create a simple program that can store notitions(create/edit/view).
I'm doing this because my OO-thinking isn't what it should be...
This is what I had come up with from structure:
NOTITION PROGRAM:
Program that stores notes. Functions are:
- creating new notes + storing them
- editing notes
- viewing notes (all)
Storing happens in MySQL database.
I would like to have a GUI window to do all this.
StartUp.java (class that starts up the program by creating a new NoteProgram.java object).
MODEL:
- note.java (a class that represent a note)
VIEW:
- NoteProgram.java (main GUI window that gives the possibility to create/edit/view notes
CONTROLLER:
- NoteController.java (controller class for notes)
I already designed the Note.java class:
The GUI (NoteProgram.java) that I have is still just a frame:Code:package model; import javax.swing.*; /* * This class represents a note. A note has: * - A ID * - A title * - A author * - A content * - A date */ public class Note { private int id; private String title; private String author; private String content; private String date; public Note(int id, String title, String author, String content, String date){ setId(id); setTitle(title); setAuthor(author); setContent(content); setDate(date); } public int getId() { return id; } public void setId(int id) { this.id = id; } public String getTitle() { return title; } public void setTitle(String title) { if(title != ""){ this.title = title; }else{ JOptionPane.showMessageDialog(null, "Your title has to be filled in"); } } public String getAuthor() { return author; } public void setAuthor(String author) { this.author = author; } public String getContent() { return content; } public void setContent(String content) { if(content != ""){ this.content = content; }else{ JOptionPane.showMessageDialog(null, "Your content has to be filled in"); } } public String getDate() { return date; } public void setDate(String date) { this.date = date; } }
And of course the StartUp.javaCode:package view; import javax.swing.JFrame; public class NoteProgram { //Declaration of fields JFrame mainFrame; public NoteProgram(){ init(); } public void init(){ //initialisation of fields for frame of GUI mainFrame = new JFrame("Notition manager"); mainFrame.setVisible(true); mainFrame.setLocationRelativeTo(null); mainFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); mainFrame.setSize(500, 400); } }
Code:import view.NoteProgram; public class StartUp { public static void main(String[] args) { NoteProgram app = new NoteProgram(); } }
About how to go further I'm a bit doubtfull...
Anyone can help me out?
Thanks
You will need a SQL connection class (probably singleton) for connecting to the SQL database. But why dont you have note.java implement Serializable instead?
I like the idea of Startup.java but what about instead of creating new windows for each note, you create new tabs. So Startup.java is called MainWindow.java and NoteProgram.java is NoteTab.Java which is a swing tab that extends a note object?
Thats probably a bit cleaner and a bit more OO? I find OOing problems hard so let me know what you think.
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks