En este post les traigo un "programita" hecho en java, claro por mi.
Anteriormente ya había mostrado el código de los archivos, pero ahora ya los traigo de una manera mas interactiva, el programa lo realice en JAVA.
La interfaz del programa es el siguiente;
El programa muestra el ejemplo de cada tema que se seleccione, se puede editar, guardar y ejecutar el "pogramita".
El Programa incluye varios frames, el código del frame principal es el siguiente;
import java.awt.Desktop;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import javax.swing.JOptionPane;
/**
*
* @author Ivan Luis Jimenez
*/
public class VBScript extends javax.swing.JFrame {
public VBScript() {
initComponents();
setTitle("Ejemplos_VBScript");
setSize(650, 380);
setLocationRelativeTo(null);
}
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {
jLabel1 = new javax.swing.JLabel();
Tema = new javax.swing.JComboBox();
Ejecutar = new javax.swing.JButton();
Limpiar = new javax.swing.JButton();
Guardar = new javax.swing.JButton();
Ejecutar_matrix = new javax.swing.JButton();
jLabel4 = new javax.swing.JLabel();
jSeparator1 = new javax.swing.JSeparator();
Abrir_Notas = new javax.swing.JButton();
jScrollPane1 = new javax.swing.JScrollPane();
Area = new javax.swing.JTextArea();
jLabel2 = new javax.swing.JLabel();
Nombres = new javax.swing.JLabel();
jLabel3 = new javax.swing.JLabel();
jMenuBar1 = new javax.swing.JMenuBar();
jMenu1 = new javax.swing.JMenu();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
setResizable(false);
getContentPane().setLayout(null);
jLabel1.setBackground(new java.awt.Color(255, 255, 255));
jLabel1.setForeground(new java.awt.Color(255, 255, 255));
jLabel1.setText("Seleccione el ejemplo que desea ver:");
getContentPane().add(jLabel1);
jLabel1.setBounds(12, 12, 220, 15);
Tema.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Primer Script (Hola Mundo)", "Variables y uso de IF", "Uso de InputBox (Lectura de teclado)", "Uso de For Next", "Uso de Do While", "Uso de Do Loop", "Uso de While Wend", "Uso de Select Case" }));
Tema.setToolTipText("");
Tema.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
TemaMouseClicked(evt);
}
});
Tema.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
TemaActionPerformed(evt);
}
});
getContentPane().add(Tema);
Tema.setBounds(10, 30, 221, 24);
Ejecutar.setText("Ejecutar Ejemplo");
Ejecutar.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
EjecutarMouseClicked(evt);
}
});
getContentPane().add(Ejecutar);
Ejecutar.setBounds(510, 100, 130, 25);
Limpiar.setText("Limpiar Area");
Limpiar.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
LimpiarMouseClicked(evt);
}
});
getContentPane().add(Limpiar);
Limpiar.setBounds(240, 30, 110, 25);
Guardar.setText("Guardar Ejemplo");
Guardar.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
GuardarMouseClicked(evt);
}
});
getContentPane().add(Guardar);
Guardar.setBounds(510, 70, 130, 25);
Ejecutar_matrix.setText("Ejecutar Matrix");
Ejecutar_matrix.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
Ejecutar_matrixMouseClicked(evt);
}
});
Ejecutar_matrix.addKeyListener(new java.awt.event.KeyAdapter() {
public void keyTyped(java.awt.event.KeyEvent evt) {
Ejecutar_matrixKeyTyped(evt);
}
});
getContentPane().add(Ejecutar_matrix);
Ejecutar_matrix.setBounds(510, 160, 130, 25);
jLabel4.setIcon(new javax.swing.ImageIcon(getClass().getResource("/chavo2.gif"))); // NOI18N
getContentPane().add(jLabel4);
jLabel4.setBounds(520, 200, 120, 100);
getContentPane().add(jSeparator1);
jSeparator1.setBounds(510, 140, 130, 10);
Abrir_Notas.setText("Abrir Bloc de Notas");
Abrir_Notas.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
Abrir_NotasMouseClicked(evt);
}
});
getContentPane().add(Abrir_Notas);
Abrir_Notas.setBounds(360, 30, 150, 25);
Area.setColumns(20);
Area.setRows(5);
jScrollPane1.setViewportView(Area);
getContentPane().add(jScrollPane1);
jScrollPane1.setBounds(12, 63, 497, 255);
jLabel2.setBackground(new java.awt.Color(255, 255, 255));
jLabel2.setForeground(new java.awt.Color(255, 255, 255));
jLabel2.setText("Bienvenido:");
getContentPane().add(jLabel2);
jLabel2.setBounds(290, 10, 90, 15);
Nombres.setBackground(new java.awt.Color(255, 255, 255));
Nombres.setForeground(new java.awt.Color(255, 255, 255));
Nombres.setText("sin nombre -_-");
getContentPane().add(Nombres);
Nombres.setBounds(380, 10, 128, 15);
jLabel3.setIcon(new javax.swing.ImageIcon(getClass().getResource("/fondo.jpg"))); // NOI18N
jLabel3.setText("jLabel3");
getContentPane().add(jLabel3);
jLabel3.setBounds(0, -20, 680, 380);
jMenu1.setText("Acerca de");
jMenu1.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
jMenu1MouseClicked(evt);
}
});
jMenuBar1.add(jMenu1);
setJMenuBar(jMenuBar1);
pack();
}// </editor-fold>
void read(String ruta) {
String codigo = new String();
File archivo = new File(ruta);
FileReader fr = null;
BufferedReader entrada = null;
try {
fr = new FileReader(ruta);
entrada = new BufferedReader(fr);
while (entrada.ready()) {
codigo += entrada.readLine() + " n";
}
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
if (null != fr) {
fr.close();
}
} catch (Exception e2) {
e2.printStackTrace();
}
}
Area.setText(codigo);
}
private void jMenu1MouseClicked(java.awt.event.MouseEvent evt) {
About call = new About();
call.setVisible(true);
}
private void TemaMouseClicked(java.awt.event.MouseEvent evt) {
}
private void LimpiarMouseClicked(java.awt.event.MouseEvent evt) {
Area.setText("");
}
private void TemaActionPerformed(java.awt.event.ActionEvent evt) {
//VBScript llamar = new VBScript();
if (Tema.getSelectedItem().toString() == "Primer Script (Hola Mundo)") {
read("Script.vbs");
} else if (Tema.getSelectedItem().toString() == "Variables y uso de IF") {
read("Holis.vbs");
} else if (Tema.getSelectedItem().toString() == "Uso de InputBox (Lectura de teclado)") {
read("inputbox.vbs");
} else if (Tema.getSelectedItem().toString() == "Uso de For Next") {
read("for_next.vbs");
} else if (Tema.getSelectedItem().toString() == "Uso de Do While") {
read("DoWhile.vbs");
} else if (Tema.getSelectedItem().toString() == "Uso de Do Loop") {
read("Do_Loop.vbs");
} else if (Tema.getSelectedItem().toString() == "Uso de While Wend") {
read("While_Wend.vbs");
} else if (Tema.getSelectedItem().toString() == "Uso de Select Case") {
read("select_case.vbs");
}
}
private void Abrir_NotasMouseClicked(java.awt.event.MouseEvent evt) {
try {
File path = new File("bloc.cmd");
Desktop.getDesktop().open(path);
} catch (IOException ex) {
mensaje_atencion("El archivo no se encuentra");
}
}
private void EjecutarMouseClicked(java.awt.event.MouseEvent evt) {
if (Tema.getSelectedItem().toString() == "Primer Script (Hola Mundo)") {
try {
File path = new File("Script.vbs");
Desktop.getDesktop().open(path);
} catch (IOException ex) {
mensaje_atencion("El archivo no existe o a sido eliminado");
}
} else if (Tema.getSelectedItem().toString() == "Variables y uso de IF") {
try {
File path = new File("Holis.vbs");
Desktop.getDesktop().open(path);
} catch (IOException ex) {
mensaje_atencion("El archivo no existe o a sido eliminado");
}
} else if (Tema.getSelectedItem().toString() == "Uso de InputBox (Lectura de teclado)") {
try {
File path = new File("inputbox.vbs");
Desktop.getDesktop().open(path);
} catch (IOException ex) {
mensaje_atencion("El archivo no existe o a sido eliminado");
}
} else if (Tema.getSelectedItem().toString() == "Uso de For Next") {
try {
File path = new File("for_next.vbs");
Desktop.getDesktop().open(path);
} catch (IOException ex) {
mensaje_atencion("El archivo no existe o a sido eliminado");
}
} else if (Tema.getSelectedItem().toString() == "Uso de Do While") {
try {
File path = new File("DoWhile.vbs");
Desktop.getDesktop().open(path);
} catch (IOException ex) {
mensaje_atencion("El archivo no existe o a sido eliminado");
}
} else if (Tema.getSelectedItem().toString() == "Uso de Do Loop") {
try {
File path = new File("Do_Loop.vbs");
Desktop.getDesktop().open(path);
} catch (IOException ex) {
mensaje_atencion("El archivo no existe o a sido eliminado");
}
} else if (Tema.getSelectedItem().toString() == "Uso de While Wend") {
try {
File path = new File("While_Wend.vbs");
Desktop.getDesktop().open(path);
} catch (IOException ex) {
mensaje_atencion("El archivo no existe o a sido eliminado");
}
} else if (Tema.getSelectedItem().toString() == "Uso de Select Case") {
try {
File path = new File("select_case.vbs");
Desktop.getDesktop().open(path);
} catch (IOException ex) {
mensaje_atencion("El archivo no existe o a sido eliminado");
}
}
}
public static void mensaje_atencion(String mens) {
JOptionPane.showMessageDialog(null, mens, "Atención", 2);
}
public static void mensaje_informar(String mens) {
JOptionPane.showMessageDialog(null, mens, "Información", 1);
}
private void GuardarMouseClicked(java.awt.event.MouseEvent evt) {
String ruta = "";
File archivo;
BufferedWriter bw = null;
if (Area.getText().length() != 0) {
if (Tema.getSelectedItem().toString() == "Primer Script (Hola Mundo)") {
ruta = "Script.vbs";
archivo = new File(ruta);
try {
if (archivo.exists()) {
bw = new BufferedWriter(new FileWriter(archivo));
bw.write(Area.getText().toString());
} else {
bw.write(Area.getText().toString());
}
bw.close();
mensaje_informar("Guardado");
} catch (Exception e) {
mensaje_atencion("El archivo no existe, o esta mal guardado");
}
} else if (Tema.getSelectedItem().toString() == "Variables y uso de IF") {
ruta = "Holis.vbs";
archivo = new File(ruta);
try {
if (archivo.exists()) {
bw = new BufferedWriter(new FileWriter(archivo));
bw.write(Area.getText().toString());
} else {
bw.write(Area.getText().toString());
}
bw.close();
mensaje_informar("Guardado");
} catch (Exception e) {
mensaje_atencion("El archivo no existe, o esta mal guardado");
}
} else if (Tema.getSelectedItem().toString() == "Uso de InputBox (Lectura de teclado)") {
ruta = "inputbox.vbs";
archivo = new File(ruta);
try {
if (archivo.exists()) {
bw = new BufferedWriter(new FileWriter(archivo));
bw.write(Area.getText().toString());
} else {
bw.write(Area.getText().toString());
}
bw.close();
mensaje_informar("Guardado");
} catch (Exception e) {
mensaje_atencion("El archivo no existe, o esta mal guardado");
}
} else if (Tema.getSelectedItem().toString() == "Uso de For Next") {
ruta = "for_next.vbs";
archivo = new File(ruta);
try {
if (archivo.exists()) {
bw = new BufferedWriter(new FileWriter(archivo));
bw.write(Area.getText().toString());
} else {
bw.write(Area.getText().toString());
}
bw.close();
mensaje_informar("Guardado");
} catch (Exception e) {
mensaje_atencion("El archivo no existe, o esta mal guardado");
}
} else if (Tema.getSelectedItem().toString() == "Uso de Do While") {
ruta = "DoWhile.vbs";
archivo = new File(ruta);
try {
if (archivo.exists()) {
bw = new BufferedWriter(new FileWriter(archivo));
bw.write(Area.getText().toString());
} else {
bw.write(Area.getText().toString());
}
bw.close();
mensaje_informar("Guardado");
} catch (Exception e) {
mensaje_atencion("El archivo no existe, o esta mal guardado");
}
} else if (Tema.getSelectedItem().toString() == "Uso de Do Loop") {
ruta = "Do_Loop.vbs";
archivo = new File(ruta);
try {
if (archivo.exists()) {
bw = new BufferedWriter(new FileWriter(archivo));
bw.write(Area.getText().toString());
} else {
bw.write(Area.getText().toString());
}
bw.close();
mensaje_informar("Guardado");
} catch (Exception e) {
mensaje_atencion("El archivo no existe, o esta mal guardado");
}
} else if (Tema.getSelectedItem().toString() == "Uso de While Wend") {
ruta = "While_Wend.vbs";
archivo = new File(ruta);
try {
if (archivo.exists()) {
bw = new BufferedWriter(new FileWriter(archivo));
bw.write(Area.getText().toString());
} else {
bw.write(Area.getText().toString());
}
bw.close();
mensaje_informar("Guardado");
} catch (Exception e) {
mensaje_atencion("El archivo no existe, o esta mal guardado");
}
} else if (Tema.getSelectedItem().toString() == "Uso de Select Case") {
ruta = "Script.vbs";
archivo = new File(ruta);
try {
if (archivo.exists()) {
bw = new BufferedWriter(new FileWriter(archivo));
bw.write(Area.getText().toString());
} else {
bw.write(Area.getText().toString());
}
bw.close();
mensaje_informar("Guardado");
} catch (Exception e) {
mensaje_atencion("El archivo no existe, o esta mal guardado");
}
}
} else {
mensaje_atencion("No hay nada que guardar");
}
}
private void Ejecutar_matrixKeyTyped(java.awt.event.KeyEvent evt) {
}
private void Ejecutar_matrixMouseClicked(java.awt.event.MouseEvent evt) {
try {
File path = new File("IvanovicHacker.bat");
Desktop.getDesktop().open(path);
} catch (IOException ex) {
mensaje_atencion("El archivo no se encuentra");
} // TODO add your handling code here:
}
// //<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 http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
// */
// 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(VBScript.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
// } catch (InstantiationException ex) {
// java.util.logging.Logger.getLogger(VBScript.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
// } catch (IllegalAccessException ex) {
// java.util.logging.Logger.getLogger(VBScript.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
// } catch (javax.swing.UnsupportedLookAndFeelException ex) {
// java.util.logging.Logger.getLogger(VBScript.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
// }
// //</editor-fold>
// Variables declaration - do not modify
private javax.swing.JButton Abrir_Notas;
private javax.swing.JTextArea Area;
private javax.swing.JButton Ejecutar;
private javax.swing.JButton Ejecutar_matrix;
private javax.swing.JButton Guardar;
private javax.swing.JButton Limpiar;
public static javax.swing.JLabel Nombres;
private javax.swing.JComboBox Tema;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel2;
private javax.swing.JLabel jLabel3;
private javax.swing.JLabel jLabel4;
private javax.swing.JMenu jMenu1;
private javax.swing.JMenuBar jMenuBar1;
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JSeparator jSeparator1;
// End of variables declaration
}
Este es el código del primer frame:
import java.awt.Color;
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
/**
*
* @author Jony
*/
public class Bienvenida extends javax.swing.JFrame {
/**
* Creates new form Bienvenida
*/
public Bienvenida() {
initComponents();
setTitle("Registro de usuario");
setLocationRelativeTo(null);
setSize(370, 110);
Aceptar.setBackground(Color.red);
}
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {
Lectura = new javax.swing.JTextField();
Aceptar = new javax.swing.JButton();
jLabel2 = new javax.swing.JLabel();
setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
setResizable(false);
getContentPane().setLayout(null);
getContentPane().add(Lectura);
Lectura.setBounds(40, 9, 281, 30);
Aceptar.setForeground(new java.awt.Color(255, 255, 255));
Aceptar.setText("Aceptar");
Aceptar.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
AceptarMouseClicked(evt);
}
});
Aceptar.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
AceptarActionPerformed(evt);
}
});
getContentPane().add(Aceptar);
Aceptar.setBounds(150, 50, 73, 25);
jLabel2.setIcon(new javax.swing.ImageIcon(getClass().getResource("/fondo2.png"))); // NOI18N
jLabel2.setText("jLabel2");
getContentPane().add(jLabel2);
jLabel2.setBounds(1, 0, 370, 80);
pack();
}// </editor-fold>
private void AceptarMouseClicked(java.awt.event.MouseEvent evt) {
VBScript call = new VBScript();
Bienvenida call1 = new Bienvenida();
call.setVisible(true);
if ((Lectura.getText().length()) == 0) {
VBScript.Nombres.setText("sin nombre -_-");
this.dispose();
} else {
VBScript.Nombres.setText(Lectura.getText());
this.dispose();
}
}
private void AceptarActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
}
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 http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
*/
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(VBScript.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(VBScript.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(VBScript.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(VBScript.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 Bienvenida().setVisible(true);
}
});
}
// Variables declaration - do not modify
private javax.swing.JButton Aceptar;
private javax.swing.JTextField Lectura;
private javax.swing.JLabel jLabel2;
// End of variables declaration
}
Espero y les sea de ayuda para los que comienzan a ver lo de programación.
Saludos mis estimados.
Ejemplos de códigos en VBScript Windows
Datos archivados del Taringa! original
0puntos
44visitas
0comentarios
Actividad nueva en Posteamelo
0puntos
1visitas
0comentarios
Dar puntos: