Proyecto Ascii Art by UVinci

This commit is contained in:
prunzinho 2024-02-28 08:07:44 -06:00
commit 47b2006ef0
10 changed files with 2576 additions and 0 deletions

73
AsciiArt/build.xml Normal file
View File

@ -0,0 +1,73 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- You may freely edit this file. See commented blocks below for -->
<!-- some examples of how to customize the build. -->
<!-- (If you delete it and reopen the project it will be recreated.) -->
<!-- By default, only the Clean and Build commands use this build script. -->
<!-- Commands such as Run, Debug, and Test only use this build script if -->
<!-- the Compile on Save feature is turned off for the project. -->
<!-- You can turn off the Compile on Save (or Deploy on Save) setting -->
<!-- in the project's Project Properties dialog box.-->
<project name="AsciiArt" default="default" basedir=".">
<description>Builds, tests, and runs the project AsciiArt.</description>
<import file="nbproject/build-impl.xml"/>
<!--
There exist several targets which are by default empty and which can be
used for execution of your tasks. These targets are usually executed
before and after some main targets. They are:
-pre-init: called before initialization of project properties
-post-init: called after initialization of project properties
-pre-compile: called before javac compilation
-post-compile: called after javac compilation
-pre-compile-single: called before javac compilation of single file
-post-compile-single: called after javac compilation of single file
-pre-compile-test: called before javac compilation of JUnit tests
-post-compile-test: called after javac compilation of JUnit tests
-pre-compile-test-single: called before javac compilation of single JUnit test
-post-compile-test-single: called after javac compilation of single JUunit test
-pre-jar: called before JAR building
-post-jar: called after JAR building
-post-clean: called after cleaning build products
(Targets beginning with '-' are not intended to be called on their own.)
Example of inserting an obfuscator after compilation could look like this:
<target name="-post-compile">
<obfuscate>
<fileset dir="${build.classes.dir}"/>
</obfuscate>
</target>
For list of available properties check the imported
nbproject/build-impl.xml file.
Another way to customize the build is by overriding existing main targets.
The targets of interest are:
-init-macrodef-javac: defines macro for javac compilation
-init-macrodef-junit: defines macro for junit execution
-init-macrodef-debug: defines macro for class debugging
-init-macrodef-java: defines macro for class execution
-do-jar: JAR building
run: execution of project
-javadoc-build: Javadoc generation
test-report: JUnit report generation
An example of overriding the target for project execution could look like this:
<target name="run" depends="AsciiArt-impl.jar">
<exec dir="bin" executable="launcher.exe">
<arg file="${dist.jar}"/>
</exec>
</target>
Notice that the overridden target depends on the jar target and not only on
the compile target as the regular run target does. Again, for a list of available
properties which you can use, check the target you are overriding in the
nbproject/build-impl.xml file.
-->
</project>

3
AsciiArt/manifest.mf Normal file
View File

@ -0,0 +1,3 @@
Manifest-Version: 1.0
X-COMMENT: Main-Class will be added automatically by build

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,8 @@
build.xml.data.CRC32=99eed0a2
build.xml.script.CRC32=23435b25
build.xml.stylesheet.CRC32=f85dc8f2@1.106.0.48
# This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml.
# Do not edit this file. You may delete it but then the IDE will never regenerate such files for you.
nbproject/build-impl.xml.data.CRC32=99eed0a2
nbproject/build-impl.xml.script.CRC32=3cf7f477
nbproject/build-impl.xml.stylesheet.CRC32=12e0a6c2@1.106.0.48

View File

