Use of Choice/combobox in an applet

A

Angus

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
 
D

Daniel Pitts

Angus said:
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

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.
 
A

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 Java ....
 
A

Andrew Thompson

Angus wrote:
...
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.
 
D

Dag Sunde

Angus said:
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 ....
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.
 
A

Angus

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?
 
A

Angus

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
 
A

Andrew Thompson

Angus said:
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.
 
D

Dag Sunde

Angus said:
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...
 
A

Angus

Dag Sunde said:
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...

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
 
A

Andrew Thompson

(JS mentioned)
....
...
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.
 
D

Dag Sunde

Angus said:
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.

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());
}
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top