Archived

This topic is now archived and is closed to further replies.

Barnabe

java thing

Recommended Posts

Barnabe    122
hail.. I am trying to make a textfield receive a valor from a double with the code:
 prox.addActionListener(
      new ActionListener(){
            valor.setText("0.00");
            abat.setText("0.00");
            deduc.setText("0.00");
    	    juros.setText("0.00");
    	    acresc.setText("0.00");
    	    vfinal.setText("0.00");            
      });   
and it shows me the message: C:\Meus documentos\Fatura.java:50: expected \\\\\\\\\\\\valor.setText("0.00"); \\\\\\\\\\\\\\\\\\\\\\\\\^ ignore the bar(\) what is wrong in this code?? thanks in advance... Farewell, _______________________ Barnabé, The Adventurer

Share this post


Link to post
Share on other sites
fractoid    703
You missed a line or two:

prox.addActionListener(
new ActionListener(){
public void actionPerformed(ActionEvent e) { //new line

valor.setText("0.00");
abat.setText("0.00");
deduc.setText("0.00");
juros.setText("0.00");
acresc.setText("0.00");
vfinal.setText("0.00");
} //new line

});

Share this post


Link to post
Share on other sites
Barnabe    122
but I am not working with handler or something like that...
the problem is about make the text getting into the TextFields...
the problem is not about make the button read the click event.. if you are talking about ActionEvent and such...
but thanks anyway..
I am still waiting for help...

Farewell,

_______________________
Barnabé, The Adventurer

Share this post


Link to post
Share on other sites
Malone1234    139
We need to see some more code then. How about the rest of the class definition for the class that this anonymous inner ActionListener class resides in.

What is prox?
Where are valor, abat, etc declared?
If you want the ActionListener to place those values in your text fields when you click on a button, you are going to need the actionPerformed(...) line that fractoid showed you.

Share this post


Link to post
Share on other sites
Barnabe    122
Ok.. this is the whole code.. the labels are in portuguese since I am from Brazil.. but it doesn''t matter.. this program was supose to be very simple.. but I don''t know why it doesn''t work.. I guess there is something missing afterall..
I should start learn c++ but by some how I am still trying java.. oh well.. this is the code:


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

public class Fatura extends JFrame{
private JTextField valor,abat,deduc,juros,acresc,vfinal;
private JButton calc,prox;
public Fatura(){
super("PAGAMENTO DE TITULOS");
Container pane=getContentPane();
pane.setLayout(new GridLayout(7,2));
pane.add(new JLabel("Valor do Documento(R$)"));
valor=new JTextField(10);
valor.setHorizontalAlignment(JTextField.RIGHT);
pane.add(valor);
pane.add(new JLabel("Desconto / Abatimento(R$)"));
abat=new JTextField(10);
valor.setHorizontalAlignment(JTextField.RIGHT);
pane.add(abat);
pane.add(new JLabel("Outras deduções(R$)"));
deduc=new JTextField(10);
valor.setHorizontalAlignment(JTextField.RIGHT);
pane.add(deduc);
pane.add(new JLabel("Juros / Multa(R$)"));
juros=new JTextField(10);
valor.setHorizontalAlignment(JTextField.RIGHT);
pane.add(juros);
pane.add(new JLabel("Outros acrécimos(R$)"));
acresc=new JTextField(10);
valor.setHorizontalAlignment(JTextField.RIGHT);
pane.add(acresc);
calc=new JButton("Calcula Fatura");
pane.add(calc);
prox=new JButton("Proxima Fatura");
pane.add(prox);
calc.add.ActionListener(
new ActionListener(){
double a=Double.ParseInt(valor.getText);
double b=Double.ParseInt(abat.getText);
double c=Double.ParseInt(deduc.getText);
double d=Double.ParseInt(juros.getText);
double e=Double.ParseInt(acresc.getText);
double vf=(a-b+c+d+e);
vfinal.setText(vf);
});
prox.addActionListener(
new ActionListener(){
valor.setText("0.00");
abat.setText("0.00");
deduc.setText("0.00");
juros.setText("0.00");
acresc.setText("0.00");
vfinal.setText("0.00");
});
pane.add(new JLabel("Valor Cobrado(R$)"));
vfinal=new JTextField(10);
valor.setHorizontalAlignment(JTextField.RIGHT);
pane.add(vfinal);
setSize(300,200);
setLocation(200,100);
setVisible(true);
}
public static void main(String[]ARG){
Fatura app=new Fatura();
app.DefaultCloseOperation(EXIT_ON_CLOSE);
}
}


help me please...
thanks in advance..

Farewell,


_______________________
Barnabé, The Adventurer

Share this post


Link to post
Share on other sites
Matei    190
You do have to write addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e) { ... } }). It's not like you can just magically paste code in the body of the new AcitonListener and it will run. What you're doing is creating an anonymous inner class which extends ActionListener, then overriding its actionPerormed method.

I suggest writing your program in small steps and compiling and running after each small change so you don't run into problems. Otherwise, the compiler errors will seem confusing.


[edited by - Matei on May 27, 2004 9:03:51 PM]

Share this post


Link to post
Share on other sites