package confronto;
import java.awt.Color;
import java.io.*;
import javax.swing.*;
/**
*
* @author Oxen Eknat
*/
public class confrontoTesti extends javax.swing.JFrame {
/**
* Creates new form confrontoTesti
*/
public confrontoTesti() {
initComponents();
}
/**
*
* @param percorsoIniziale is the string that contains the folder of the unedited file
* @param percorsoFinale is the string that contains the folder where the edited file will be put in
*/
public static void modificaTesto (String percorsoIniziale, String percorsoFinale){
try{
FileReader f= new FileReader(percorsoIniziale);
String a=f.toString();
int l = a.length();
for (int i=0; i<l; i++){
char c1 = a.charAt(i);
String n = "";
if (c1=='1'|c1=='2'|c1=='3'|c1=='4'|c1=='5'|c1=='6'|c1=='7'|c1=='8'|c1=='9'|c1=='0'){
do{
n += c1;
i++;
c1 = a.charAt(i);
} while (c1=='1'|c1=='2'|c1=='3'|c1=='4'|c1=='5'|c1=='6'|c1=='7'|c1=='8'|c1=='9'|c1=='0');
}
int n1 = Integer.getInteger(n);
try{
try (PrintWriter writer = new PrintWriter(percorsoFinale, "UTF-8")) {
writer.println(n1);
}
}
catch(FileNotFoundException | UnsupportedEncodingException errore1){
JOptionPane.showMessageDialog(null,"Errore imprevisto! Errore:" + errore1 ,"ERRORE!",JOptionPane.ERROR_MESSAGE);
}
}
}
catch(FileNotFoundException errore){
JOptionPane.showMessageDialog(null,"Errore imprevisto! Errore:" + errore ,"ERRORE!",JOptionPane.ERROR_MESSAGE);
}
}
/**
* This method is called from within the constructor to initialize the form.
* WARNING: Do NOT modify this code. The content of this method is always
* regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {
jTextField2 = new javax.swing.JTextField();
jTextField1 = new javax.swing.JTextField();
jButton1 = new javax.swing.JButton();
jTextField3 = new javax.swing.JTextField();
jButton2 = new javax.swing.JButton();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
jTextField2.setEditable(false);
jTextField2.setFont(new java.awt.Font("Times New Roman", 0, 24)); // NOI18N
jTextField2.setHorizontalAlignment(javax.swing.JTextField.CENTER);
jTextField2.setText("CONFRONTO");
jTextField2.setBorder(null);
jTextField2.setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
jTextField2.setFocusable(false);
jTextField2.setHighlighter(null);
jTextField2.setOpaque(false);
jTextField2.setSelectedTextColor(new java.awt.Color(0, 0, 0));
jTextField2.setSelectionColor(new java.awt.Color(240, 240, 240));
jTextField1.setFont(new java.awt.Font("Tahoma", 2, 11)); // NOI18N
jTextField1.setText("percorso del file");
jTextField1.setCursor(new java.awt.Cursor(java.awt.Cursor.TEXT_CURSOR));
jTextField1.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
jTextField1MouseClicked(evt);
}
public void mouseEntered(java.awt.event.MouseEvent evt) {
jTextField1MouseEntered(evt);
}
});
jTextField1.addKeyListener(new java.awt.event.KeyAdapter() {
public void keyPressed(java.awt.event.KeyEvent evt) {
jTextField1KeyPressed(evt);
}
});
jButton1.setText("Verifica!");
jButton1.setToolTipText("");
jButton1.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
jButton1MouseClicked(evt);
}
});
jTextField3.setFont(new java.awt.Font("Tahoma", 2, 11)); // NOI18N
jTextField3.setText("percorso del nuovo file");
jTextField3.setCursor(new java.awt.Cursor(java.awt.Cursor.TEXT_CURSOR));
jTextField3.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
jTextField3MouseClicked(evt);
}
public void mouseEntered(java.awt.event.MouseEvent evt) {
jTextField3MouseEntered(evt);
}
});
jTextField3.addKeyListener(new java.awt.event.KeyAdapter() {
public void keyPressed(java.awt.event.KeyEvent evt) {
jTextField3KeyPressed(evt);
}
});
jButton2.setText("Crea il nuovo file!");
jButton2.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
jButton2MouseClicked(evt);
}
});
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jButton2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(jButton1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(jTextField2, javax.swing.GroupLayout.DEFAULT_SIZE, 380, Short.MAX_VALUE)
.addComponent(jTextField1)
.addComponent(jTextField3))
.addContainerGap())
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(19, 19, 19)
.addComponent(jTextField2, javax.swing.GroupLayout.PREFERRED_SIZE, 42, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jButton1)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jTextField3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jButton2, javax.swing.GroupLayout.PREFERRED_SIZE, 82, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(65, 65, 65))
);
pack();
}// </editor-fold>
private void jTextField1MouseClicked(java.awt.event.MouseEvent evt) {
jTextField1.setFont(new java.awt.Font("Tahoma", 0, 11));
jTextField1.setForeground(Color.black);
jTextField1.setText("");
}
private void jTextField1KeyPressed(java.awt.event.KeyEvent evt) {
}
private void jTextField1MouseEntered(java.awt.event.MouseEvent evt) {
}
private void jButton1MouseClicked(java.awt.event.MouseEvent evt) {
String percorso;
percorso=jTextField1.getText();
try {
FileReader f= new FileReader(percorso);
}
catch (FileNotFoundException errore){
jTextField1.setFont(new java.awt.Font("Tahoma", 2, 11));
jTextField1.setForeground(Color.red);
jTextField1.setText("Errore: percorso non valido");
}
}
private void jTextField3MouseClicked(java.awt.event.MouseEvent evt) {
jTextField3.setFont(new java.awt.Font("Tahoma", 0, 11));
jTextField3.setForeground(Color.black);
jTextField3.setText("");
}
private void jTextField3MouseEntered(java.awt.event.MouseEvent evt) {
// TODO add your handling code here:
}
private void jTextField3KeyPressed(java.awt.event.KeyEvent evt) {
// TODO add your handling code here:
}
private void jButton2MouseClicked(java.awt.event.MouseEvent evt) {
String percorsoIniziale=jTextField1.getText();
String percorsoFinale=jTextField3.getText();
modificaTesto (percorsoIniziale, percorsoFinale);
}
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
/* Set the Nimbus look and feel */
//<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
/* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
* For details see [url=http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html]How to Set the Look and Feel (The Java™ Tutorials > Creating a GUI With JFC/Swing > Modifying the Look and Feel)[/url]
*/
try {
for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
if ("Nimbus".equals(info.getName())) {
javax.swing.UIManager.setLookAndFeel(info.getClassName());
break;
}
}
} catch (ClassNotFoundException ex) {
java.util.logging.Logger.getLogger(confrontoTesti.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(confrontoTesti.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(confrontoTesti.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(confrontoTesti.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
}
//</editor-fold>
/* Create and display the form */
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new confrontoTesti().setVisible(true);
}
});
}
// Variables declaration - do not modify
private javax.swing.JButton jButton1;
private javax.swing.JButton jButton2;
private javax.swing.JTextField jTextField1;
private javax.swing.JTextField jTextField2;
private javax.swing.JTextField jTextField3;
// End of variables declaration
}