• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Applet Project

 
Ranch Hand
Posts: 77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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:
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Dave DiRito
Ranch Hand
Posts: 77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you, Ulf.

Is there an example somewhere of some gridlayout code that would give me an idea of how to use it?
 
author
Posts: 14112
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
 
Dave DiRito
Ranch Hand
Posts: 77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 1282
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The first error is telling you to write this method:


To fix the second diagnostic:

 
Ulf Dittmer
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you, Nicholas and Ulf. I will try those fixes.

Dave
 
Dave DiRito
Ranch Hand
Posts: 77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
YES! I just corrected those two errors and it now compiles!

Thank you both so much.
 
I don't always make ads but when I do they're tiny
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic