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!
I think it is working, you just can't see the new data. pnlCenter can only hold 10 elements. Everything else is discarded. Try using a TextArea instead of a panel and you'll see data get appended with every button press.
I took your code, used a TextArea and it worked fine. Maybe you should try printing out the data as you read it in from the URL. Making a container dynamic involves a bit more work than "clearing" it. At the very least you have to invoke invalidate() on the container to mark it as needing the layout manager applied, then after altering it invoke validate() to run the layout manager.
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.
As you probably have noticed, I'm not a very accomplished Java programmer.
hey, we're all learning, just at different levels.
From your comment, I take it one should avoid 'writing' to containers.
You CAN do it but there's more to it than you were thinking. If you want to go deeper, the Java Tutorial has two chapters: Creating a GUI with Swing and 2D Graphics which you should run through so you have a better idea as to what process are going on and how things get written to the screen.
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
Sure. You've figured out two parts of the Model-View-Controller (MVC) paradigm. One separates the responsability of containing the data to the model, displaying the data to the view and working with the data to the controller, then all these pieces collaborate by passing messages back and forth. Swing is based on MVC so it's easier to do what you describe than with AWT. Again, take a look at the tutorials and I think everything will fall into place. [ July 22, 2005: Message edited by: Joe Ess ]