aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes Applet Project Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Applet Project" Watch "Applet Project" New topic
Author

Applet Project

Dave DiRito
Ranch Hand

Joined: Feb 08, 2008
Posts: 77
I need to build an applet program with no Swing at all in it. I must display a list of movies for the user to select. The list must get generated from an arraylist of the movies.

The closest example I have right now is an applet that displays a horizontal checkbox group of three items to select. What I want to do is display the checkbox group vertically and also be able to generate the group from the arraylist of movies.

Can anyone point me in the right direction?

Here a piece of the code that creates the checkbox group from the example I have:
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41817
    
  62
Since you already have the checkboxes, I'm assuming that the vertical positioning is the problem. You can use a java.awt.GridLayout as layout, with one column and as many rows as you have checkboxes (in other words "new GridLayout(3, 1)").

Moving to the AWT/Swing/GUI forum, as there's nothing applet-specific about the question.


Ping & DNS - my free Android networking tools app
Dave DiRito
Ranch Hand

Joined: Feb 08, 2008
Posts: 77
Thank you, Ulf.

Is there an example somewhere of some gridlayout code that would give me an idea of how to use it?
Ilja Preuss
author
Sheriff

Joined: Jul 11, 2001
Posts: 14112
Originally posted by Dave DiRito:

Is there an example somewhere of some gridlayout code that would give me an idea of how to use it?


The javadoc for the GridLayout class contains such an example.


The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
Dave DiRito
Ranch Hand

Joined: Feb 08, 2008
Posts: 77
Here is more information regarding what I am attempting to do. I need to read a file of movie titles into an arraylist. From that list I need to generate a menu of movies from which the user can choose. The movie file can change so the movie titles and even the number of movies can change.

I'm thinking that I should build a checkboxgroup by somehow looping through the arraylist. The caption of each checkbox would be the name of the movie. I don't know if that's the best way to do this or if it's even possible.

Another restriction I have is that I cannot use Swing. It must be an applet that runs in a web browser. This is a class project. Any suggestions would be greatly appreciated.

Here is my attempt at the loop which does not compile:

Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41817
    
  62
What does "does not compile" mean? If there's an error messge, tell us what it is.

As to not using Swing, just stay clear of the classes in javax.swing.*, and use the ones in java.awt.* instead.
Dave DiRito
Ranch Hand

Joined: Feb 08, 2008
Posts: 77
Here is my program with the errors following. For the moment I have the movie array hard coded. Thank you for looking at this:



C:\Java Programs\DVD Test2>javac Pgm1app.java
Pgm1app.java:23: invalid method declaration; return type required
setLayout(new GridLayout(3, 1));
^
Pgm1app.java:23: illegal start of type
setLayout(new GridLayout(3, 1));
^
Pgm1app.java:23: <identifier> expected
setLayout(new GridLayout(3, 1));
^
Pgm1app.java:25: illegal start of type
for(x = 0; x < movies.length: x++){
^
Pgm1app.java:28: <identifier> expected
Checkbox hiddenBox = new Checkbox("",true,dvdGroup);
^
5 errors
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41817
    
  62
You can't put code outside of any method declaration. The lines it's complaining about -the setLayout call and the loop- need to be inside of the init method.
Dave DiRito
Ranch Hand

Joined: Feb 08, 2008
Posts: 77
OK, here's the code where I made changes followed by the errors I'm getting now. I don't know where it wants the parentheses.




C:\Java Programs\DVD Test2>javac Pgm1app.java
Pgm1app.java:32: ')' expected
add(Checkbox movieBox(x) = new Checkbox(movies(x),false,dvdG
roup));
^
1 error
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41817
    
  62
add(Checkbox movieBox(x) = new Checkbox(movies(x),false,dvdGroup));


You can't mix a variable declaration and the use of the variable like that. Also, arrays use square brackets, not round brackets. Try this:


[ March 16, 2008: Message edited by: Ulf Dittmer ]
Dave DiRito
Ranch Hand

Joined: Feb 08, 2008
Posts: 77
Thank you. Here's my changed code and the errors I get now:


C:\Java Programs\DVD Test2>javac Pgm1app.java
Pgm1app.java:8: Pgm1app is not abstract and does not override abstract method it
emStateChanged(java.awt.event.ItemEvent) in java.awt.event.ItemListener
public class Pgm1app extends Applet implements ItemListener{
^
Pgm1app.java:28: cannot find symbol
symbol : class CheckBox
location: class Pgm1app
Checkbox[] movieBox = new CheckBox[movies.length];
^
2 errors
Nicholas Jordan
Ranch Hand

Joined: Sep 17, 2006
Posts: 1282
The first error is telling you to write this method:


To fix the second diagnostic:



"The differential equations that describe dynamic interactions of power generators are similar to that of the gravitational interplay among celestial bodies, which is chaotic in nature."
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41817
    
  62
Actually, the second error is fixed by using "Checkbox" instead of "CheckBox" (which the error message is complaining about). Java class names are case-sensitive.
Dave DiRito
Ranch Hand

Joined: Feb 08, 2008
Posts: 77
Thank you, Nicholas and Ulf. I will try those fixes.

Dave
Dave DiRito
Ranch Hand

Joined: Feb 08, 2008
Posts: 77
YES! I just corrected those two errors and it now compiles!

Thank you both so much.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Applet Project