brokenjago
Newbie
- Joined
- Jul 9, 2003
- Messages
- 328
- Reaction score
- 0
Help/Advice with code! Thanks!
Hi guys, I'm new on this particular forum. I usually hang out around the HL2 Discussion, and the Off Topic Forums, but I thought I'd try my hand here.
Anyway, I've been coding in java for about 8 months now, I was in a program in my school called the Oracle Database Interent Academy, a two year program in which you familiarise yourself with databases, and the programming behind them, etc etc...
I decided that I enjoyed coding immensely, and have since continued past my graduation (I graduated in June). I was pondering what to make when a friend came up to me with a plea:
"Jago <--(that's my name), I want to switch from Trillian to GAIM, but I need my Trillian Logs with GAIM. "Hhhhhmmmm," I thought, "This presents an interesting program challenge that would actually be useful to someone! Let the coding begin!"
I soon realized that I needed to take baby steps toward my ultimate goal: I quickly made a basic program that writes a crappy ol' string to a file. That was a success. The next phase, I decided, was to create a program that accepts user input, then generates a web page (fully XHTML 1.0 Strict and CSS valid ), with a picture and basic info about that person. That's what I'm doing now. So far, it's come along swimmingly, and I'm doing well. I don't really have any problems with the code, other than minor annoyances, which I will address later. I was just wondering what you think of the code for now. Whether it's well made, whether I used good/efficient ways, etc, etc.
Well, without further ado, here is my code:
Sorry for a lack of comments, I previously had everything carefully commented, but then I re-wrote half the program and all the comments became obsolete. It is now my policy to write comments only after the code is finalized.
Hi guys, I'm new on this particular forum. I usually hang out around the HL2 Discussion, and the Off Topic Forums, but I thought I'd try my hand here.
Anyway, I've been coding in java for about 8 months now, I was in a program in my school called the Oracle Database Interent Academy, a two year program in which you familiarise yourself with databases, and the programming behind them, etc etc...
I decided that I enjoyed coding immensely, and have since continued past my graduation (I graduated in June). I was pondering what to make when a friend came up to me with a plea:
"Jago <--(that's my name), I want to switch from Trillian to GAIM, but I need my Trillian Logs with GAIM. "Hhhhhmmmm," I thought, "This presents an interesting program challenge that would actually be useful to someone! Let the coding begin!"
I soon realized that I needed to take baby steps toward my ultimate goal: I quickly made a basic program that writes a crappy ol' string to a file. That was a success. The next phase, I decided, was to create a program that accepts user input, then generates a web page (fully XHTML 1.0 Strict and CSS valid ), with a picture and basic info about that person. That's what I'm doing now. So far, it's come along swimmingly, and I'm doing well. I don't really have any problems with the code, other than minor annoyances, which I will address later. I was just wondering what you think of the code for now. Whether it's well made, whether I used good/efficient ways, etc, etc.
Well, without further ado, here is my code:
Code:
/*********************************************************************
* Automatic HTML profile Creator by Jago Goddard. This program is *
* released in accordance with the GNU General Public Lisence. You *
* are free to distrubute the program, and/or use portions of it *
* in your own projects so long as you give the original author (me) *
* credit. Have fun, and remember kids, don't do drugs! *
*********************************************************************/
//all HTML used by this program is actually completely XHTML 1.0 Strict and CSS3 compliant, Verify it with the W3, if you must...
//before anything happens, please realize that I have very bad spelling, So please excuse any errors I might make in my comments
import java.io.*;
class gimmeHTML{
FileWriter HTMLDocWriter, CSSWriter;
String firstName, lastName;
gimmeHTML(String fName, String lName)
{
firstName = fName;
lastName = lName;
try
{
HTMLDocWriter = new FileWriter(firstName + "'s Profile.html");
CSSWriter = new FileWriter("Style Sheet.css");
}
catch(IOException exc)
{
System.out.println("Fatal Error: FileWriter creation failed. Check folder and/or file permissions and try again.");
}
}
void brIt()
{
try
{
HTMLDocWriter.write("[br]");
}
catch(IOException exc)
{
System.out.println("Fatal Error: Could not write to HTML document. Please check file permissions and try again.");
}
}
void nbspIt(int quantity)
{
try
{
for(int x=0;x<=quantity;x++)
{
HTMLDocWriter.write("");
}
}
catch(IOException exc)
{
System.out.println("Fatal Error: Could not write to HTML document. Please check file permissions and try again.");
}
}
void constructCSSDoc()
{
try
{
CSSWriter.write("p.right {text-align: right} p.left {text-align: left} p.center {text-align: center} img {border-width: 0} a {border-width: 0}");
}
catch(IOException exc)
{
System.out.println("Fatal Error: Write to CSS file failed. File will have no formatting.");
}
}
void writeIt(String string)
{
try
{
HTMLDocWriter.write(string);
}
catch(IOException exc)
{
System.out.println("Fatal Error: Could not write to HTML document. Please check file permissions and try again.");
}
}
void horizontalRule()
{
try
{
HTMLDocWriter.write("<hr />");
}
catch(IOException exc)
{
System.out.println("Fatal Error: Could not write to HTML document. Please check file permissions and try again.");
}
}
void constructDocumentOpen()
{
try
{
HTMLDocWriter.write("<?xml version=\"1.0\" encoding=\"UTF-8\"?> <!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\"> <html> <head><link rel=\"stylesheet\" type=\"text/css\" href=\"Style Sheet.css\" /> <title>Profile Creator 1.0 - "+firstName+"'s Profile</title></head><body>");
}
catch(IOException exc)
{
System.out.println("Fatal Error: Could not write to HTML document. Please check file permissions and try again.");
}
}
void writeCSSValid()
{
try
{
HTMLDocWriter.write("[url=\"http://jigsaw.w3.org/css-validator/\"][img]\"http://jigsaw.w3.org/css-validator/images/vcss\" alt=\"Valid CSS!\" height=\"31\" width=\"88\" />[/url]");
}
catch(IOException exc)
{
System.out.println("Fatal Error: Could not write to CSS document. Please check file permissions and try again.");
}
}
void writeXHTMLValid()
{
try
{
HTMLDocWriter.write("[url=\"http://validator.w3.org/check?uri=referer\"][img]\"http://www.w3.org/Icons/valid-xhtml10\" alt=\"Valid XHTML 1.0!\" height=\"31\" width=\"88\" />[/url]");
}
catch(IOException exc)
{
System.out.println("Fatal Error: Could not write to HTML document. Please check file permissions and try again.");
}
}
void constructDocumentClose()
{
try
{
HTMLDocWriter.write("</body></html>");
}
catch(IOException exc)
{
System.out.println("Fatal Error: Could not write to HTML document. Please check file permissions and try again.");
}
}
void alignItOpen(String alignment)
{
if(alignment != "center" && alignment != "right" && alignment != "left")
{
System.out.println("Invalid alignment chosen. Defaulting to \"center\"");
alignment = "center";
}
try
{
HTMLDocWriter.write("<p class=\""+alignment+"\">");
}
catch(IOException exc)
{
System.out.println("Fatal Error: Could not write to HTML document. Please check file permissions and try again.");
}
}
void alignItClose()
{
try
{
HTMLDocWriter.write("</p>");
}
catch(IOException exc)
{
System.out.println("Fatal Error: Could not write to HTML document. Please check file permissions and try again.");
}
}
void boldItOpen()
{
try
{
HTMLDocWriter.write("[b]");
}
catch(IOException exc)
{
System.out.println("Fatal Error: Could not write to HTML document. Please check file permissions and try again.");
}
}
void boldItClose()
{
try
{
HTMLDocWriter.write("[/b]");
}
catch(IOException exc)
{
System.out.println("Fatal Error: Could not write to HTML document. Please check file permissions and try again.");
}
}
void italicizeItOpen()
{
try
{
HTMLDocWriter.write("[i]");
}
catch(IOException exc)
{
System.out.println("Fatal Error: Could not write to HTML document. Please check file permissions and try again.");
}
}
void italicizeItClose()
{
try
{
HTMLDocWriter.write("[/i]");
}
catch(IOException exc)
{
System.out.println("Fatal Error: Could not write to HTML document. Please check file permissions and try again.");
}
}
void underlineItOpen()
{
try
{
HTMLDocWriter.write("<u>");
}
catch(IOException exc)
{
System.out.println("Fatal Error: Could not write to HTML document. Please check file permissions and try again.");
}
}
void underlineItClose()
{
try
{
HTMLDocWriter.write("</u>");
}
catch(IOException exc)
{
System.out.println("Fatal Error: Could not write to HTML document. Please check file permissions and try again.");
}
}
void linkItOpen(String link)
{
try
{
HTMLDocWriter.write("[url=\""+link+"\"]");
}
catch(IOException exc)
{
System.out.println("Fatal Error: Could not write to HTML document. Please check file permissions and try again.");
}
}
void linkItClose()
{
try
{
HTMLDocWriter.write("[/url]");
}
catch(IOException exc)
{
System.out.println("Fatal Error: Could not write to HTML document. Please check file permissions and try again.");
}
}
void imageIt(String src){
try
{
HTMLDocWriter.write("[img]\""+src+"\" id=\""+firstName+"'s Picture\" />");
}
catch(IOException exc)
{
System.out.println("Fatal Error: Could not write to HTML document. Please check file permissions and try again.");
}
}
}
class profileCreator{
public static void main(String args[]){
try
{
gimmeHTML blah = new gimmeHTML("test","man");
blah.constructCSSDoc();
blah.CSSWriter.close();
blah.constructDocumentOpen();
blah.alignItOpen("center");
blah.writeXHTMLValid();
blah.nbspIt(2);
blah.writeCSSValid();
blah.alignItClose();
blah.constructDocumentClose();
blah.HTMLDocWriter.close();
}
catch(IOException exc)
{
System.out.println("Fatal Error: File Creation failed.");
}
}
}
Sorry for a lack of comments, I previously had everything carefully commented, but then I re-wrote half the program and all the comments became obsolete. It is now my policy to write comments only after the code is finalized.