Ryoutt

Untitled

Apr 26th, 2015
213
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 16.35 KB | None | 0 0
  1.  
  2. import java.awt.event.KeyEvent;
  3. import java.io.File;
  4. import java.io.FileWriter;
  5. import javax.print.DocFlavor;
  6. import javax.swing.Icon;
  7. import javax.swing.ImageIcon;
  8. import javax.swing.JButton;
  9. import javax.swing.JOptionPane;
  10.  
  11. public class PainelRobo extends javax.swing.JFrame {
  12.  
  13.     public PainelRobo() {
  14.         initComponents();
  15.     }
  16.  
  17.     @SuppressWarnings("unchecked")
  18.     // <editor-fold defaultstate="collapsed" desc="Generated Code">                          
  19.     private void initComponents() {
  20.  
  21.         Frente = new javax.swing.JButton();
  22.         Esquerda = new javax.swing.JButton();
  23.         Tras = new javax.swing.JButton();
  24.         Direita = new javax.swing.JButton();
  25.         Atacar = new javax.swing.JButton();
  26.         Title = new javax.swing.JLabel();
  27.  
  28.         setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
  29.  
  30.         Frente.setIcon(new javax.swing.ImageIcon("C:\\Users\\Gabriel\\Documents\\Net Beans\\Trabalho Robó\\Frente.png")); // NOI18N
  31.         Frente.addActionListener(new java.awt.event.ActionListener() {
  32.             public void actionPerformed(java.awt.event.ActionEvent evt) {
  33.                 FrenteActionPerformed(evt);
  34.             }
  35.         });
  36.         Frente.addKeyListener(new java.awt.event.KeyAdapter() {
  37.             public void keyPressed(java.awt.event.KeyEvent evt) {
  38.                 FrenteKeyPressed(evt);
  39.             }
  40.         });
  41.  
  42.         Esquerda.setIcon(new javax.swing.ImageIcon("C:\\Users\\Gabriel\\Documents\\Net Beans\\Trabalho Robó\\Esquerda.png")); // NOI18N
  43.         Esquerda.addActionListener(new java.awt.event.ActionListener() {
  44.             public void actionPerformed(java.awt.event.ActionEvent evt) {
  45.                 EsquerdaActionPerformed(evt);
  46.             }
  47.         });
  48.  
  49.         Tras.setIcon(new javax.swing.ImageIcon("C:\\Users\\Gabriel\\Documents\\Net Beans\\Trabalho Robó\\Trás.png")); // NOI18N
  50.         Tras.addActionListener(new java.awt.event.ActionListener() {
  51.             public void actionPerformed(java.awt.event.ActionEvent evt) {
  52.                 TrasActionPerformed(evt);
  53.             }
  54.         });
  55.  
  56.         Direita.setIcon(new javax.swing.ImageIcon("C:\\Users\\Gabriel\\Documents\\Net Beans\\Trabalho Robó\\Direita.png")); // NOI18N
  57.         Direita.addActionListener(new java.awt.event.ActionListener() {
  58.             public void actionPerformed(java.awt.event.ActionEvent evt) {
  59.                 DireitaActionPerformed(evt);
  60.             }
  61.         });
  62.  
  63.         Atacar.setIcon(new javax.swing.ImageIcon("C:\\Users\\Gabriel\\Documents\\Net Beans\\Trabalho Robó\\Atacar.png")); // NOI18N
  64.         Atacar.addActionListener(new java.awt.event.ActionListener() {
  65.             public void actionPerformed(java.awt.event.ActionEvent evt) {
  66.                 AtacarActionPerformed(evt);
  67.             }
  68.         });
  69.  
  70.         Title.setText("MAG  OF  WAR!");
  71.  
  72.         javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
  73.         getContentPane().setLayout(layout);
  74.         layout.setHorizontalGroup(
  75.             layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  76.             .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
  77.                 .addContainerGap(84, Short.MAX_VALUE)
  78.                 .addComponent(Esquerda)
  79.                 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
  80.                 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
  81.                     .addComponent(Title, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
  82.                     .addComponent(Tras, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
  83.                     .addComponent(Frente, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
  84.                 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
  85.                 .addComponent(Direita)
  86.                 .addGap(84, 84, 84))
  87.             .addGroup(layout.createSequentialGroup()
  88.                 .addComponent(Atacar)
  89.                 .addGap(0, 0, Short.MAX_VALUE))
  90.         );
  91.         layout.setVerticalGroup(
  92.             layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  93.             .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
  94.                 .addContainerGap(23, Short.MAX_VALUE)
  95.                 .addComponent(Title)
  96.                 .addGap(18, 18, 18)
  97.                 .addComponent(Frente)
  98.                 .addGap(31, 31, 31)
  99.                 .addComponent(Tras)
  100.                 .addGap(70, 70, 70))
  101.             .addGroup(layout.createSequentialGroup()
  102.                 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  103.                     .addGroup(layout.createSequentialGroup()
  104.                         .addGap(95, 95, 95)
  105.                         .addComponent(Direita))
  106.                     .addGroup(layout.createSequentialGroup()
  107.                         .addGap(95, 95, 95)
  108.                         .addComponent(Esquerda)))
  109.                 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
  110.                 .addComponent(Atacar))
  111.         );
  112.  
  113.         pack();
  114.     }// </editor-fold>                        
  115.  
  116.     int i;
  117.     private void FrenteActionPerformed(java.awt.event.ActionEvent evt) {                                      
  118.         try {
  119.             String conteudo = "1";
  120.             String pasta = "";
  121.             String nomeArquivo = null;
  122.             if (nomeArquivo == String.valueOf(i)) {
  123.                 nomeArquivo = String.valueOf(i + 1);
  124.             } else {
  125.                 nomeArquivo = String.valueOf(i).toString();
  126.             }
  127.             i++;
  128.             File novoArquivo = new File(pasta + nomeArquivo + ".txt");
  129.             FileWriter fw = new FileWriter(novoArquivo);
  130.             fw.write(conteudo);
  131.             fw.close();
  132.             System.out.println("Gravado " + nomeArquivo + ", conteúdo: " + conteudo);
  133.             Thread.sleep(500);
  134.         } catch (Exception ex) {
  135.             JOptionPane.showMessageDialog(null, "ERRO: " + ex.getMessage(), "ERRO", JOptionPane.ERROR_MESSAGE);
  136.         }
  137.     }                                      
  138.  
  139.     private void EsquerdaActionPerformed(java.awt.event.ActionEvent evt) {                                        
  140.         try {
  141.             String conteudo = "4";
  142.             String pasta = "";
  143.             String nomeArquivo = null;
  144.             if (nomeArquivo == String.valueOf(i)) {
  145.                 nomeArquivo = String.valueOf(i + 1);
  146.             } else {
  147.                 nomeArquivo = String.valueOf(i).toString();
  148.             }
  149.             i++;
  150.             File novoArquivo = new File(pasta + nomeArquivo + ".txt");
  151.             FileWriter fw = new FileWriter(novoArquivo);
  152.             fw.write(conteudo);
  153.             fw.close();
  154.             System.out.println("Gravado " + nomeArquivo + ", conteúdo: " + conteudo);
  155.             Thread.sleep(500);
  156.         } catch (Exception ex) {
  157.             JOptionPane.showMessageDialog(null, "ERRO: " + ex.getMessage(), "ERRO", JOptionPane.ERROR_MESSAGE);
  158.         }
  159.     }                                        
  160.  
  161.     private void TrasActionPerformed(java.awt.event.ActionEvent evt) {                                    
  162.         try {
  163.             String conteudo = "2";
  164.             String pasta = "";
  165.             String nomeArquivo = null;
  166.             if (nomeArquivo == String.valueOf(i)) {
  167.                 nomeArquivo = String.valueOf(i + 1);
  168.             } else {
  169.                 nomeArquivo = String.valueOf(i).toString();
  170.             }
  171.             i++;
  172.             File novoArquivo = new File(pasta + nomeArquivo + ".txt");
  173.             FileWriter fw = new FileWriter(novoArquivo);
  174.             fw.write(conteudo);
  175.             fw.close();
  176.             System.out.println("Gravado " + nomeArquivo + ", conteúdo: " + conteudo);
  177.             Thread.sleep(500);
  178.         } catch (Exception ex) {
  179.             JOptionPane.showMessageDialog(null, "ERRO: " + ex.getMessage(), "ERRO", JOptionPane.ERROR_MESSAGE);
  180.         }
  181.     }                                    
  182.  
  183.     private void DireitaActionPerformed(java.awt.event.ActionEvent evt) {                                        
  184.         try {
  185.             String conteudo = "3";
  186.             String pasta = "";
  187.             String nomeArquivo = null;
  188.             if (nomeArquivo == String.valueOf(i)) {
  189.                 nomeArquivo = String.valueOf(i + 1);
  190.             } else {
  191.                 nomeArquivo = String.valueOf(i).toString();
  192.             }
  193.             i++;
  194.             File novoArquivo = new File(pasta + nomeArquivo + ".txt");
  195.             FileWriter fw = new FileWriter(novoArquivo);
  196.             fw.write(conteudo);
  197.             fw.close();
  198.             System.out.println("Gravado " + nomeArquivo + ", conteúdo: " + conteudo);
  199.             Thread.sleep(500);
  200.         } catch (Exception ex) {
  201.             JOptionPane.showMessageDialog(null, "ERRO: " + ex.getMessage(), "ERRO", JOptionPane.ERROR_MESSAGE);
  202.         }
  203.     }                                      
  204.  
  205.     private void AtacarActionPerformed(java.awt.event.ActionEvent evt) {                                      
  206.         try {
  207.             String conteudo = "5";
  208.             String pasta = "";
  209.             String nomeArquivo = null;
  210.             if (nomeArquivo == String.valueOf(i)) {
  211.                 nomeArquivo = String.valueOf(i + 1);
  212.             } else {
  213.                 nomeArquivo = String.valueOf(i).toString();
  214.             }
  215.             i++;
  216.             File novoArquivo = new File(pasta + nomeArquivo + ".txt");
  217.             FileWriter fw = new FileWriter(novoArquivo);
  218.             fw.write(conteudo);
  219.             fw.close();
  220.             System.out.println("Gravado " + nomeArquivo + ", conteúdo: " + conteudo);
  221.             Thread.sleep(500);
  222.         } catch (Exception ex) {
  223.             JOptionPane.showMessageDialog(null, "ERRO: " + ex.getMessage(), "ERRO", JOptionPane.ERROR_MESSAGE);
  224.         }
  225.     }                                      
  226.  
  227.     private void FrenteKeyPressed(java.awt.event.KeyEvent evt) {                                  
  228.         if (evt.getKeyChar() == 'w') {
  229.             try {
  230.                 String conteudo = "1";
  231.                 String pasta = "";
  232.                 String nomeArquivo = null;
  233.                 if (nomeArquivo == String.valueOf(i)) {
  234.                     nomeArquivo = String.valueOf(i + 1);
  235.                 } else {
  236.                     nomeArquivo = String.valueOf(i).toString();
  237.                 }
  238.                 i++;
  239.                 File novoArquivo = new File(pasta + nomeArquivo + ".txt");
  240.                 FileWriter fw = new FileWriter(novoArquivo);
  241.                 fw.write(conteudo);
  242.                 fw.close();
  243.                 System.out.println("Gravado " + nomeArquivo + ", conteúdo: " + conteudo);
  244.                 Thread.sleep(500);
  245.             } catch (Exception ex) {
  246.                 JOptionPane.showMessageDialog(null, "ERRO: " + ex.getMessage(), "ERRO", JOptionPane.ERROR_MESSAGE);
  247.             }
  248.  
  249.         } else {
  250.             if (evt.getKeyChar() == 'a') {
  251.                 try {
  252.                     String conteudo = "4";
  253.                     String pasta = "";
  254.                     String nomeArquivo = null;
  255.                     if (nomeArquivo == String.valueOf(i)) {
  256.                         nomeArquivo = String.valueOf(i + 1);
  257.                     } else {
  258.                         nomeArquivo = String.valueOf(i).toString();
  259.                     }
  260.                     i++;
  261.                     File novoArquivo = new File(pasta + nomeArquivo + ".txt");
  262.                     FileWriter fw = new FileWriter(novoArquivo);
  263.                     fw.write(conteudo);
  264.                     fw.close();
  265.                     System.out.println("Gravado " + nomeArquivo + ", conteúdo: " + conteudo);
  266.                     Thread.sleep(500);
  267.                 } catch (Exception ex) {
  268.                     JOptionPane.showMessageDialog(null, "ERRO: " + ex.getMessage(), "ERRO", JOptionPane.ERROR_MESSAGE);
  269.                 }
  270.             } else {
  271.                 if (evt.getKeyChar() == 's') {
  272.                     try {
  273.                         String conteudo = "2";
  274.                         String pasta = "";
  275.                         String nomeArquivo = null;
  276.                         if (nomeArquivo == String.valueOf(i)) {
  277.                             nomeArquivo = String.valueOf(i + 1);
  278.                         } else {
  279.                             nomeArquivo = String.valueOf(i).toString();
  280.                         }
  281.                         i++;
  282.                         File novoArquivo = new File(pasta + nomeArquivo + ".txt");
  283.                         FileWriter fw = new FileWriter(novoArquivo);
  284.                         fw.write(conteudo);
  285.                         fw.close();
  286.                         System.out.println("Gravado " + nomeArquivo + ", conteúdo: " + conteudo);
  287.                         Thread.sleep(500);
  288.                     } catch (Exception ex) {
  289.                         JOptionPane.showMessageDialog(null, "ERRO: " + ex.getMessage(), "ERRO", JOptionPane.ERROR_MESSAGE);
  290.                     }
  291.                 } else {
  292.                     if (evt.getKeyChar() == 'd') {
  293.                         try {
  294.                             String conteudo = "3";
  295.                             String pasta = "";
  296.                             String nomeArquivo = null;
  297.                             if (nomeArquivo == String.valueOf(i)) {
  298.                                 nomeArquivo = String.valueOf(i + 1);
  299.                             } else {
  300.                                 nomeArquivo = String.valueOf(i).toString();
  301.                             }
  302.                             i++;
  303.                             File novoArquivo = new File(pasta + nomeArquivo + ".txt");
  304.                             FileWriter fw = new FileWriter(novoArquivo);
  305.                             fw.write(conteudo);
  306.                             fw.close();
  307.                             System.out.println("Gravado " + nomeArquivo + ", conteúdo: " + conteudo);
  308.                             Thread.sleep(500);
  309.                         } catch (Exception ex) {
  310.                             JOptionPane.showMessageDialog(null, "ERRO: " + ex.getMessage(), "ERRO", JOptionPane.ERROR_MESSAGE);
  311.                         }
  312.                     } else {
  313.                         if (evt.getKeyChar() == 'l') {
  314.                             try {
  315.                                 String conteudo = "5";
  316.                                 String pasta = "";
  317.                                 String nomeArquivo = null;
  318.                                 if (nomeArquivo == String.valueOf(i)) {
  319.                                     nomeArquivo = String.valueOf(i + 1);
  320.                                 } else {
  321.                                     nomeArquivo = String.valueOf(i).toString();
  322.                                 }
  323.                                 i++;
  324.                                 File novoArquivo = new File(pasta + nomeArquivo + ".txt");
  325.                                 FileWriter fw = new FileWriter(novoArquivo);
  326.                                 fw.write(conteudo);
  327.                                 fw.close();
  328.                                 System.out.println("Gravado " + nomeArquivo + ", conteúdo: " + conteudo);
  329.                                 Thread.sleep(500);
  330.                             } catch (Exception ex) {
  331.                                 JOptionPane.showMessageDialog(null, "ERRO: " + ex.getMessage(), "ERRO", JOptionPane.ERROR_MESSAGE);
  332.                             }
  333.                         }
  334.                     }
  335.                 }
  336.             }
  337.         }
  338.     }                                
  339.  
  340.     public static void main(String args[]) {
  341.  
  342.         java.awt.EventQueue.invokeLater(new Runnable() {
  343.             public void run() {
  344.                 new PainelRobo().setVisible(true);
  345.             }
  346.         });
  347.     }
  348.  
  349.     // Variables declaration - do not modify                    
  350.     private javax.swing.JButton Atacar;
  351.     private javax.swing.JButton Direita;
  352.     private javax.swing.JButton Esquerda;
  353.     private javax.swing.JButton Frente;
  354.     private javax.swing.JLabel Title;
  355.     private javax.swing.JButton Tras;
  356.     // End of variables declaration                  
  357. }
Advertisement
Add Comment
Please, Sign In to add comment