Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / November 2006

Tip: Looking for answers? Try searching our database.

Use of Choice/combobox in an applet

Thread view: 
Angus - 20 Nov 2006 19:44 GMT
Hello

I want to write a Java applet (up to Java v1.1) which gets some information
from the server and writes a list to a Choice/Combobox on the web page.

Should I use a Choice control as part of my applet? Or should I put the
information in a combobox which is part of a html form? What is best? And
how roughly to go about it?

Angus
Daniel Pitts - 20 Nov 2006 20:39 GMT
> Hello
>
[quoted text clipped - 6 lines]
>
> Angus

Actually, I would suggest trying to avoid using Java altogether and use
JavaScript instead.

JavaScript, incase you didn't know, if very different from Java.  If
all you need to do is fill a Combobox depending on information from the
server, you could try to make the server populate the combo box on the
initial load, especially if that data is static. If the data is
dynamic, look into using AJAX to load the data from the server.

Writing an applet is much more trouble IMHO.

Hope this helps,
Daniel.
Angus - 20 Nov 2006 21:31 GMT
I need to do a lot more than just fill a combobox.  So I will be using Java.
Just want an answer to my question assuming I am using Java ....

> > Hello
> >
[quoted text clipped - 20 lines]
> Hope this helps,
> Daniel.
Dag Sunde - 20 Nov 2006 23:32 GMT
> I need to do a lot more than just fill a combobox.  So I will be
> using Java. Just want an answer to my question assuming I am using
[quoted text clipped - 22 lines]
>>
>> Writing an applet is much more trouble IMHO.

Please don't top-post...

That depends entirely what you want to do with the items in the list
afterwards... are you going to use them exclusively in the applet,
then use the Java contol. You can also access public methods in your
applet from JavaScript later.

If you mostly need the items in the html page (For JavaScript, use
the HTML control. You can access Javascript functions from an Applet,
so you will still be able to get hold of the items from the applet.

--
Dag.
Angus - 21 Nov 2006 10:05 GMT
Top posting is a style choice I make.  Why do people get so upset about
top-posting grrr

If I use a html form control how can I access the contents of the HTML
control from my applet?  You mention accessing JavaScript functions from an
applet.  Is that the way to do it?  How?

Angus

> > I need to do a lot more than just fill a combobox.  So I will be
> > using Java. Just want an answer to my question assuming I am using
[quoted text clipped - 36 lines]
> --
> Dag.
Andrew Thompson - 21 Nov 2006 10:40 GMT
> Top posting is a style choice I make.  Why do people get so upset about
> top-posting grrr

Oh, I don't get upset.  I hope you don't get too upset
when I ignore your further posts (it's a 'choice' thing).

Andrew T.
Dag Sunde - 21 Nov 2006 11:12 GMT
> Top posting is a style choice I make.  Why do people get so upset
> about top-posting grrr
>
> If I use a html form control how can I access the contents of the HTML
> control from my applet?  You mention accessing JavaScript functions
> from an applet.  Is that the way to do it?  How?

Like Andrew, I choose not to help a person when he chooses to ignore
common netiquette. In c.l.j.p, bottom posting is the norm, because it
makes it a lot easier to follow the flow of the conversation.

I do have complete code samples for you, but they won't be posted until
you stop making your own rules.

Tip thou... I have posted about this Applet/JS topih here before...

Signature

Dag.

Angus - 21 Nov 2006 12:00 GMT
> > Top posting is a style choice I make.  Why do people get so upset
> > about top-posting grrr
[quoted text clipped - 14 lines]
> --
> Dag.

Is that more to your liking?

If I use a html form control how can I access the contents of the HTML
control from my applet?  I had a look at accessing JavaScript functions from
an
applet but that seems fraught with problems so something I want to avoid.

Angus
Andrew Thompson - 21 Nov 2006 13:00 GMT
(JS mentioned)
...
> > > If I use a html form control how can I access the contents of the HTML
> > > control from my applet?  You mention accessing JavaScript functions
> > > from an applet.  Is that the way to do it?  How?
..
> > Tip thou... I have posted about this Applet/JS topih here before...
..
> If I use a html form control how can I access the contents of the HTML
> control from my applet?

Can we take a pause here and get a little more
detail on the end effect you are trying to achieve?
(I am sure there is a simpler way to approach what
this web-app. needs to do, but it is not very clear to
me yet, what it's supposed to do and how.)

Note that applets are not good at interacting directly with
HTML, they do it via JS generally, so it seems either the
Java is an unnecessary overhead, or the HTML is unnecessary,
or if neither of those statements is correct, the JS is essential!

Andrew T.
Dag Sunde - 21 Nov 2006 13:15 GMT
<snipped/>

>> Tip thou... I have posted about this Applet/JS topih here before...
>
[quoted text clipped - 5 lines]
> applet but that seems fraught with problems so something I want to
> avoid.

Brilliant! ;-)

You need to add the plugin.jar to your classpath while developing
(Part of JRE, and not JDK)

Put the applet class files in the same directory as your html-file
on the server...

Here's the html:

<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
 <script type="text/javascript">
  function getSelected() {
   return document.getElementById("names").value;
  }
 </script>

</head>

<body>
 <applet code=CallbackApplet.class width="300" height="50" >
 </applet>
 <select id="names">
  <option value="Andrew" selected="selected">Andrew</option>
  <option value="Angus">Angus</option>
  <option value="Dag">Dag</option>
 </select>
</body>

</html>

And here's the Applet code:

import java.applet.Applet;
import netscape.javascript.*;
import java.awt.*;
import java.awt.Button;
import java.awt.event.ActionEvent;

public class CallbackApplet extends Applet {

private Panel content = new Panel();
private Button cmdGet = new Button();
private Label lbl = new Label();

public void init() {

 content.setBackground( Color.YELLOW);
 this.add(content);

 lbl.setText("Hello World!");
 content.add(lbl);

 cmdGet.setLabel("Get Combo Item");
 cmdGet.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(ActionEvent e) {
        getSelectedItem(e);
      }
    });
 content.add(cmdGet);

 this.invalidate();
}

private void getSelectedItem(ActionEvent e) {

 JSObject appletOwner = JSObject.getWindow ( this );
 lbl.setText(appletOwner.call ( "getSelected", null ).toString());
}
}

Signature

Dag.

Andrew Thompson - 20 Nov 2006 22:03 GMT
..
> Should I use a Choice control as part of my applet? Or should I put the
> information in a combobox which is part of a html form?

Ask yourself this.  What does an applet bring to this
page that could *not* be done in an HTML form?

Unless it is something spectacular, most users would
prefer the HTML form, since it appears quicker, for
more people, and has few, if any usability problems.

(In fact, the very question, should I use an Applet or HTML
seems like a dumb one to me - the only things I'd do in
an applet, could not be done in pure HTML..)

Andrew T.
Angus - 21 Nov 2006 10:03 GMT
I need to do some connect to a socket on the web server, and do a load of
i/o.

If I use a html form control how can I access the contents of the HTML
control from my applet?

> ..
> > Should I use a Choice control as part of my applet? Or should I put the
[quoted text clipped - 12 lines]
>
> Andrew T.
Ian Wilson - 21 Nov 2006 11:34 GMT
>> Angus wrote: ..
>>
[quoted text clipped - 10 lines]
> I need to do some connect to a socket on the web server, and do a
> load of i/o.

It looks like you could use AJAX instead of an Applet?


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.