Ngoc Bui
Ngoc Bui

Reputation: 15

applet - browser doesn't show java applet

I'm create a simple applet. I follow a tutorial in "Java in 24h" .when I run apply by terminal appletviewer helloworld.html. It worked. I see "Click me" button and "Hello World" but when I open helloworld.html by browser ( Safari, Chrome, Firefox ) . I don't see applet. it just hava "end line!" I enabled java pluins for my browser and I'm using macosx

my code :

import javax.swing.*;
import java.awt.*;
import java.applet.*;
import java.awt.event.*;
//<applet code = Saluton width = 300 height = 300> </applet>
public class Saluton extends Applet {
    public void init() {
         Button buttons = new Button("Click me!");
         this.add(buttons);
    }
    public void paint(Graphics screen)
    {
        Graphics2D screen2D = (Graphics2D) screen;
        screen2D.drawString("Hello World",120,120);
    }
} 

and HTML file

<head>
<title>Hello World!</title>
</head>
<body bgcolor = green text = "#FF00FF">
<center>
<applet 
    code = Saluton
    width = 300
    height = 150
>
<p>end line!</p>
</applet>
</center>
</body>
</html>

Upvotes: 1

Views: 740

Answers (1)

rekiem87
rekiem87

Reputation: 1573

This was meant to be a comment, but i will try to explain in detail...

TL;DR

It is not working because most browsers does not run java applets these days, there is no way around it, and it is good, do not fight the future (being 2019 is even the present, you are trying to use a tool from the past).

You should not be using applets this days, i repeat, you should not be using applets this days. End of discussion.

Long answer

This history is based on ancient, anecdotal and maybe not so exact experience.

Some history

The java applets were introduced around 1995, those where other times, Javascript was much more young, lacked so many things like libraries or standards. To fix this, the ability to run external plugins was utilized to run some more powerful and complex solutions, like Flash or the applets.

This allowed some really powerful applications, games and more, but the easiness to run external code plus the popularization of internet in the world give some dangerous tools in the hands of the wrong people.

The java folks were trying to define the boundaries that allowed to use the power of java maintaining a sand box that provided the user security without set a hard limit to the java language, but even the Flash plugin, designed from the start to run in browsers, was having some really serious security problems. Imagine Java, a language designed to run on the desktop, sure it had some hard problems too.

So, the solutions were insufficient, Sun (latter Oracle) and Macromedia (latter Adobe) was throwing a ton of money and resources to the problem, but there was no end near, the hackers had no problem finding new bugs, and the people did not have the culture of keep your programs updated, and automatic updates were not a thing back then, so now imagine, you are a company with other ton of money and the need to make more complex app for browsers what do you do? (without saying company names)

Throw two tons of money and... CrEaTe YoUr OwN tEcHnOlGy!!!, and call it Microsoft Silverlight, at the same time, Google folks tried with other approach, called Dart, but with a backup plan, a strong inversion of three tons of money in Javascript, creating Javascript V8, a really decent and impressive implementation of the Javascript language, all while some people were fighting to achieve some standards in between browsers.

While this was happening, also the open source was becoming a predominant force in the software industry, luckily a lot of big tech was in the hype train, so there was a lot of good will and cooperation desire, so the companies realized, Why do we throw a zillion dollars crating our own private tools, instead of improving the public ones?, so all technologies were abandoned in favor of more standards (HTML5, ECMA6).

This helped to centralize security problems, grow a ton of libraries which feed applications which were growing in complexity, boosting even more the web applications that we use nowadays. Slowly the browsers has been throwing support for all those old technologies, so you should not be developing in them.

So nowadays, what is used for the same tasks?

As everything in this engineering life, it depends.

For general applications that you need to be sure run in a ton of devices, use a web application, you can use Java for the back-end, it is really powerful as a server side language, and have a tons of libraries and frameworks, for the front you can use Vue, Angular, React, or any library that suits you.

If you want some advanced features and access to some non web standard hardware, you can try also some tools that allow to create native apps with one code base, like react native or xamarin.

If you just want to do a java runnable in a desktop environment with easy updates, i could recommend bypass the browser completely and use JNLP which

allows an application to be launched on a client desktop by using resources that are hosted on a remote web server

This way you can use JavaFx, Swing or whatever you like.

Those were some options, there are many more (full native, NetFramework for windows, Qt...) but again, please, do not use applets they are old, insecure and depreciated.

Disclaimer: Sorry for my English, it is not my primary language, any correction is appreciated.

Upvotes: 1

Related Questions