Remote Coder Blog

A brief respite from my coding closet

Java Timer Applet

November17

I am not certain whether or not it’s taboo to post your code on the internet. There are several sites out there that do this, and I know without some code examples every now and then to look at, I might never understand certain elements.

It was hard to find any thing that closely related to what I’m about to post here. Basically, I was looking for some example that would illustrate for me how to use the Javax.swing.timer method.

I could understand that I needed to create the method by using:
timer = new Timer(1000, new TimerListener); which initializes a variable called timer as a new Timer method, counting by seconds, and called using the TimerListener class (inside class I had to create).

The reason why I was trying to create this java class was so I could imbed it into an applet for use on an html page.

This is the html code I used to call the applet:
<.html>

<.head><.title>Timer Applet<./timer><./head>
<.body><.applet code="timer.class" width="300" height="100"><./applet><./body><./html>
<./code>

Basically, the applet tag calls the java class and puts it in a predetermined sized window. When you load the html page in your browser (with Java enabled) it will call the java class, and run it.

So my Java code is as follows:
//Name: David Nick
//Date: 11.16.2009
//Purpose: To create a Java Timer Applet

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;

public class timer extends JApplet
{

private JTextField tLabel;
private JPanel tPanel;
private JPanel bPanel;
private JButton startBtn;
private JButton stopBtn;
private Timer timer;
private int x = 0;

public void init()
{
timer = new Timer(1000, new TimerListener());
getContentPane().setBackground(Color.black);

//building the panels
buildTpanel();
buildBpanel();

//add panels to content pane
add(tPanel);
add(bPanel);

//setting the panel layout
setLayout(new GridLayout(2, 1));
}

private void buildTpanel()
{
//create the panel
tPanel = new JPanel();

//create Textfield that goes into the tPanel
tLabel = new JTextField("000000");

//add textfield to panel
tPanel.add(tLabel);
}

private void buildBpanel()
{
//create the panel
bPanel = new JPanel();

//create the buttons
startBtn = new JButton("Start");
stopBtn = new JButton("Stop");

//create the button listeners
startBtn.addActionListener(new StartListener());
stopBtn.addActionListener(new StopListener());

//add buttons to the panel
bPanel.add(startBtn);
bPanel.add(stopBtn);
}

//creating a listener for the start button

private class StartListener implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
timer.start();
}
}

//creating a listener for the stop button

private class StopListener implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
timer.stop();
}
}

//creating a timer listener
private class TimerListener implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
x++;
tLabel.setText("000000"+(x));
}
}
}

One of the difficulties for me was nailing down how to increment the counter once I hit the start button. The Timer method has only timer.start(); and timer.stop();. There is no timer.reset(); method. It is in poor taste to try and force the timer to set itself to all zeros because in clicking start it continues where you hit stop.

And so there you have the Java Timer Method used in an HTML applet.

posted under HTML, XHTML, CSS, AJAX, Java, Programming, School, Source Code | Comments Off

Facebook, styles for FireFox, and killing that annoying status spam

May30

Recently one of my Twitter “reads” mentioned using a plug in for FireFox called Stylish to kill all of the spam on the right hand side of FaceBook.

If you are a frequent user of FaceBook, you know that it’s pretty annoying to constantly see a list of whatever “applications” your friends are using. (I.E.: List 5 things you hate, blah blah blah)

What Stylish is, is an add-on for FireFox that essentially modifies a websites formatting, and lays over the top of what ever site you’re viewing. So if something particular annoys you with a site, Stylish will allow you to remove the offending piece of code, thus making the site more enjoyable for your tastes.

Using Stylish for FaceBook turned off the notifications but still left other spam like the suggestions window, and other notifications.

So this is the code that stylish created for facebook:

