Codigo Ensamblador En Java
Enviado por miguemon • 15 de Agosto de 2011 • 16.013 Palabras (65 Páginas) • 1.495 Visitas
package ensambueno;
import java.io.*;
import java.util.Vector;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.util.StringTokenizer;
public final class Main extends JFrame {
String ruta="";
String vector, codigo = "",vector2;
String a,b;
JLabel L1;
JTextField TF;
JTextArea TA,TA2;
String a1, a2, a3;
String x1, x2, x3, x4;
JScrollPane S1,S2;
JButton b1,b2,b3,b4,b5;
public Main (){
super("");
L1=new JLabel("Codigo");
b1=new JButton("Guardar");
b2=new JButton("Ensamblar");
b3=new JButton("Salir");
b4=new JButton("Abrir");
TA=new JTextArea(25,60);
S1=new JScrollPane(TA);
JPanel P1=new JPanel();
P1.add(b4);
P1.add(b1);
P1.add(b2);
P1.add(b3);
JPanel P2=new JPanel();
P2.add(S1);
this.add(P1,BorderLayout.NORTH);
this.add(L1,BorderLayout.CENTER);
this.add(P2,BorderLayout.SOUTH);
this.setSize(900,550);
this.setVisible(true);
this.setLocationRelativeTo(null);
b1.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent envento){
JFileChooser g=new JFileChooser();
int r=g.showSaveDialog(null);
if(r==JFileChooser.CANCEL_OPTION)
return;
ruta="";
ruta +=g.getSelectedFile();
File archivo=new File(ruta);
try{
BufferedWriter wri=new BufferedWriter(new FileWriter(archivo)); //f////Para leer el archivo
wri.write(TA.getText());
wri.close();
}catch(IOException error ){
} }
});
b2.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent enven){
File archivo = null;
archivo=new File(ruta);
try{
BufferedWriter wri=new BufferedWriter(new FileWriter(archivo));
wri.write(TA.getText());
wri.close();
}catch(IOException error ){
}
Main s=new Main (ruta);
}
});
b3.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent envent){
System.exit(0);
}
});
b4.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
ruta="";
contador=1;
JFileChooser s=new JFileChooser();
int r=s.showOpenDialog(null);
if(r==JFileChooser.CANCEL_OPTION)
return;
ruta+=s.getSelectedFile();
File archivo=new File(ruta);
try{
BufferedReader b=new BufferedReader(new FileReader(archivo));
String linea;
while((linea=b.readLine())!=null){
TA.append(linea);
TA.append("\n");
contador++;
}
}
catch(IOException er){
JOptionPane.showMessageDialog(null,"error en lectura de archivo");
}
}
});
}
String linea,ensam1,ensam2,ensam3;
int h=0;
String datos2;
String reg2="",reg="",Resultado = "";
String e,s,c,c1,t,y,u,o,m,p,ee,ss;
String xxx,xxx1,xxx2,xxx3,xxx4,xxx5,mmm,oo;
String oo2;
int contador,conta;
public Main (String as){
super("ENSAMBLAR");
TA2=new JTextArea(20,50);
S2=new JScrollPane(TA2);
b1=new JButton("GUARDAR");
b2=new JButton("OBTENER SALTOS");
this.add(b2,BorderLayout.NORTH);
this.add(S2,BorderLayout.CENTER);
this.add(b1,BorderLayout.SOUTH);
this.setSize(700,500);
this.setVisible(true);
this.setLocationRelativeTo(null);
b1.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent envento){
File archivo=new File("NUEVO.exe");
try{
BufferedWriter wri=new BufferedWriter(new FileWriter(archivo)); //f////Para leer el archivo
wri.write(TA2.getText());
wri.close();
}catch(IOException error ){
} }
});
b2.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent envento){
TA2.setText("");
String linea ="";
String ch[] = new String[40];
String ch1[] = new String[40];
Vector band = new Vector();
Vector band2 = new Vector();
int cont = 0,i;
int suma=0;
int res=0;
String num="";
int mas;
int tamaño;
try {
FileReader fr = new FileReader("NUEVO.EXE");
BufferedReader origen = new BufferedReader(fr);
while ((linea = origen.readLine()) != null) {
if(linea !=null){
band.addElement(linea);
band2.addElement(linea);
}
}
for (i = 1; i < band.size(); i++) {
if (band2 != null) {
vector2 = (String) band.elementAt(i);
ch[i]=vector2; }
}
for (i = 1; i < band.size(); i++) {
if (band != null) {
vector = (String) band.elementAt(i);
x1 = vector.substring(0, 2);
x2 = vector.substring(0, 3);
if (x1.equals("Je") || x2.equals("Jae") || x2.equals("Jbe")|| x2.equals("Jne")){
TA2.append("\n "+vector);
x3 = vector.substring(3, vector.length())+":";
x4 = vector.substring(4, vector.length()) + ":";
...