This program should display 1 normal button (a) and 3 radio buttons (x,z,y). When the user selects one radio button and press the button a, it should redirects him to a website. The problem is during the launch. The window is empty, and in the bottom left there’s a message saying “Start: Applet Not Initialized”. Also, I get “java.lang.InstantiationException” in the console.
I’ll be grateful for any help.
package nome.nonoriginale;
import java.awt.Button;
import java.awt.Checkbox;
import java.awt.event.ActionListener;
import java.net.MalformedURLException;
import java.net.URL;
import javax.swing.JApplet;
import com.sun.corba.se.spi.orbutil.fsm.Action;
public abstract class Linkers extends JApplet implements ActionListener
{
Button a = new Button("Go to");
URL libro1;
URL libro2;
URL libro3;
Checkbox x;
Checkbox z;
Checkbox y;
public void init()
{
try
{
libro1 = new URL("http://www.reddit.com/");
libro2 = new URL("http://www.youtube.com/");
libro3 = new URL("http://www.ismatteirecanati.it/default.aspx?pag=0&lang=it");
}
catch(MalformedURLException e)
{
System.out.println("Link's broken, brah");
}
add(a);
add(x);
add(z);
add(y);
a.addActionListener(this);
}
public void ActionPerformed(Action e)
{
if(x.getState() == true)
getAppletContext().showDocument(libro1);
else if(y.getState() == true)
getAppletContext().showDocument(libro2);
else if(z.getState() == true)
getAppletContext().showDocument(libro3);
}
}
The class can’t be instantiated as it is declared
abstract. You need to remove theabstractkeyword from the class declaration:Aside from that, you can implement
ActionListenerby implementing:It looks like you have imported a CORBA
Actionclass by mistake.Once these changes are made you wil get a
NullPointerExceptionas your checkboxes are not instantiated.Don’t mix AWT with Swing components—AWT are heavyweight and will adversely affect the drawing of Swing components.
so you could use: