Teniendo el siguiente proyecto creado:
Cuyo código es el siguiente:
private void CopiarActionPerformed(java.awt.event.ActionEvent evt) {
portapapeles=pantalla.getSelectedText();
}
private void TamaLetraActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
jDialogTamaLetra.setSize(300,250);
jDialogTamaLetra.setVisible(true);
}
private void btnAceptarLetraActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
//ya que solo cambiaremos la letra debemos mantener el tamaño y el estilo
int tama=pantalla.getFont().getSize();
int estilo=pantalla.getFont().getStyle();
String letra=jList1.getSelectedValue();
pantalla.setFont(new Font(letra,estilo,tama));
jDialogTipoLetra.dispose();
}
private void TipoLetraActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
jDialogTipoLetra.setSize(410,350);
jDialogTipoLetra.setVisible(true);
jDialogTipoLetra.setModal(true);
jDialogTipoLetra.requestFocusInWindow();
}
private void NuevoActionPerformed(java.awt.event.ActionEvent evt) {
panelNuevo.setVisible(true);
pantalla.setText("");
}
private void SalirActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
System.exit(0);
}
private void CortarActionPerformed(java.awt.event.ActionEvent evt) {
portapapeles=pantalla.getSelectedText();
pantalla.replaceSelection("");
}
private void PegarActionPerformed(java.awt.event.ActionEvent evt) {
pantalla.replaceSelection(portapapeles);
}
private void SeleccionarTodoActionPerformed(java.awt.event.ActionEvent evt) {
pantalla.selectAll();
}
private void EstiloActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
jDialogEstilo.setSize(250,300);
jDialogEstilo.setVisible(true);
}
private void btnAceptarTamanoActionPerformed(java.awt.event.ActionEvent evt) {
//obtenemos los valores iniciales
String letra=pantalla.getFont().getFontName();
int estilo=pantalla.getFont().getStyle();
int tama=Integer.parseInt(jComboBox1.getSelectedItem().toString());
Font nueva=new Font (letra,estilo,tama);
pantalla.setFont(nueva);
jDialogTamaLetra.dispose();
}
private void saveActionPerformed(java.awt.event.ActionEvent evt) {
try {
// String ruta= "c:/archivo.txt";
Writer salida = new BufferedWriter(new OutputStreamWriter(new FileOutputStream("archivo.txt"),"UTF8"));
salida.write(pantalla.getText());
//para finalizar cierro el flujo al disco
salida.flush();
JOptionPane.showMessageDialog(this, "Fichero guardado correctamente", "INFORME",JOptionPane.ERROR_MESSAGE);
} catch (IOException ex) {
Logger.getLogger(Form1.class.getName()).log(Level.SEVERE, null, ex);
JOptionPane.showMessageDialog(this, "Error de E/S", "ERROR",1);
}
}
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
jDialogTipoLetra.dispose();
}
private void cutActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
portapapeles=pantalla.getSelectedText();
pantalla.replaceSelection("");
}
private void copyActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
portapapeles=pantalla.getSelectedText();
}
private void pasteActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
pantalla.replaceSelection(portapapeles);
}
private void btnNewActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
panelNuevo.setVisible(true);
pantalla.setText("");
//habilitamos botones de la barra de herramientas
save.setEnabled(true);
cut.setEnabled(true);
copy.setEnabled(true);
paste.setEnabled(true);
selecTodo.setEnabled(true);
}
private void btnCancelarTamaActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
jDialogTamaLetra.dispose();
}
private void btnAceptarEstiloActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
//obtenemos los valores iniciales
Font font = pantalla.getFont();
Map attributes = font.getAttributes();//par clave-valor para los atributos del texto de la textArea
if (jCheckBoxNegrita.isSelected()) {
attributes.put(TextAttribute.WEIGHT, TextAttribute.WEIGHT_BOLD);//cambiamos el valor del atributo "peso"
} else {
attributes.put(TextAttribute.WEIGHT, TextAttribute.WEIGHT_REGULAR);
}
if (jCheckBoxCursiva.isSelected()) {
attributes.put(TextAttribute.POSTURE, TextAttribute.POSTURE_OBLIQUE);//cambiamos el valor del atributo "postura"
} else {
attributes.put(TextAttribute.POSTURE, TextAttribute.POSTURE_REGULAR);
}
if (jCheckBoxUnderline.isSelected()) {
attributes.put(TextAttribute.UNDERLINE, TextAttribute.UNDERLINE_ON);//cambiamos el valor del atributo "subrayado"
} else {
attributes.put(TextAttribute.UNDERLINE, -1);//sin subrayar
}
pantalla.setFont(font.deriveFont(attributes));//cambiamos la fuente
jDialogEstilo.dispose();
}
private void GuardarActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
String s = pantalla.getText();
Archivo a = new Archivo();
try {
a.crearArchivo(s,this);
} catch (IOException ex) {
Logger.getLogger(Form1.class.getName()).log(Level.SEVERE, null, ex);
}
}
private void CerrarActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
panelNuevo.setVisible(false);
}
private void ColorActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
Color inicial=pantalla.getForeground();
Color newColor=JColorChooser.showDialog(this, "Eliga el color", inicial);
if (newColor != null){
pantalla.setForeground(newColor);
}
}
private void jMenuItem1ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
if (!lista.llena()){//si la lista no está llena guardo
lista.guardarFichero( pantalla.getText());
}
}
private void AbrirActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
//método para probar. Habría que implementar que me pida el nº de fichero
pantalla.setText(lista.abrirFichero(0).toString());
}
private void selecTodoActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
pantalla.selectAll();
}
0 comentarios:
Publicar un comentario