@ -0,0 +1,95 @@
annotation.processing.enabled=true
annotation.processing.enabled.in.editor=false
annotation.processing.processor.options=
annotation.processing.processors.list=
annotation.processing.run.all.processors=true
annotation.processing.source.output=${build.generated.sources.dir}/ap-source-output
build.classes.dir=${build.dir}/classes
build.classes.excludes=**/*.java,**/*.form
# This directory is removed when the project is cleaned:
build.dir=build
build.generated.dir=${build.dir}/generated
build.generated.sources.dir=${build.dir}/generated-sources
# Only compile against the classpath explicitly listed here:
build.sysclasspath=ignore
build.test.classes.dir=${build.dir}/test/classes
build.test.results.dir=${build.dir}/test/results
# Uncomment to specify the preferred debugger connection transport:
#debug.transport=dt_socket
debug.classpath=\
${run.classpath}
debug.modulepath=\
${run.modulepath}
debug.test.classpath=\
${run.test.classpath}
debug.test.modulepath=\
${run.test.modulepath}
# Files in build.classes.dir which should be excluded from distribution jar
dist.archive.excludes=
# This directory is removed when the project is cleaned:
dist.dir=dist
dist.jar=${dist.dir}/AsciiArt.jar
dist.javadoc.dir=${dist.dir}/javadoc
dist.jlink.dir=${dist.dir}/jlink
dist.jlink.output=${dist.jlink.dir}/AsciiArt
excludes=
includes=**
jar.compress=false
javac.classpath=
# Space-separated list of extra javac options
javac.compilerargs=
javac.deprecation=false
javac.external.vm=true
javac.modulepath=
javac.processormodulepath=
javac.processorpath=\
${javac.classpath}
javac.source=17
javac.target=17
javac.test.classpath=\
${javac.classpath}:\
${build.classes.dir}
javac.test.modulepath=\
${javac.modulepath}
javac.test.processorpath=\
${javac.test.classpath}
javadoc.additionalparam=
javadoc.author=false
javadoc.encoding=${source.encoding}
javadoc.html5=false
javadoc.noindex=false
javadoc.nonavbar=false
javadoc.notree=false
javadoc.private=false
javadoc.splitindex=true
javadoc.use=true
javadoc.version=false
javadoc.windowtitle=
# The jlink additional root modules to resolve
jlink.additionalmodules=
# The jlink additional command line parameters
jlink.additionalparam=
jlink.launcher=true
jlink.launcher.name=AsciiArt
main.class=asciiart.Principal
manifest.file=manifest.mf
meta.inf.dir=${src.dir}/META-INF
mkdist.disabled=false
platform.active=default_platform
run.classpath=\
${javac.classpath}:\
${build.classes.dir}
# Space-separated list of JVM arguments used when running the project.
# You may also define separate properties like run-sys-prop.name=value instead of -Dname=value.
# To set system properties for unit tests define test-sys-prop.name=value:
run.jvmargs=
run.modulepath=\
${javac.modulepath}
run.test.classpath=\
${javac.test.classpath}:\
${build.test.classes.dir}
run.test.modulepath=\
${javac.test.modulepath}
source.encoding=UTF-8
src.dir=src
test.src.dir=test

View File

@ -0,0 +1,15 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://www.netbeans.org/ns/project/1">
<type>org.netbeans.modules.java.j2seproject</type>
<configuration>
<data xmlns="http://www.netbeans.org/ns/j2se-project/3">
<name>AsciiArt</name>
<source-roots>
<root id="src.dir"/>
</source-roots>
<test-roots>
<root id="test.src.dir"/>
</test-roots>
</data>
</configuration>
</project>

View File

