Applet Java

2 respostas
samanta.santos

[color=red]Bom dia, estou começando java agora e estou vendo alguns exemplos em um livro chamado CoreJava 2. Neste exemplo,não estou conseguindo fazer com que os botões apareçam. Alguém pode me ajudar :?:
Agradeço desde já :lol:
[/color]

<html> 
<head> 
<title>WelcomeApplet</title> 
</head> 
<body> 
<hr>Este Applet é do Livro 
<a href="http://www.horstmann.com/corejava.html"> 
Core Java</a> By <i>Cay Horstman</i> and <i>Gary Cornel</i>, publicado por Sun Microsystem Press. 

<!-- "CONVERTED_APPLET" --> 
<!-- CONVERTER VERSION 1.0 --> 
<script language="javascript"><!-- 
var _info = navigator;userAgente; var _ns = false; 
var _ie = (_info.indexOf(MSIE) > 0 && _info.indexOf("Win") > 0 && _info.indexOf("Windows 3.1") < 0); 
//--> 
</script> 

<comment><script language="javascript1.1"><!-- 
var _ns = (navigator.appName.indexOf("Netscape") >=0 && 
((_info.indexOf("Win") > 0 || (_info.indexOf("Win16") < 0 && 
java.lang.System.getProperty ("os.version").indexOf("3.5") < 0) || 
(_info.indexOf("Sun") > 0) || (ibdex.Of("Linux") > 0))); 
//--></script></comment> 

<script language="javascript"><!-- 
if (_ie == true) document.writeln('<OBJECT classid = "clsid:8AD9C840-044E-11D1-B3E9-0080F499F93" 
width = 400 heigth = 200 codebase="http://java.sun.com/products/plugin/1.1.1/jinstall-111-win2.cab#Version=1,1,1,0"> 
<NOEMBED><XMP>') 
else if (_ns == true)document.writeln('<EMBED type="aplication/x-java-applet;version=1.1" java_CODE = WelcomeApplet.class width = 400 heigth = 200 greeting = "Welcome to Core Java" 
pluginspage="http://java.sun.com/products/plugin/1.1.1/plugin-install.html"><NOEMBED><XMP>'); 
//--><script> 
<applet code = WelcomeApplet.class width = 400 heigth = 200> 
</XMP> 
<param name = code value = WelcomeApplet.class> 

<param name="type" value="aplication/x/java-applet;version=1.1"> 
<param name = greeting value"Welcome To Core Java!"> 
</applet> 

<!-- 
<applet code = WlcomeApplet.class width = 400 heigth = 200> 
<param name = greeting value"Welcome To Core Java!"> 
</applet> 
--> 
<!--"END_CONVERT_APPLET"--> 
</hr> 
<a href="WelcomeApplet.java">The Source.</a> 

</bobdy> 
</html> 

import javax.swing.*; 
import java.applet.*; 
import java.awt.*; 
import java.awt.event.*; 
import java.net.*; 

public class WelcomeApplet extends JApplet 
implements ActionListener 
{ public void init(){ 

Container contentPane = getContentPane(); 
contentPane.setLayout(new BorderLayout()); 
JLabel label = new JLabel(getParameter("greeting"), SwingConstants.CENTER); 
label.setFont(new Font("TimesRoman", Font.BOLD, 1); 
contentPane.add(label, 0); 
JPanel panel = new JPanel(); 
cayButton = new JButton("Cay Horsmann"); 
cayButton.addActionListener(this); 
panel.add(cayButton); 
garyButton = new JButton("Gary Cornell"); 
garyButton.addActionListener(this); 
panel.add(garyButton); 
contentPane.add(label, 0); 
} 

public void actionPerformed(ActionEvent evt){ 

Object source = evt.getSource(); 
String urlName; 
if (source == cayButton) 
urlName = "http//www.horstmann.com"; 
else if (source == garyButton) 
urlName = "mailto:[email removido]"; 
else return; 

try { 
URL u = new URL(urlName); 
getAppletContext().showDocument(u); 
} catch(Exception e){ 
showStatus("Error" + e); 
} 

} 

private JButton cayButton; 
private JButton garyButton; 
}

2 Respostas

ViniGodoy

Por favor, ponha seus códigos entre as tags code:

seu código

Uma forma fácil de fazer isso é selecionar o código todo e clicar em “Code”, na barra de botões.

ViniGodoy

Outra coisa, não duplique tópicos:
http://www.guj.com.br/posts/list/197331.java

Esse aqui será trancado, já que o outro está mais respondido.

Criado 18 de fevereiro de 2010
Ultima resposta 18 de fev. de 2010
Respostas 2
Participantes 2