I have a piece of Java code where users will get a bunch of outputs (outputs are numbers).
I am trying to edit this code so that I can display the output as a Java Applet via webpage. Here's a part of the result I need to show.

String s1 = String.format("%9.0f\n", (double)N);  
String s2 = String.format("%10.20f\n", fX);  
String s3 = String.format("%10.20f\n", fY);  
......  
String s10 = ...;  

System.out.printf("Here are all the running results. ");  
System.out.printf(s1);  
System.out.printf(s2);  
System.out.printf(s3);  
......  
System.out.printf(s10); 

My problem is, I can do this as a regular Java program but I cannot make it happen as a Java Applet. I need to make it as an applet to collect data from users and detect if there's any differences. I tried JLabel and JTextField but they both only accept strings as output. I cannot find a way to display variables' values in Java Applet.

I am also not sure if using Java Applet is the best way to do so, cause I don't really find too many amazing things Java Applet can do while I am working on this. Looking for chances to implement this into a PHP page if Java Applet is a dead end.

Member Avatar for iamthwee

seriously java applets are a has-been of web tech. Consider writing this in php and jquery, you will be much better off.

Java applets are still very powerful but as iamthwee said its a "has-been" there are much better ways to create in browser programs, javascript for example.

One thing to realize is that the computer accepts all input and output as strings so not being able to ues just integers is nothing new. If you want to output a string to a jtext field or jlabel simply convert your output to a string JLabel.setText(theNumber + "") is the simplest way and if you want to be proper use JLabel.setText(Integer.toString(theNumber)). Its been a while since i worked with GUIs so forgive me if i have the wrong methods.

  • question isn't clear, please whats I cannot find a way to display variables' values in Java Applet., variables from and for why reason(s), code posted is about basic Java knowledges and haven't something with Applet/JApplet, you'll be the same issue in C++/.Net or Php

  • use Hybrid JApplet (Swing & JApplet),

  • better to create an Standalone Swing App and to distribute anywhere by using Java Web Start

  • have look at JavaFX 2.x, but I'd suggest to waiting for JavaFX8, there I'm hope that every new features will be added to official API and without bugs from current version,

What I am trying to accomplish is displaying the value of those variables (String s1 to s10). Their values will be calculated on those computers who have JDK. Values can be displayed as output when you try to run the code as a normal Java code through cmd or any IDEs but I am just having a hard time to get them displayed through a Java Applet.

I did tell you how to print integers to a jlable or jtextbox but there is not enough clear informatiion here to help you fruther. Please restate your question along with the code you are having trouble with. The code posted above is not even related to your problem.

Member Avatar for iamthwee

It's a very bad idea to use java applets. Not bad mouthing the technology or anything (well actually I am) but java applets have definitely seen their day. Now with the demise of flash it is much better to consider using technology which is going to survive the test of time and NOT be restricted to client side technology which needs to be specifically installed and is not even available to some devices notably iOS devices (without major hacking of course)

mKorbel compared java applets to c++.net or php. This is a terrible comparsion. How can you compare client side technology with server side technology? Perhaps if you said servlets you may have a point but applets are not servlets.

So no, don't use java applets if you can help it.

@iamthwee

  • code posted is about basic Java knowledges and haven't something with Applet/JApplet, you'll be the same issue in C++/.Net or Php != comparing the apples with bananas

  • the same as as mentioned once time another thread about lonely hearts, isn't it

Member Avatar for iamthwee

code posted is about basic Java knowledges and haven't something with Applet/JApplet, you'll be the same issue in C++/.Net or Php != comparing the apples with bananas

Good point, to be fair I was having trouble understanding the way you write as English is probably not your native tongue. Regardless of this fact, my point still stands . . . A java applet is a poor choice for today's web technology.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.