@ -0,0 +1,248 @@
package asciiart;
/*
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
*/
/**
*
* @author mario
*/
import javax.swing.*;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
import javax.swing.filechooser.FileNameExtensionFilter;
import java.awt.*;
import java.awt.datatransfer.Clipboard;
import java.awt.datatransfer.StringSelection;
import java.awt.event.*;
import java.io.*;
import java.awt.image.BufferedImage;
import javax.imageio.ImageIO;
class PanelImagen extends JPanel {
private BufferedImage imagenOriginal;
private BufferedImage imagenEscalaGrises;
private BufferedImage imagenMostrada;
private float opacidad = 1.0f;
private JTextArea textArea;
public PanelImagen() {
setBackground(Color.WHITE);
setLayout(new BorderLayout());
textArea = new JTextArea() {
@Override
protected void paintComponent(Graphics g) {
if (!isOpaque() && getBackground().getAlpha() < 255) {
g.setColor(getBackground());
g.fillRect(0, 0, getWidth(), getHeight());
}
super.paintComponent(g);
}
};
textArea.setFont(new Font("Monospaced", Font.PLAIN, 12));
textArea.setOpaque(false);
add(textArea, BorderLayout.CENTER);
}
public void establecerImagenFondo(BufferedImage imagen) {
imagenOriginal = imagen;
imagenEscalaGrises = convertirAEscalaDeGrises(imagen);
imagenMostrada = aplicarOpacidad(imagenEscalaGrises, opacidad);
repaint();
}
private BufferedImage convertirAEscalaDeGrises(BufferedImage imagen) {
BufferedImage gris = new BufferedImage(imagen.getWidth(), imagen.getHeight(), BufferedImage.TYPE_BYTE_GRAY);
Graphics g = gris.getGraphics();
g.drawImage(imagen, 0, 0, null);
g.dispose();
return gris;
}
private BufferedImage aplicarOpacidad(BufferedImage imagen, float opacidad) {
BufferedImage resultado = new BufferedImage(imagen.getWidth(), imagen.getHeight(), BufferedImage.TYPE_INT_ARGB);
Graphics2D g2d = resultado.createGraphics();
AlphaComposite alphaComposite = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, opacidad);
g2d.setComposite(alphaComposite);
g2d.drawImage(imagen, 0, 0, null);
g2d.dispose();
return resultado;
}
public void establecerOpacidad(float opacidad) {
if (imagenEscalaGrises != null) {
this.opacidad = opacidad / 100.0f;
imagenMostrada = aplicarOpacidad(imagenEscalaGrises, this.opacidad);
repaint();
}
}
public JTextArea getTextArea() {
return textArea;
}
@Override
protected void paintComponent(Graphics g) {
super.paintComponent(g);
if (imagenMostrada != null) {
g.drawImage(imagenMostrada, 0, 0, getWidth(), getHeight(), this);
}
}
}
public class EditorAsciiArt extends JFrame {
private int filas = 10;
private int columnas = 10;
private PanelImagen panelImagen;
private JSlider deslizadorOpacidad;
private JTextField campoFilas;
private JTextField campoColumnas;
public EditorAsciiArt() {
setTitle("Editor de Arte ASCII");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setLayout(new BorderLayout());
JPanel panelIzquierdo = new JPanel();
panelIzquierdo.setLayout(new BoxLayout(panelIzquierdo, BoxLayout.Y_AXIS));
JButton botonImagenFondo = new JButton("Seleccionar Imagen Fondo");
botonImagenFondo.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
seleccionarImagenFondo();
}
});
panelIzquierdo.add(botonImagenFondo);
JButton botonGuardar = new JButton("Guardar ASCII Art");
botonGuardar.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
guardarASCIIArt();
}
});
panelIzquierdo.add(botonGuardar);
JButton botonCopiar = new JButton("Copiar ASCII Art");
botonCopiar.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
copiarASCIIArt();
}
});
panelIzquierdo.add(botonCopiar);
JButton botonCargar = new JButton("Cargar ASCII Art");
botonCargar.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
cargarASCIIArt();
}
});
panelIzquierdo.add(botonCargar);
panelIzquierdo.add(new JLabel("Opacidad:"));
deslizadorOpacidad = new JSlider(0, 100, 100);
deslizadorOpacidad.addChangeListener(new ChangeListener() {
@Override
public void stateChanged(ChangeEvent e) {
int valor = deslizadorOpacidad.getValue();
panelImagen.establecerOpacidad(valor);
}
});
panelIzquierdo.add(deslizadorOpacidad);
panelIzquierdo.add(Box.createVerticalGlue());
JButton botonHome = new JButton("Inicio");
botonHome.addActionListener(new ActionListener(){
@Override
public void actionPerformed(ActionEvent e){
regresarInicio();
}
});
panelIzquierdo.add(botonHome);
add(panelIzquierdo, BorderLayout.WEST);
panelImagen = new PanelImagen();
add(panelImagen, BorderLayout.CENTER);
setSize(800, 600);
setLocationRelativeTo(null);
setVisible(true);
}
private void seleccionarImagenFondo() {
JFileChooser fileChooser = new JFileChooser();
FileNameExtensionFilter filter = new FileNameExtensionFilter("Archivos de Imagen", "jpg", "jpeg", "png", "gif");
fileChooser.setFileFilter(filter);
int returnVal = fileChooser.showOpenDialog(this);
if (returnVal == JFileChooser.APPROVE_OPTION) {
File file = fileChooser.getSelectedFile();
try {
BufferedImage imagen = ImageIO.read(file);
panelImagen.establecerImagenFondo(imagen);
} catch (Exception ex) {
ex.printStackTrace();
}
}
}
private void guardarASCIIArt() {
try {
JTextArea textArea = panelImagen.getTextArea();
String asciiArt = textArea.getText();
File file = new File("asciiart.txt");
BufferedWriter writer = new BufferedWriter(new FileWriter(file));
writer.write(asciiArt);
writer.close();
JOptionPane.showMessageDialog(this, "ASCII Art guardado exitosamente.");
} catch (Exception e) {
e.printStackTrace();
JOptionPane.showMessageDialog(this, "Error al guardar el ASCII Art.", "Error", JOptionPane.ERROR_MESSAGE);
}
}
private void copiarASCIIArt() {
JTextArea textArea = panelImagen.getTextArea();
StringSelection stringSelection = new StringSelection(textArea.getText());
Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
clipboard.setContents(stringSelection, null);
JOptionPane.showMessageDialog(this, "ASCII Art copiado al portapapeles.");
}
private void cargarASCIIArt() {
try {
File file = new File("asciiart.txt");
BufferedReader reader = new BufferedReader(new FileReader(file));
StringBuilder asciiArtBuilder = new StringBuilder();
String line;
while ((line = reader.readLine()) != null) {
asciiArtBuilder.append(line);
asciiArtBuilder.append("\n");
}
reader.close();
panelImagen.getTextArea().setText(asciiArtBuilder.toString());
} catch (Exception e) {
e.printStackTrace();
JOptionPane.showMessageDialog(this, "Error al cargar el ASCII Art.", "Error", JOptionPane.ERROR_MESSAGE);
}
}
private void regresarInicio(){
Principal nuevaVentana = new Principal();
nuevaVentana.setVisible(true);
dispose();
}
public static void main(String[] args) {
SwingUtilities.invokeLater(() -> {
new EditorAsciiArt();
});
}
}

