Forums Register Login

Applet Project

+Pie Number of slices to send: Send
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:
+Pie Number of slices to send: Send
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.
+Pie Number of slices to send: Send
Thank you, Ulf.

Is there an example somewhere of some gridlayout code that would give me an idea of how to use it?
+Pie Number of slices to send: Send
 

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.
+Pie Number of slices to send: Send
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:

+Pie Number of slices to send: Send
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.
+Pie Number of slices to send: Send
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
+Pie Number of slices to send: Send
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.
+Pie Number of slices to send: Send
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
+Pie Number of slices to send: Send
 

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 ]
+Pie Number of slices to send: Send
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
+Pie Number of slices to send: Send
The first error is telling you to write this method:


To fix the second diagnostic:

+Pie Number of slices to send: Send
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.
+Pie Number of slices to send: Send
Thank you, Nicholas and Ulf. I will try those fixes.

Dave
+Pie Number of slices to send: Send
YES! I just corrected those two errors and it now compiles!

Thank you both so much.
Does this tiny ad smell okay to you?
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 4712 times.
Similar Threads
state of radio button.
check box group
Stuck on checkboxes -pleeeeze help
adding Checkboxgroup to a panel
DRAW A NEW LINE
More...

All times above are in ranch (not your local) time.
The current ranch time is
Apr 16, 2024 06:55:41.