Ciao a tutti, ho queste due classi seguenti:
Sulla classe NuovoAggiungi mi da errore enclosing sulle righe: Nuovo.this.nome....
qualcuno sa aiutarmi??
e questa:
Sulla classe NuovoAggiungi mi da errore enclosing sulle righe: Nuovo.this.nome....
qualcuno sa aiutarmi??
Java:
import java.awt.Button;
import java.awt.GridLayout;
import java.awt.TextField;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.Scanner;
import javax.swing.JFrame;
import javax.swing.JFrame;
class Nuovo extends JFrame {
TextField nome = new TextField(50);
Button aggiungi = new Button("Aggiungi");
public Nuovo() {
super("Nuovo");
this.nome.setText("Aggiungi nome e numero di telefono");
this.aggiungi.addActionListener(new aggiungi());
setLayout(new GridLayout(2, 1));
add(this.nome);
add(this.aggiungi);
pack();
show();
}
class aggiungi implements ActionListener {
public void actionPerformed(ActionEvent e) {
String name = new String();
Nuovo.this.nome.selectAll();
String line = new String();
String aux = new String();
try {
File file = new File("C:/Rubrica.txt");
FileReader reader = new FileReader(file);
Scanner in = new Scanner(reader);
char c = '\n';
aux = "";
while (in.hasNextLine()) {
line = in.nextLine();
aux = String.valueOf(aux) + line + c;
}
reader.close();
} catch (IOException j) {
j.printStackTrace();
}
name = Nuovo.this.nome.getSelectedText();
try {
File doc = new File("C:/Rubrica.txt");
doc.createNewFile();
FileWriter fw = new FileWriter(doc);
fw.write(String.valueOf(aux) + name);
fw.flush();
fw.close();
} catch (IOException j) {
j.printStackTrace();
}
}
}
}
e questa:
Java:
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.Scanner;
class NuovoAggiungi implements ActionListener {
public void actionPerformed(ActionEvent e) {
String name = new String();
Nuovo.this.nome.selectAll();
String line = new String();
String aux = new String();
try {
File file = new File("C:/Rubrica.txt");
FileReader reader = new FileReader(file);
Scanner in = new Scanner(reader);
char c = '\n';
aux = "";
while (in.hasNextLine()) {
line = in.nextLine();
aux = String.valueOf(aux) + line + c;
}
reader.close();
} catch (IOException j) {
j.printStackTrace();
}
name = Nuovo.this.nome.getSelectedText();
try {
File doc = new File("C:/Rubrica.txt");
doc.createNewFile();
FileWriter fw = new FileWriter(doc);
fw.write(String.valueOf(aux) + name);
fw.flush();
fw.close();
} catch (IOException j) {
j.printStackTrace();
}
}
}