View File

@ -0,0 +1,65 @@
/*
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
*/
package asciiart;
/**
*
* @author mario
*/
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class Principal extends JFrame {
public Principal() {
setTitle("ASCII Art Converter"); // Título original
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setLayout(null); // Establecer un diseño nulo para usar setBounds
// Creación de botones
JButton asciiArtButton = new JButton("Crear ASCII Art");
asciiArtButton.setBounds(50, 60, 150, 30); // Establecer posición y tamaño
asciiArtButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
// Abre la clase AsciiArt
new EditorAsciiArt().setVisible(true);
dispose(); // Cierra el menú principal
}
});
JButton imageToAsciiButton = new JButton("Transformar imagen a ASCII Art");
imageToAsciiButton.setBounds(220, 60, 220, 30); // Establecer posición y tamaño
imageToAsciiButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
// Abre la clase SeleccionarImage
new SeleccionarImage().setVisible(true);
dispose(); // Cierra el menú principal
}
});
// Agregar botones al JFrame
add(asciiArtButton);
add(imageToAsciiButton);
setSize(500, 150); // Tamaño del JFrame
setLocationRelativeTo(null); // Centrar en la pantalla
// Label con el título (agregado después de setSize y setLocationRelativeTo)
JLabel titleLabel = new JLabel("ASCII ART by UVinci", SwingConstants.CENTER);
titleLabel.setFont(new Font("Arial", Font.BOLD, 24)); // Establecer fuente y tamaño
titleLabel.setForeground(Color.BLACK); // Establecer color de texto a negro
titleLabel.setBounds(0, 10, getWidth(), 30); // Centrar y establecer posición
add(titleLabel);
}
public static void main(String[] args) {
SwingUtilities.invokeLater(() -> {
new Principal().setVisible(true);
});
}
}

View File

