Hola intento simular la rotacion de un motor tengo 36 imagenes que van de 10 en 10 grados que al pasar una tras otra dan efecto de rotacion.... necesito que al precionar el boton automatico me simule dicha rotacion con eso ya me guio en la parte manual que pide grados de rotacion y revoluciones por minuto
SOlO
este es el codigo que tengo, si me pudieran ayudar diciend donde me equivoco y como podria implementarlo
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 )
SOlO
este es el codigo que tengo, si me pudieran ayudar diciend donde me equivoco y como podria implementarlo
Código (java) [Seleccionar]
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;
public class Motor extends JFrame implements Runnable{
Image[] img;
Image fondo;
InputStream imgStream;
Timer timer1;
private BufferStrategy estrategia;
int numeroImagen=0;
public Motor() {
super("STEPPER MOTOR SIMULATOR");
JDesktopPane principal = new JDesktopPane();
// declaracion de variables del GUI
JLabel modo = new JLabel("MODO");
JLabel labelAutomatico = new JLabel("AUTOMATICO");
JButton botonAutomatico = new JButton("RUN");
JButton botonStop= new JButton("STOP");
JLabel labelManual = new JLabel("MANUAL:");
JLabel labelRPM = new JLabel("RPM");
JLabel direccion = new JLabel("DIRECCION");
final JTextField rpm = new JTextField();
JLabel labelGrados = new JLabel("GRADOS");
DefaultComboBoxModel dirModelo = new DefaultComboBoxModel(new String[]{"LEFT" ,"RIGTH"});
final JComboBox dir = new JComboBox(dirModelo);
final JTextField grados = new JTextField();
JButton run = new JButton("RUN");
JPanel simulador = new JPanel();
// Agregando a nuestro Desktop
principal.setBackground(new Color(180,180,180));
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.add(principal, BorderLayout.CENTER);
this.setResizable(false);
this.setSize(650, 390);
this.setLocationRelativeTo(null);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
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
public static void main(String[] args){
// se crea un objeto para inicializar
Motor obj = new Motor();
}// fin del main
public void cargaImagen() {
img = new Image[36];
try {
imgStream = Principal.class.getResourceAsStream("Imagenes/0.jpg");
fondo = ImageIO.read(imgStream);
for (int i = 0; i < 36; i++) {
imgStream = Principal.class.getResourceAsStream("Imagenes/"+i+".jpg");
img[i] = ImageIO.read(imgStream);
}
} catch (IOException e) {
e.printStackTrace();
}
}
public void run() {
if(numeroImagen <= 35) {
numeroImagen++;
}
else {
numeroImagen = 0;
}
}
public void paint(Graphics g) {
Graphics g3 = (Graphics2D) estrategia.getDrawGraphics();
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 )