David M Fairchild

+ Follow
since Apr 08, 2005
Cows and Likes
Total received
In last 30 days
Total given
Total received
Received in last 30 days
Total given
Given in last 30 days
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by David M Fairchild

I see where the problem is not in the layout of the status panel. It appears that setBackground() does not set the color of the entire canvas. I would say that my "TheGame" class derived from Canvas is reserving space for a title bar. Although the bounds of cnvGame, an instance of TheGame include the whole canvas. The status text displays "Canvas bounds = 0, 33, 400, 334.". My applet is in a 400 by 400 space on the web page so 400 - 33 - 33 = 334, the full height minus the NORTH and SOUTH panels.

Now I'm looking for why Canvas is allocating space for a title bar and how I can turn that "feature" off.

Thanks for you help. Any additional insights would be helpful.
12 years ago
12 years ago
I have a simple first applet I'm playing with. I defined a Panel to go in the NORTH area of the main Panel and placed a single TextField in the Panel.

For some reason the FlowLayoutManager lays out enough space for 2 rows of TextFields in the Panel? Why is that? Is there a way to make it stop doing that?
12 years ago
You should be able to use a try / catch syntax in the Applet code. Or are you wondering what happens to the browser if the applet fails?

You can see output from your applet using the Java Console. (Found under 'Tools' on IE)
16 years ago
I have a nifty applet that gets it's data from a database via an ASP on the web server the Applet is launched from. I have no problem recieving data, but when I try to update the data by sending a URL string to the web server/ASP file it fails.

If I just paste the URL from the Java Console to the address window of a browser (IE 6.0) it works fine, updates the database as expected.

Does anyone know of a reason the Applet won't do the same?
16 years ago

I'm doing, practically the same thing. I have experience with ASP so I set up a web site to use ASP (it's Windows IIS so pretty easy to do). Then I have my Java Applet send requests back to my web site for data.

To encapsulate every thing I created a class, 'WebData', which knows how to connect to the web site and can build a request. Here is the code for that:

import java.io.* ;
import java.net.* ;
import java.util.*;