@ -0,0 +1,89 @@
package asciiart;
import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
import javax.swing.filechooser.FileNameExtensionFilter;
import java.awt.image.BufferedImage;
import javax.imageio.ImageIO;
public class SeleccionarImage extends JFrame {
private static final String CHARACTERS = "a%k*t=-:. ";
String imagePath = "";
int width = 0;
int height = 0;
public SeleccionarImage() {
initComponents();
}
private void initComponents() {
JButton seleccionarBoton = new JButton("Seleccionar Imagen");
seleccionarBoton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
JFileChooser fileChooser = new JFileChooser();
fileChooser.setCurrentDirectory(new File(System.getProperty("user.home")));
FileNameExtensionFilter filter = new FileNameExtensionFilter("Archivos de Imagen", "jpg", "jpeg", "png", "gif");
fileChooser.setFileFilter(filter);
int result = fileChooser.showOpenDialog(SeleccionarImage.this);
if (result == JFileChooser.APPROVE_OPTION) {
File selectedFile = fileChooser.getSelectedFile();
imagePath = selectedFile.getAbsolutePath(); // Actualizar la variable imagePath
generarASCII(imagePath); // Llamar al método para generar el arte ASCII
}
}
});
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
getContentPane().add(seleccionarBoton, "North");
pack();
setLocationRelativeTo(null);
}
private void generarASCII(String imagePath) {
try {
BufferedImage image = ImageIO.read(new File(imagePath));
String asciiArt = convertToASCII(image);
TransformarAscii nuevaVentana = new TransformarAscii(width,height,asciiArt); // Suponiendo que CrearAscii es el nombre de tu otra ventana
nuevaVentana.setVisible(true);
dispose();
} catch (Exception ex) {
ex.printStackTrace();
}
}
private String convertToASCII(BufferedImage image) {
StringBuilder asciiArt = new StringBuilder();
width = image.getWidth();
height = image.getHeight();
for (int y = 0; y < height; y++) {
for (int x = 0; x < width; x++) {
//Obtener el color del píxel en formato RGB
int color = image.getRGB(x, y);
//Convertir el color a escala de grises
int gray = (int) (0.21 * ((color >> 16) & 0xff) + 0.72 * ((color >> 8) & 0xff) + 0.07 * (color & 0xff));
//Calcular el índice del carácter en función del nivel de gris
int index = (int) ((gray / 255.0) * (CHARACTERS.length() - 1));
asciiArt.append(CHARACTERS.charAt(index));
}
// Agregar un salto de línea al final de cada fila
asciiArt.append("\n");
}
return asciiArt.toString();
}
public static void main(String[] args) {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
new SeleccionarImage().setVisible(true);
}
});
}
}

View File