@namespace url(http://www.w3.org/1999/xhtml);

@-moz-document domain("facebook.com") {
.UIHotStream {display:none;}

}

and I added the following line to completely block/hide everything on that right side:

.UITitledBox {display:none;}

and so altogether you have:

@namespace url(http://www.w3.org/1999/xhtml);

@-moz-document domain("facebook.com") {
.UIHotStream {display:none;}
.UITitledBox {display:none;}
}

I hope that my tip was helpful if you are as tired of looking at that garbage as I am. Now I am going to see what other sites I can use Stylish for because there is certainly plenty of spam/garbage out there I don’t want to look at.

Wow, the end of May is already here

May27

And you thought you were busy? :)

Just a quick update to my last post. I completed my spring semester and passed all of my classes. So I’ve successfully navigated through Java 1, Agile Programming Methodology (Using Ruby on Rails), XML (DOM, SAX, XHTML), and PHP/MYSQL!

I am by far not finished learning ANY of these languages as they are all excellent and have their uses. Let’s just say this semester was getting my feet wet.

In retrospect, I certainly have a ton of work to do to master each of these. Along with working them, I also dusted off my HTML, graphics work, javascript, and picked up a new skill (CSS).

I have all of my textbooks for next semester, but I need to also find time to dive into them and get some of that knowledge under my belt before the semester starts. I’d like to do better this semester than I did the last one.

Now, as for this summer and blogging…. Mid June is going to be terrible for me as I am leaving for a 4 day excursion w/family. July is looking slightly better, and August I am taking another trip w/family. That means to you (the few of you there are) that I am going to continue my sporadic blogging.

I did want to pass along a link that I received for an IDE geared for MAC OS X called Coda. For a VERY limited time, Panic Inc (the company that makes Coda) is offering their products for 50% off what they normally sell them for.

If you go here, you’ll find more about it. I am about to download the demo and see for myself what the fuss is all about. I have also recently picked up Komodo Edit and I love their Windows IDE product. It’s worth finding something you like and sticking to it.

School season is winding down!

May6

May is a great month. Baseball, warmer temps, bugs are not fully aware that humans are outside, AND… school season is wrapping up for the semester!

Before my final exams next Monday and Tuesday, I have to complete 2 projects (1 Java, 1 php) and make sure that I have all of my code handy on a single thumb drive. This is incase we are allowed only 1 for taking our final app tests.

In Java we are working on abstract methods and classes. So we’ll create a driver/main app, which will call upon a parent class, and 2 child classes. This sounds simple enough but the work is tedious and I hope I have time to take care of it.

In PHP, the project is a bit more difficult as we have to completely revamp a website we’ve written, that has SQL functionality, and so not only changing graphics, web pages (which are all in php) but also making sure that every aspect that calls a DB query works.

So, PHP first, and we’ll sweat the small stuff later right?

And that is what I am doing now until next Tuesday. After class is out, then I am hoping to write more frequently over the summer!

Wish me luck!

posted under Blogging, Java, PHP, School | Comments Off

Gettin’ Busy Wit’ It

April8

Wow, with April upon us you have to be asking yourself: “What is this guy doing that’s keeping him so busy from writing?”

The answer is simple:

  1. In my java class we are working on using Abstract methods in our programming. These are, simply put, place markers in parent classes that are invoked generally in child classes. Our final Java exam is an app test and I am trying to make sure all my coding knowledge is committed to a thumb drive so that when I go in, I have my base experience to call back on.
  2. Agile Methodology (in which we’re learning Ruby on Rails) we are set to begin our final project in which I code a ecommerce site based on my partners specifications. We are doing final demos of our current project today and tomorrow.
  3. XML. We are working on XSLT (XML Style Sheets) and this marks the turning point in understanding the complexities of XML.
  4. PHP. We’re pretty much working on MYSQL connectivity issues as we’ve gone away from web site rendering to the functional aspects of setting up a php server and having it connect  to a database.
  5. My first SkyWarn exercise/drill is tonight, so I have to review some documentation on the planning. Of course, since everything is subject to change at a given notice, all my reading my be in vain. :)
  6. This week there is plenty of things going on at both of my dojos. I have new Katas(Sayaws)|[Forms] to learn as well as videography of one of my dojos. I need to dump whatever videos I have onto my computer, and prepare for a 5 hour session at Shuri-Te.  Then come back and go to my Arnis class on Friday. :)

Next week is a tad lighter on the schedule, but with Easter coming Sunday, and driving to my in-laws place, I need to get on the ball with my coding that will likely be due Monday.

It won’t be long and May will be here. Once that happens, and school is out, I can get to work on writing more articles about skills/tricks I’ve discovered while developing.

BTW, if you haven’t checked out my main site, please do so. If you know of anyone looking for a developer intern over the summer, drop me a line as well. Thanks!

posted under Blogging, Java, PHP, Programming, Ruby, School, XML | Comments Off
« Older Entries