Olá.
Amigo, deveria funcionar normalmente como se usa uma Applet mesmo num HTML simples. Você tentou e deu algum erro pra você?
retificando...
Deveria funcionar normalmente como quando se usa uma Applet mesmo num HTML simples
ola amigos.
não deu certo eu nunca usei applet por isso não sei onde posso estar usando
<applet code="classe2.class" width="320" height="80" name="classe2">
public class Classe2 extends JApplet{
@Override
public void paint(Graphics g){
super.paint(g);
Graphics2D g2d = (Graphics2D) g.create();
g2d.drawString("ALO MUNDO", 100, 20);
g2d.dispose();
}
}
não aparece nada alguém sabe o que pode ser?
Não deveria ser "Classe2.class" ao invés de "classe2.class"?
então ja tentei de tudo um pouco eu nunca usei por isso fico meio sem saber o que pode dar errado.
no log de erro fala que não encontra a classe que estou chamando
log de erro
carregar: classe arquivo.applet.class não encontrada.
java.lang.ClassNotFoundException: arquivo.applet.class
at sun.plugin2.applet.Applet2ClassLoader.findClass(Applet2ClassLoader.java:252)
at sun.plugin2.applet.Plugin2ClassLoader.loadClass0(Plugin2ClassLoader.java:250)
at sun.plugin2.applet.Plugin2ClassLoader.loadClass(Plugin2ClassLoader.java:180)
at sun.plugin2.applet.Plugin2ClassLoader.loadClass(Plugin2ClassLoader.java:161)
at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
at sun.plugin2.applet.Plugin2ClassLoader.loadCode(Plugin2ClassLoader.java:687)
at sun.plugin2.applet.Plugin2Manager.createApplet(Plugin2Manager.java:3025)
at sun.plugin2.applet.Plugin2Manager$AppletExecutionRunnable.run(Plugin2Manager.java:1498)
at java.lang.Thread.run(Thread.java:662)
Exceção: java.lang.ClassNotFoundException: arquivo.applet.clas
tag na GSP
<applet codebase="classes" code="arquivo.applet.class" width=350 height=200></applet>
ou
<applet codebase="classes" code="applet.class" width=350 height=200></applet>
applet com interface
public class applet extends javax.swing.JApplet {
/** Initializes the applet applet */
@Override
public void init() {
/* Set the Nimbus look and feel */
//<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
/* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
* For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
*/
try {
for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
if ("Nimbus".equals(info.getName())) {
javax.swing.UIManager.setLookAndFeel(info.getClassName());
break;
}
}
} catch (ClassNotFoundException ex) {
java.util.logging.Logger.getLogger(applet.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(applet.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(applet.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(applet.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
}
//</editor-fold>
/* Create and display the applet */
try {
java.awt.EventQueue.invokeAndWait(new Runnable() {
public void run() {
initComponents();
}
});
} catch (Exception ex) {
ex.printStackTrace();
}
}
/** This method is called from within the init() method to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {
jButton1 = new javax.swing.JButton();
jButton2 = new javax.swing.JButton();
jLabel1 = new javax.swing.JLabel();
jButton1.setText("color 1");
jButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton1ActionPerformed(evt);
}
});
jButton2.setText("color 2");
jButton2.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton2ActionPerformed(evt);
}
});
jLabel1.setFont(new java.awt.Font("DejaVu Sans", 1, 24));
jLabel1.setText("color");
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(38, 38, 38)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jLabel1)
.addGroup(layout.createSequentialGroup()
.addComponent(jButton1)
.addGap(38, 38, 38)
.addComponent(jButton2)))
.addContainerGap(214, Short.MAX_VALUE))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(56, 56, 56)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jButton1)
.addComponent(jButton2))
.addGap(37, 37, 37)
.addComponent(jLabel1)
.addContainerGap(151, Short.MAX_VALUE))
);
}// </editor-fold>
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
jLabel1.setForeground(Color.BLUE);
jLabel1.setText("OLA MUNDO");
}
private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
jLabel1.setForeground(Color.RED);
jLabel1.setText("teste 2");
}
// Variables declaration - do not modify
private javax.swing.JButton jButton1;
private javax.swing.JButton jButton2;
private javax.swing.JLabel jLabel1;
// End of variables declaration
}
applet sem interface
public class Teste extends JApplet {
public void paint(Graphics g) {
g.drawString("Alô Pessoal!", 100, 20);
}
}
Amigo,
não tem segredo.
1. Crie sua classe com primeira letra maiúscula, "como manda a cartilha"
2. Não declare a classe em pacote algum (sem "package ..." na primeira linha)
3. Coloque o arquivo ".class" e não o ".java" na mesma pasta do .gsp
Não tem como não funcionar. Fiz aqui um teste e funcinou perfeitamente ;)