Problemas com Applets

3 respostas
D_Goulart

Salve, salve!!!

Estou com um pequeno probleminha com o Java Applet.

Tenho q fazer um applet q some 4 notas e que ao clicar no botão calcular, exiba uma mensagem se o cara foi aprovado ou reprovado. Eu já comecei a fazer, mas só q ao clicar no resultado, aparece escrito no botão. E outra, como eu faço pra ordenar labels e textfields?

Me ajudem aí, por favor!!!

Aguardo respostas!!!

:x

3 Respostas

D

Posso ver o código???

Eu estudo programação e não adivinhação.

D_Goulart

Esta aí meu camarada:

import java.awt.;
import java.applet.
;

public class Bimestre extends Applet {

Label nota1;

Label nota2;

Label nota3;

Label nota4;

Label TRotulo;
TextField texto1;
TextField texto2;
TextField texto3;
TextField texto4;

Button button1;

public void init(){
    nota1 = new Label("Digite a nota1:",Label.LEFT);
    add(nota1);
    texto1 = new TextField(10);
    add(texto1);

    nota2 = new Label("Digite a nota2:",Label.RIGHT);
    add(nota2);
    texto2 = new TextField(10);
    add(texto2);

    nota3 = new Label("Digite a nota3:", Label.LEFT);
    add(nota3);
    texto3 = new TextField(10);
    add(texto3);

    nota4 = new Label("Digite a nota4:", Label.LEFT);
    add(nota4);
    texto4 = new TextField(10);
    add(texto4);

    button1 = new Button("Cálculo");
    add(button1);             
}

@Override
public boolean action (Event evt, Object arg){
    if(evt.target instanceof Button)
        CliqueBotao(arg);
    return true;
}
protected void CliqueBotao(Object Label){
    float n1,n2,n3,n4;
    float media;
    
    n1 = Float.parseFloat(texto1.getText());
    n2 = Float.parseFloat(texto2.getText());
    n3 = Float.parseFloat(texto3.getText());
    n4 = Float.parseFloat(texto4.getText());

    media = (n1+n2+n3+n4)/4;

    if(media >=7){
        button1.setLabel("*** Aluno Aprovado ***");
    } else {
    if (media <=5){
        button1.setLabel("*** Aluno Reprovado ***");
         
    }
   
}
}

}

// feito no netbeans 6.9.1

D
D. Goulart:
Esta aí meu camarada:

import java.awt.*;
import java.applet.*;

public class Bimestre extends Applet {
Label nota1;
Label nota2;
Label nota3;
Label nota4;
Label TRotulo;

TextField texto1;
TextField texto2;
TextField texto3;
TextField texto4;

Button button1;

public void init(){
nota1 = new Label("Digite a nota1:",Label.LEFT);
add(nota1);
texto1 = new TextField(10);
add(texto1);

nota2 = new Label("Digite a nota2:",Label.RIGHT);
add(nota2);
texto2 = new TextField(10);
add(texto2);

nota3 = new Label("Digite a nota3:", Label.LEFT);
add(nota3);
texto3 = new TextField(10);
add(texto3);

nota4 = new Label("Digite a nota4:", Label.LEFT);
add(nota4);
texto4 = new TextField(10);
add(texto4);

button1 = new Button("Cálculo");
add(button1);
}

@Override
public boolean action (Event evt, Object arg){
if(evt.target instanceof Button)
CliqueBotao(arg);
return true;
}
protected void CliqueBotao(Object Label){
float n1,n2,n3,n4;
float media;

n1 = Float.parseFloat(texto1.getText());
n2 = Float.parseFloat(texto2.getText());
n3 = Float.parseFloat(texto3.getText());
n4 = Float.parseFloat(texto4.getText());

media = (n1+n2+n3+n4)/4;

if(media >=7){
button1.setLabel("*** Aluno Aprovado ***");
} else {
if (media <=5){
button1.setLabel("*** Aluno Reprovado ***");

}

}
}
}

// feito no netbeans 6.9.1

Coloque em tag para ficar mais visível veja:

import java.awt.*;
import java.applet.*;

public class Bimestre extends Applet {
    Label nota1;
    Label nota2;
    Label nota3;
    Label nota4;
    Label TRotulo;

    TextField texto1;
    TextField texto2;
    TextField texto3;
    TextField texto4;

    Button button1;

    public void init(){
        nota1 = new Label(&quot;Digite a nota1:&quot;,Label.LEFT);
        add(nota1);
        texto1 = new TextField(10);
        add(texto1);

        nota2 = new Label(&quot;Digite a nota2:&quot;,Label.RIGHT);
        add(nota2);
        texto2 = new TextField(10);
        add(texto2);

        nota3 = new Label(&quot;Digite a nota3:&quot;, Label.LEFT);
        add(nota3);
        texto3 = new TextField(10);
        add(texto3);

        nota4 = new Label(&quot;Digite a nota4:&quot;, Label.LEFT);
        add(nota4);
        texto4 = new TextField(10);
        add(texto4);

        button1 = new Button(&quot;Cálculo&quot;);
        add(button1);             
    }

    @Override
    public boolean action (Event evt, Object arg){
        if(evt.target instanceof Button)
            CliqueBotao(arg);
        return true;
    }
    protected void CliqueBotao(Object Label){
        float n1,n2,n3,n4;
        float media;
        
        n1 = Float.parseFloat(texto1.getText());
        n2 = Float.parseFloat(texto2.getText());
        n3 = Float.parseFloat(texto3.getText());
        n4 = Float.parseFloat(texto4.getText());

        media = (n1+n2+n3+n4)/4;

        if(media &gt;=7){
            button1.setLabel(&quot;*** Aluno Aprovado ***&quot;);
        } else {
        if (media &lt;=5){
            button1.setLabel(&quot;*** Aluno Reprovado ***&quot;);
             
        }
       
    }
    }
}

Ai fica mais fácil ver e seu programa esta certo, mais trate da sintaxe dele. Ta com muitos erros.

Criado 13 de setembro de 2010
Ultima resposta 14 de set. de 2010
Respostas 3
Participantes 2