Sto cercando di creare un' applet java per far mettere dei commenti ai post pubblicati sulla nuova versione del mio sito.. pensavo di mettere un' applet e non uno script in php soprattutto per ovviare al problema dello spam.. ma anche per esercitarmi un po' con il java... ho trovato questo sito che spiega come scrivere su file txt...
ho creato prima questo programma per provare se funzionava
e poi ho cercato di trasformarlo in un' appletCodice:import java.io.*; import javax.swing.*; public class commenti2 { public static void main(String[] args) throws IOException { //prima di tutto faccio leggere il numero del commento BufferedReader fileread = new BufferedReader(new FileReader("commenti/numero")); String num; int num1, numero; num=fileread.readLine(); numero=Integer.parseInt(num); num1=numero+1; fileread.close(); //chiude il file //Adesso scrivo nel file numero il nuovo numero FileWriter nuovonum = new FileWriter("commenti/numero"); BufferedWriter nuovonumbuffer = new BufferedWriter(nuovonum); PrintWriter printnuovonum = new PrintWriter(nuovonumbuffer); printnuovonum.println( num1 ); printnuovonum.close(); //Adesso scrivo il commento nel file apposito FileWriter fileout = new FileWriter("commenti/commento" + num1); BufferedWriter filewrite = new BufferedWriter(fileout); PrintWriter printout = new PrintWriter(filewrite); String testo; testo = JOptionPane.showInputDialog("Inserisci un commento "); printout.println( testo ); printout.close(); JOptionPane.showMessageDialog( null, ""+ num1); System.exit( 0 ); } }
Ma il compilatore da questi errori:Codice:import java.io.*; import javax.swing.*; public class commentiapplet extends JApplet { public void init() throws IOException { //prima di tutto faccio leggere il numero del commento BufferedReader fileread = new BufferedReader(new FileReader("commenti/numero")); String num; int num1, numero; num=fileread.readLine(); numero=Integer.parseInt(num); num1=numero+1; fileread.close(); //chiude il file //Adesso scrivo nel file numero il nuovo numero FileWriter nuovonum = new FileWriter("commenti/numero"); BufferedWriter nuovonumbuffer = new BufferedWriter(nuovonum); PrintWriter printnuovonum = new PrintWriter(nuovonumbuffer); printnuovonum.println( num1 ); printnuovonum.close(); //Adesso scrivo il commento nel file apposito FileWriter fileout = new FileWriter("commenti/commento" + num1); BufferedWriter filewrite = new BufferedWriter(fileout); PrintWriter printout = new PrintWriter(filewrite); String testo; Container c= getContentPane(); c.setLayout( new FlowLayout() ); Label = new JLabel ( "Scrivi qui sotto il tuo commento a questo post" ); c.add(Label); testo = new JTextField( 50 ); c.add(testo); printout.println( testo ); printout.close(); System.exit( 0 ); } }
Credo di aver sbagliato nella creazione del metodo init ma non so come correggere l' errore... qualcuno ha suggerimenti?Codice:Found 6 semantic errors compiling "commentiapplet.java": 5. public void init() throws IOException { ^----^ *** Semantic Error: The checked exception "IOException" is not assignable to any exception in the throws clause of the accessible method "void init();" declared in type "java.applet.Applet". 28. Container c= getContentPane(); ^-------^ *** Semantic Error: Type "Container" was not found. 29. c.setLayout( new FlowLayout() ); ^--------^ *** Semantic Error: Type "FlowLayout" was not found. 31. Label = new JLabel ( "Scrivi qui sotto il tuo commento a questo post" ); ^---^ *** Semantic Error: No accessible field named "Label" was found in type "commentiapplet". 32. c.add(Label); ^---^ *** Semantic Error: No accessible field named "Label" was found in type "commentiapplet". 33. testo = new JTextField( 50 ); ^--------------------------^ *** Semantic Error: The type of the right sub-expression, "javax.swing.JTextField", is not assignable to the variable, of type "java.lang.String".

LinkBack URL
About LinkBacks

