SOlO
este es el codigo que tengo, si me pudieran ayudar diciend donde me equivoco y como podria implementarlo
Código
import java.awt.BorderLayout; import java.awt.Color; import javax.swing.*; import java.awt.Graphics; import java.awt.Graphics2D; import java.awt.Image; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.image.BufferStrategy; import java.io.IOException; import java.io.InputStream; import java.security.Principal; import javax.imageio.ImageIO; Image fondo; InputStream imgStream; Timer timer1; private BufferStrategy estrategia; int numeroImagen=0; public Motor() { super("STEPPER MOTOR SIMULATOR"); // declaracion de variables del GUI // Agregando a nuestro Desktop principal.add(modo); principal.add(labelAutomatico); principal.add(botonAutomatico); principal.add(botonStop); principal.add(labelManual); principal.add(labelRPM); principal.add(direccion); principal.add(rpm); principal.add(labelGrados); principal.add(grados); principal.add(dir); principal.add(run); principal.add(simulador); // Dando Ubicacion modo.setBounds(120, 30, 40, 30); labelAutomatico.setBounds(20, 100, 1000, 20); botonAutomatico.setBounds(120,100, 70, 20); botonStop.setBounds(200, 100, 70, 20); labelManual.setBounds(20, 160, 80, 20); labelRPM.setBounds(50, 190, 30, 20); labelGrados.setBounds(150, 190, 50, 20); direccion.setBounds(250, 190, 100, 20); rpm.setBounds(50, 230, 50, 20); grados.setBounds(150, 230, 50, 20); dir.setBounds(250, 230, 60, 20); run.setBounds(120, 290, 120, 20); simulador.setBounds(380, 30, 228, 231); // Frame this.setResizable(false); this.setSize(650, 390); this.setLocationRelativeTo(null); this.setVisible(true); /* botonAutomatico.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { cargaImagen(); repaint(); run(); } }); //*********************** botonStop.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { } }); */ }// fin del constructor // se crea un objeto para inicializar Motor obj = new Motor(); }// fin del main public void cargaImagen() { try { fondo = ImageIO.read(imgStream); for (int i = 0; i < 36; i++) { img[i] = ImageIO.read(imgStream); } e.printStackTrace(); } } public void run() { if(numeroImagen <= 35) { numeroImagen++; } else { numeroImagen = 0; } } g3.drawImage(img[numeroImagen], 380, 30, 228, 231, null); estrategia.show(); repaint(); } }
estos son los errores que me muestra:
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at Motor.paint(Motor.java:180)
at javax.swing.RepaintManager$3.run(RepaintManager.java:825)
at javax.swing.RepaintManager$3.run(RepaintManager.java:802)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:87)
at javax.swing.RepaintManager.paintDirtyRegions(RepaintManager.java:802)
at javax.swing.RepaintManager.paintDirtyRegions(RepaintManager.java:745)
at javax.swing.RepaintManager.prePaintDirtyRegions(RepaintManager.java:725)
at javax.swing.RepaintManager.access$1000(RepaintManager.java:46)
at javax.swing.RepaintManager$ProcessingRunnable.run(RepaintManager.java:1668)
at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:209)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:672)
at java.awt.EventQueue.access$400(EventQueue.java:81)
at java.awt.EventQueue$2.run(EventQueue.java:633)
at java.awt.EventQueue$2.run(EventQueue.java:631)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:87)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:642)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:269)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:184)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:174)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:169)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:161)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at Motor.paint(Motor.java:182)
at javax.swing.RepaintManager$3.run(RepaintManager.java:825)
at javax.swing.RepaintManager$3.run(RepaintManager.java:802)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:87)
at javax.swing.RepaintManager.paintDirtyRegions(RepaintManager.java:802)
at javax.swing.RepaintManager.paintDirtyRegions(RepaintManager.java:745)
at javax.swing.RepaintManager.prePaintDirtyRegions(RepaintManager.java:725)
at javax.swing.RepaintManager.access$1000(RepaintManager.java:46)
at javax.swing.RepaintManager$ProcessingRunnable.run(RepaintManager.java:1668)
at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:209)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:672)
at java.awt.EventQueue.access$400(EventQueue.java:81)
at java.awt.EventQueue$2.run(EventQueue.java:633)
at java.awt.EventQueue$2.run(EventQueue.java:631)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:87)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:642)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:269)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:184)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:174)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:169)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:161)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)
anexo una imagen de lo que quiero hacer...
Gracias de antemano
necesito mostrar en ese JPanel las imagenes una tras otra cuando presione el boton RUN. les agradezco su ayuda.... solo con un pequeño consejo yo ya resuelvo lo demas
Pd: volvi a hacer el codigo de ceros (sin usar el editor de netbeans, para que quedara mas entendible el codigo )