Showing posts with label HTML. Show all posts
Showing posts with label HTML. Show all posts

JavaScript Forms

I am working on development a web app game. It is being written in JavaScript. I had learned how to do forms, so I made the game use a form. The majority of the screen is a big select area. I was going crazy because my JavaScript code was generating errors. The browser kept complaining that document.forms[0].mySelect was either NULL or not an object.

This was troubling because I had coded successful projects that used this technique. Googling the web also showed many examples of this working. To get by I hacked some getElementById calls instead. It still troubled my. I was running Internet Explorer 8. This stuff should have been working.

Near the end of my game development cycle I had to add more items to the form such as a status message. That is when I found the root cause of the problem. The select element was not within the form tags in the HTML. Ouch. No wonder JavaScript could not access the select object. It was just not part of the form. Now I got an action item to go back and use the familiar technique to access the form data in JavaScript code.

Java App Version One

It is about time for me to get down to business and code a prototype for my app ideas. Previously I had thought I needed a polished product. But version 1 does not need all that. It just needs to get done. Then I will try it out for myself and see what to change in version 2.

Of course I am going to use Java as the programming language. The eventual product will be a web app displayed in HTML. However the first version might even just be text based. We shall see. I will probably post a link to my alpha version when it is ready for distribution.

Window Pane Management

I have been creating buttons that have no text on them. They only have a graphic icon loaded from an image file. I noticed that the button size grows to accommodate larger pictures. This leads to different sized buttons and a messy user interface. There must be a way to keep a uniform button size, shrinking icon images as needed.

Another problem I have is when a control such as a button is invisible. The other controls rearrange during the paint() so as to obscure the position where the invisible control would be. I don't like this reshuffling of the screen when a control goes invisible. There should be a way to reserve space on the screen for a control that may become visible in the future. However this is not the default behavior.

I normally use appletViewer to test out my applets in development. But I found out that this tool only displays the embedded applet in an HTML page. It does not render any of the other HTML elements. Weird.

Applets and Web Pages

So far I have been concentrating on applets. The applet is normally the entire web page. The HTML for the web page is merely to name the applet, and give it a size. However this is not normal. You usually have some other presentation in the HTML page. Therefore I did a more realistic project that integrated applet output with the markup from the HTML source.

I had an exercise from my textbook dealing with times. In Java, you can get the number of milliseconds since 1970. This feature has been encapsulated with the Date class. The default constructor of Date initializes the object to the current date and time. Use DateFormat to choose how you want to show the date. Even though the class is abstract, you can still call the static members.

Button Behavior

You size an applet in the HTML page that hosts it. I find that you need to size the applet area carefully to allows your controls to be layed out as expected on the screen.

The general pattern I use when user input drives the display is to have a member variable of my JApplet derived class. There is conditional logic in the paint() method that depends on this variable. When a user action changes the variable state, repaint() is called to redraw the screen.

I've been doing a lot with buttons that have no text on them. They only have an icon image on them. I have encountered some problems with transparency. I would like the button background color to bleed through any white portion of my image. However does not seem to be the default behavior of the button class. Maybe I need to set some unknown options. I hope I do not need to code or draw my own button face.

My First Applet

Here I am in my full week of training. This is an independent study for me. My goal is to learn applet programing. Read a couple chapters in my school textbook. We always skipped the applet and other GUI sections. Unfortunately the applet chapter requires you to read the big Java Swing chapter. I have skipped it. So I am going to be having some troubles.

Applets do not have a main function. Instead they have an init. They close when the web page that contains them closes. The containing web page is written in HTML. The applet itself runs on the client machine. There are some security restrictions like an applet cannot run a program, read a file, or write a file. You should test your applets on many browsers including multiple versions of the same browser.

The older class for applets is Applet. Go figure. You cannot use Swing with this old style class. You also cannot do icons or menus. Use buttons instead. I found that I could load an HTML page which referenced an applet. However when I recoded and recompiled the applet, an Internet Explorer 6 refresh would not run the new version of the applet. That was annoying. Instead I decided to use appletviewer. Here is another strange thing. The reload function in appletviewer causes the window to disappear and the viewer to freeze. Another funny thing was that I tried to use Graphics2D in my paint method. It compiled but just output a light blue screen. All my graphics were gone. I guess I can make do with the normal Graphics class.

Disappointing Advice

This semester I am taking a web development class in school. We are learning HTML and Cascading Style Sheets (CSS). However next semester I shall take an advanced Java programming class. I thought I had better brush up on my Java programming since I had not done any since my intro to Java class.

I thought I could combine what I learned in web development with some Java code to produce a Content Management System (CMS). It would take user input and spit out a blog site in HTML. This seemed doable in a month or two if I kept the app simple.

Today I read an advice column from a developer claiming to be a veteran who was in the know. He started out by recommending that developers do not create CMS systems. Ooops. He went on to say that developers should not code in Java. Ouch. That was the double whammy.

The reasons for this advice were twofold. First there are too many existing CMS solutions on the market. Second he said users just don't use Java apps. Well that might make sense if I was trying to start up a business with my product. But I am just trying to write a throw away app to gain some experience. So I think I am okay with my idea. It just won't turn into some money making opportunity. Or will it?