Re: [ Beginner ] Code Errors
Quote:
Originally Posted by tima
I'm trying this code but unfortunately it is not working. Would someone
help me find the errors ?
Can I persuade you to say in what way it isn't working?
From what I can see the code won't even compile.
If you are getting compiler errors, post up the full text of the error messages. Java error messages usually tell you exactly what's wrong.
If you are getting run time errors, post up the errors and the actual code you are using, because it can't be what you just posted.
If it gives no errors but just doesn't work, explain what isn't working and post the actual code you run.
Mistakes are the portals of discovery...
J. Joyce
Re: [ Beginner ] Code Errors
Error #: 204: illegal start of expression at line 53, column 3
Error #: 206: malformed expression at line 49, column 3
The lines are highlighted in the code .
Re: [ Beginner ] Code Errors
Well that's odd - the error messages you posted didn't look right, so I compiled the code you posted and got these (with both Java 1.4.2 and 1.5):
Quote:
Information:Compilation completed with 2 errors and 0 warnings
Information:2 errors
Information:0 warnings
H:\Source\TEMP\src\untitled5\Echange.java
Error:Error:line (46)illegal start of expression
Error:Error:line (62)';' expected
The first is because you are declaring the actionPerformed method in the middle of the Echange constructor. Java doesn't allow methods to be declared inside methods. The second error is a result of the first error messing up the code structure.
Are you using Sun's standard javac compiler?
There are other errors in the code, e.g. FlowLayout doesn't have a constructor that takes 2 ints.
Act in haste and repent at leisure; code too soon and debug forever...
R. Kennington
Re: [ Beginner ] Code Errors
My version is JBuilder 4.0.152.0.
Thx a lot dlorde, it finally worked ! I* really appreciate your time and
ur kind cooperation :)
Here's the right code:
Code:
package untitled5;
import java.awt.*;
import java.awt.event.*;
public class Echange extends Frame implements ActionListener {
Label l1=new Label("text1");
TextField t1=new TextField(20);
Label l2=new Label("text2");
TextField t2=new TextField(20);
Button ef=new Button("Effacer");
Button ech=new Button("Echanger");
Button fin=new Button("Fin");
public Echange(){
Panel p1=new Panel();
Panel p2=new Panel();
GridLayout g=new GridLayout(2,2);
FlowLayout f=new FlowLayout(FlowLayout.LEFT,1,3);
p1.setLayout(g);
p2.setLayout(f);
p1.add(l1);
p1.add(t1);
p1.add(l2);
p1.add(t2);
p2.add(ef);
p2.add(ech);
p2.add(fin);
ef.addActionListener(this);
ech.addActionListener(this);
fin.addActionListener(this);
BorderLayout b=new BorderLayout();
this.setLayout(b);
this.add("North",p1);
this.add("Center",p2);
pack();
show();
addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent e){
System.exit(0);
}});
}
public void actionPerformed(ActionEvent e){
if(e.getSource()==ef){
t1.setText(" ");
t2.setText(" ");
}
else
if(e.getSource()==ech){
String s;
s=t1.getText();
t1.setText(t2.getText());
t2.setText(s);
}
else if(e.getSource()==fin){
System.exit(0);
}
}
public static void main(String[] args) {
new Echange();
}
}