@ -0,0 +1,209 @@
package asciiart;
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.datatransfer.*;
import java.io.*;
public class TransformarAscii extends javax.swing.JFrame {
int width = 0;
int height = 0;
String copia = "";
String ruta = "C:/Users/CDGN_/Desktop/ProyectoFinal/frontend/";
public TransformarAscii() {
initComponents();
}
public TransformarAscii(int width, int height, String asci) {
initComponents();
this.width = width;
this.height = height;
this.setSize(600, 600);
Font font = new Font(Font.MONOSPACED, Font.PLAIN, 12); // Fuente de ancho fijo
AsciiText.setFont(font);
AsciiText.setText(asci);
copia = asci;
JScrollPane scrollPane = new JScrollPane(AsciiText);
jPanel1.add(scrollPane);
}
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {
jMenuBar1 = new javax.swing.JMenuBar();
jMenu1 = new javax.swing.JMenu();
jMenu2 = new javax.swing.JMenu();
AsciiText1 = new javax.swing.JTextField();
jPanel1 = new javax.swing.JPanel();
JPanel zoomPanel = new JPanel(new FlowLayout());
JPanel actionPanel = new JPanel(new FlowLayout());
AsciiText = new javax.swing.JTextArea();
JButton copiar = new JButton("Copiar");
JButton guardar = new JButton("Guardar");
JButton zoomInButton = new JButton("Mas Zoom");
JButton SeleccionarImagen = new JButton("Seleccionar Imagen");
JButton zoomOutButton = new JButton("Menos Zoom");
JButton BotonHome = new JButton("Inicio");
JButton BotonReduccion = new JButton("Reducir Signos");
zoomInButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
Font currentFont = AsciiText.getFont();
Font newFont = currentFont.deriveFont(currentFont.getSize() + 2f);
AsciiText.setFont(newFont);
}
});
zoomOutButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
Font currentFont = AsciiText.getFont();
Font newFont = currentFont.deriveFont(currentFont.getSize() - 2f);
AsciiText.setFont(newFont);
}
});
copiar.addActionListener(new ActionListener(){
@Override
public void actionPerformed(ActionEvent e){
copiarAlPortapapeles(copia);
}
});
guardar.addActionListener(new ActionListener(){
@Override
public void actionPerformed(ActionEvent e){
String nombrearchivo = "asciiArt1.txt";
guardarEnArchivo(copia,ruta, nombrearchivo);
}
});
SeleccionarImagen.addActionListener(new ActionListener(){
@Override
public void actionPerformed(ActionEvent e){
SeleccionarImagenMetodo();
}
});
BotonHome.addActionListener(new ActionListener(){
@Override
public void actionPerformed(ActionEvent e){
regresarInicio();
}
});
BotonReduccion.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
System.out.println(reduceAscii(copia));
}
});
jMenu1.setText("File");
jMenuBar1.add(jMenu1);
jMenu2.setText("Edit");
jMenuBar1.add(jMenu2);
AsciiText1.setText("a");
AsciiText1.setToolTipText("");
AsciiText1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
AsciiText1ActionPerformed(evt);
}
});
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
jPanel1.setLayout(new BorderLayout());
jPanel1.add(AsciiText, BorderLayout.CENTER);
zoomPanel.add(zoomInButton);
zoomPanel.add(zoomOutButton);
actionPanel.add(copiar);
actionPanel.add(guardar);
actionPanel.add(SeleccionarImagen);
actionPanel.add(BotonHome);
jPanel1.add(zoomPanel, BorderLayout.NORTH);
jPanel1.add(actionPanel, BorderLayout.SOUTH);
getContentPane().add(jPanel1, java.awt.BorderLayout.CENTER);
pack();
}// </editor-fold>
private void AsciiText1ActionPerformed(java.awt.event.ActionEvent evt) {
}
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new TransformarAscii().setVisible(true);
}
});
}
public static void copiarAlPortapapeles(String texto) {
// Obtiene el Toolkit del sistema
Toolkit toolkit = Toolkit.getDefaultToolkit();
Clipboard clipboard = toolkit.getSystemClipboard();
StringSelection strSel = new StringSelection(texto);
clipboard.setContents(strSel, null);
}
public static void guardarEnArchivo(String texto, String rutaCarpeta, String nombreArchivo) {
try {
File carpeta = new File(rutaCarpeta);
if (!carpeta.exists()) {
carpeta.mkdirs();
}
String rutaCompleta = rutaCarpeta + nombreArchivo;
FileWriter writer = new FileWriter(rutaCompleta);
writer.write(texto);
writer.close();
System.out.println("Texto guardado en el archivo: " + rutaCompleta);
} catch (IOException e) {
System.out.println("Error al guardar el archivo: " + e.getMessage());
}
}
private void SeleccionarImagenMetodo(){
new SeleccionarImage().setVisible(true);
dispose();
}
private void regresarInicio(){
Principal nuevaVentana = new Principal();
nuevaVentana.setVisible(true);
dispose();
}
private String reduceAscii(String ascii) {
StringBuilder sb = new StringBuilder();
for (int i = 0; i < ascii.length(); i++) {
char currentChar = ascii.charAt(i);
sb.append(currentChar);
if (i % 2 == 0 && currentChar == '.') { // Elimina un punto cada dos símbolos
sb.deleteCharAt(sb.length() - 2);
}
}
return sb.toString();
}
private javax.swing.JTextArea AsciiText;
private javax.swing.JTextField AsciiText1;
private javax.swing.JMenu jMenu1;
private javax.swing.JMenu jMenu2;
private javax.swing.JMenuBar jMenuBar1;
private javax.swing.JPanel jPanel1;
}