public class WebData {
HttpURLConnection con;
String cb;

* Method WebData
public WebData(String codeBase) {
cb = codeBase;

public Vector<String> getData(Vector<String> params) {
Vector<String> aList = new Vector<String>();
URL textURL;
String line;

String command = cb + "getData.asp?";
for(int i=0;i<params.size();i++) {
command = command.concat(params.get(i) + "&");
command = command.substring(0, command.length() - 1);

try {
textURL = new URL(command);
BufferedReader theStream = new BufferedReader(
new InputStreamReader(textURL.openStream()));
// now read the lines one at a time
while ( ( line = theStream.readLine() ) != null ) {
} // close while loop


} catch(Exception e) {


Because this is an applet, it's simplier to connect back to the web site that sent the applet. The function 'getData()' takes a Vector of string consisting of the name of the function (on the ASP file) that I want to call and any parameters that are necessary to call that function. It returns a Vector of String.

In my application, the list boxes and combo boxes have an instance of the WebData class and know how to display the Vector of String they get back from the getData() function. So the Vector to call the data just gets passed thru them as such:

public void listJobCodes() {
Vector<String> params = new Vector<String>();
int i = WorkGroups.getSelectedIndex();

if(i < 0) {



This method tells the JobCodes list to get the job codes associated with a specific WorkGroup that the user selected. You can see where it builds the parameters that will be sent to WebData. The function 'getJobCodes' is coded in the asp file on the web server.

This could be done with jsp, perl, php or any cgi application.

Hope this helps.
16 years ago
This is just a guess, I'm probably not the best person to reply to you. But is it possible that there are other dll's that the library you are trying to open relies upon? If so you will want to include their location in the java.library.path. It may also be necessary to include the system library files but I'm not sure about that.
16 years ago
Thanks Joe,

I appologize for not attempting your suggestion before I replied before.

As you probably have noticed, I'm not a very accomplished Java programmer. From your comment, I take it one should avoid 'writing' to containers. That's not what I actually did, but my previous example might have worked if I had populated the grid with labels then emptied the labels and re-wrote to the label rather than attempt to empty the grid and then filling it with labels again.

It seems this could be handy if you had a multi-form application and wanted to maintain a similar look and feel to all of your forms. You could invalidate the panel(s) then fill them with new labels/text boxes from a list in a database. That way you could alter your form by changing the contents of the database table used to populate the form.... could be handy.

Thanks again.
16 years ago
Thanks for the answer Joe, but I've already tried putting a statment in actionPerformed() to clear the center panel before calling getData(). Nothing gets written back.
16 years ago
Very interesting conversation! Back to the original topic ... I had a secret clearence when I was in the US Navy. I got out 19 years ago and haven't ever mentioned it on an application. I had no idea that it might be valuable. What about now? Is 19 years without a clearence job a problem?

On the job availability front, the current US Administration's objective is to protect big business owners, not citizens. I was writing my senators 10 years ago objecting to the policy of importing workers to do jobs I was qualified for and couldn't get a job doing.

On the other hand, just as I would like to be able to earn a living wage, I am sure that Kishore, and many like him, would as well. When the US government allows employers to go offshore to hire the best talent of other countries it hurts the US. It hurts our education system by reducing the investment there, it increases unemployment and lowers the standard of living in this country, eroding the middle class. It also hurts the country the talent is drawn from, intellectual talent is a valuable resource whether it's programming, engineering, medical, etc. The people remaining in these countries recieve little compensation for the loss and their 'would be' middle class leaves their country. The introduction of the middle class citizen has been America's greatest contribution to the world. They drive the economy by creating a demand for products, and they achieve more because they can envision a better future for themselves and their children.

While individuals coming to this country seeking jobs may be better off, the country they leave behind and the US would be better off, as a whole, if governments sought to increase opportunities at home for their most talented resource. Fostering the growth of their own middle class.
16 years ago
In the code listing below the getFile() function runs when called by init() but not when called by actionPerformed(). I'm strugling trying to figure out how to get an applet to communicate with the web server as the front end of a 3 tier application. Eventually, I will want to query the web server based on some user event and display the returned data.

Why Doesn't the getFile() call work in actionPerformed()? The text "Button Pushed" shows up in the status bar so I know actionPerformed() was called!

import java.io.* ;
import java.net.* ;
import java.applet.* ;
import java.awt.* ;
import java.awt.event.*;

public class HelloServerFile extends Applet implements ActionListener {
Panel pnlCenter = new Panel(new GridLayout(10,1));
Label lblStatus = new Label("Status:");

public void init() {
Panel pnlNorth = new Panel(new FlowLayout());
Panel pnlSouth = new Panel(new FlowLayout());
Button myButton = new Button("Get File");

setLayout( new BorderLayout() );

pnlNorth.add(new Label("Version 1.07"));


add(pnlNorth, BorderLayout.NORTH);
add(pnlCenter, BorderLayout.CENTER);
add(pnlSouth, BorderLayout.SOUTH);

} // close init

private void getFile() {
String line = new String("Button Pressed.");

URL textURL = new URL( getCodeBase() , "test.txt" );
BufferedReader theStream =
new BufferedReader(new InputStreamReader(textURL.openStream()));

while ( ( line = theStream.readLine() ) != null ) {
pnlCenter.add( new Label( line, Label.CENTER ) );
} // close while loop

} // close try
catch ( Exception e ) {

public void actionPerformed(ActionEvent ae) {
lblStatus.setText("Button Pushed");

} // close actionPerformed
} // close applet
16 years ago
I'm looking for a good book on Applets. One that covers every conceivable topic on Applets. Most of the books I've seen seem to be begining books. While I'm not a beginning programmer I am fairly new to Java.

What I specifically am trying to do is to develop a 3 tier application with a Java Applet as a front end. I will probably use ASP or Perl for a middle tier.

While I have seen replies indicating that you can GET and PUT data to the URL that launched the Applet, I have never seen any indication of how to do this.

I'd like a book with a little bit of advertising (telling me what can be done) and a lot of information (telling me how to do it!).
16 years ago
This may not help much but you might be able to use JNI the Java Native Interface to do this.

In a nutshell, the JNI can call library functions in a dll. I've done this with a stand alone application but not from a web page. Java security in an applet may prevent you from using JNI.

If you are able to use JNI, you need to write your own dll, probably in C or C++ and will need to call the windows library call Shell_NotifyIcon. Here are the required definitions, but if you are familiar with windows programming in C you won't have any problem with the tray icon.

Private Const NIF_ICON = &H2
Private Const NIF_MESSAGE = &H1
Private Const NIF_TIP = &H4
Private Const NIM_ADD = &H0
Private Const NIM_DELETE = &H2
Private Const NIM_MODIFY = &H1

cbSize As Long
hwnd As Long
uId As Long
uFlags As Long
uCallBackMessage As Long
hIcon As Long
szTip As String * 64
End Type

Private Declare Function Shell_NotifyIcon Lib "shell32.dll" _
Alias "Shell_NotifyIconA" (ByVal dwMessage As Long, _

I've never put an icon in a tray from C, but I have from VB and it's easy enough.

All in all, it's not a quicky solution.
17 years ago
Or some method that is called just before an object is destroyed?
17 years ago
Got It !!!

The problem seem to be in how Java was interpreting the c type long. I had a statment:

env->SetLongArrayRegion(buf, i, 1, (jlong*)&arVal[i]);

Which compiled but transferred garbage back to Java. So I added a variable:

jlong lVal = 0;

and then converted arVal[i] to a jlong:

iVal = (jlong)arVal[i];

Then added that to the jlongArray:

env->SetLongArrayRegion(buf, i, 1, &lVal);

And Viola' ... It worked!

Thanks for the help.
17 years ago