Jump to content
alphasil

Erro no actioneventlsitener

Recommended Posts

alphasil

Olá

Tenho um erro que não consigo resolver o porquê, alguém pode ajudar-me?

import java.applet.Applet;
import java.awt.Button;
import java.awt.Graphics;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Label;
import java.awt.TextField;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.text.NumberFormat;


public class Applet_media extends Applet
{

 TextField n1, n2, n3;
 double a, b;
 NumberFormat nf;
 Button calc;

public void init() {
   // Uso do grid layout.
   GridBagLayout gbag = new GridBagLayout();
   GridBagConstraints gbc = new GridBagConstraints();
   setLayout(gbag);

   Label heading = new Label("Média");
   Label media = new Label("Nota 1");
   Label media1 = new Label("Nota 2");
   Label mediaTotal = new Label("Média Final");


   n1 = new TextField(16);
   n2 = new TextField(16);
   n3 = new TextField(16);

   // Campo não editável.
   n3.setEditable(false);

   calc = new Button("Calcular");



 // Define the grid bag.
   gbc.weighty = 1.0; // use a row weight of 1
   gbc.gridwidth = GridBagConstraints.REMAINDER;
   gbc.anchor = GridBagConstraints.NORTH;
   gbag.setConstraints(heading, gbc);

   // Anchor most components to the right.
   gbc.anchor = GridBagConstraints.EAST;

   gbc.gridwidth = GridBagConstraints.RELATIVE;
   gbag.setConstraints(media, gbc);
   gbc.gridwidth = GridBagConstraints.REMAINDER;
   gbag.setConstraints(n1, gbc);

   gbc.gridwidth = GridBagConstraints.RELATIVE;
   gbag.setConstraints(media1, gbc);
   gbc.gridwidth = GridBagConstraints.REMAINDER;
   gbag.setConstraints(n2, gbc);

   gbc.gridwidth = GridBagConstraints.RELATIVE;
   gbag.setConstraints(mediaTotal, gbc);
   gbc.gridwidth = GridBagConstraints.REMAINDER;
   gbag.setConstraints(n3, gbc);


   // Adiciona os componentes.
   add(heading);
   add(media);
   add(n1);
   add(media1);
   add(n2);
   add(mediaTotal);
   add(n3);
   add(calc);

   //Accões;
   n1.addActionListener(this);
   n2.addActionListener(this);
   calc.addActionListener(this)

   //Conversão de dígitos para 2 casas decimais
   nf = NumberFormat.getInstance();
   nf.setMinimumFractionDigits(2);
   nf.setMaximumFractionDigits(2);
}

 /*
  * User pressed Enter on a text field or pressed Compute.
  */
 public void actionPerformed(ActionEvent ae) {
   repaint();
 }

    // Display the result if all fields are completed.
 public void paint(Graphics g) {
   double result = 0.0;

   String n1Str = n1.getText();
   String n2Str = n2.getText();

   a = Double.parseDouble(n1Str);
   b = Double.parseDouble(n2Str);
   result = (a+b)/2;

   n3.setText(nf.format(result));

}
}

O erro é nestas linhas

//Accões;

n1.addActionListener(this);

n2.addActionListener(this);

calc.addActionListener(this)

Obrigado


gmc11

 

Share this post


Link to post
Share on other sites
brunoais

E o erro é:


"[Os jovens da actual geração]não lêem porque não envolve um telecomando que dê para mirar e atirar, não falam porque a trapalhice é rainha e o calão é rei" autor: thoga31

Life is a genetically transmitted disease, induced by sex, with death rate of 100%.

Share this post


Link to post
Share on other sites
alphasil

Desculpa...n pus ;)

The method addActionListener(java.awt.event.ActionListener) in the type java.awt.Textfield is not applicable for the arguments

Não percebo


gmc11

 

Share this post


Link to post
Share on other sites
brunoais

Applet_media não implementa java.awt.event.ActionListener


"[Os jovens da actual geração]não lêem porque não envolve um telecomando que dê para mirar e atirar, não falam porque a trapalhice é rainha e o calão é rei" autor: thoga31

Life is a genetically transmitted disease, induced by sex, with death rate of 100%.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.