olavexz Posted June 27, 2011 Report Share Posted June 27, 2011 hola a todos, me gustaría saber si me pueden ayudar con mi problema el cual consiste en: tengo que crear un programa el cual la aga de recepcionista en un aeropuerto... iba todo bien hasta la parte en que se debia agregar una animacion en la cual la maleta se moveria de izquiera a derecha... para ello se me ocurrio ocupar el teclado pero no responde a la imagen... codigo package Clases; import javax.swing.Icon; import javax.swing.ImageIcon; import javax.swing.JOptionPane; public class Envio_Equipaje extends javax.swing.JDialog { private String nombre [] = {"","/imagenes/maleta.png","/imagenes/mochila.png","/imagenes/bolsos.png"};// se llama al paquete imagen para insetar en la aplicacion private Icon iconos [] = // declara un metodo para elegir en el menu de forma ordenada { new ImageIcon(getClass().getResource(nombre[0])),// obetiene una imagen atravez de array y se guardar por defecto para hacer la seleccion new ImageIcon(getClass().getResource(nombre[1])), new ImageIcon(getClass().getResource(nombre[2])), new ImageIcon(getClass().getResource(nombre[3])) }; /** Creates new form Jf_formularioHijo */ public Envio_Equipaje(java.awt.Frame parent, boolean modal) { // primer constructor por defecto que guarda seleccion del menu jcombox super(parent, modal); initComponents(); jComboBox1.removeAllItems(); jComboBox1.addItem("Seleccione"); jComboBox1.addItem("Maleta"); jComboBox1.addItem("Mochila"); jComboBox1.addItem("bolso"); } //abajo se creo otro constructor igual al por defecto y se implementa segun la plantilla que hemos creado en cual se seleciona en menu anteior mencionado public Envio_Equipaje(java.awt.Frame parent, boolean modal,String ImprimeTicket, String pasajero , String destino, int vueloN, String Equipajes, int peso, int cantidad, double sobreEquipaje ,double Peso_excede, double Valor_SobreEquipaje) { super(parent, modal); initComponents(); this.jLabel8.setText(ImprimeTicket+""); this.jTextField1.setText(pasajero+""); this.jTextField2.setText(destino+""); this.jTextField3.setText(vueloN+""); this.jTextField9.setText(Equipajes+""); this.jTextField10.setText(peso+""); this.jTextField4.setText(cantidad+""); this.jTextField6.setText(sobreEquipaje+""); this.jTextField7.setText(Valor_SobreEquipaje+""); this.jTextField8.requestFocus(); } /** This method is called from within the constructor to * initialize the form. * WARNING: Do NOT modify this code. The content of this method is * always regenerated by the Form Editor. */ @SuppressWarnings("unchecked") // <editor-fold defaultstate="collapsed" desc="Generated Code"> private void initComponents() { jLabel2 = new javax.swing.JLabel(); jLabel1 = new javax.swing.JLabel(); jLabel3 = new javax.swing.JLabel(); jLabel4 = new javax.swing.JLabel(); jLabel6 = new javax.swing.JLabel(); jLabel7 = new javax.swing.JLabel(); jLabel8 = new javax.swing.JLabel(); jLabel9 = new javax.swing.JLabel(); jTextField1 = new javax.swing.JTextField(); jTextField4 = new javax.swing.JTextField(); jTextField6 = new javax.swing.JTextField(); jTextField2 = new javax.swing.JTextField(); jTextField3 = new javax.swing.JTextField(); jPanel1 = new javax.swing.JPanel(); jLabel10 = new javax.swing.JLabel(); jTextField8 = new javax.swing.JTextField(); jButton1 = new javax.swing.JButton(); jTextField7 = new javax.swing.JTextField(); jLabel11 = new javax.swing.JLabel(); jLabel12 = new javax.swing.JLabel(); jTextField9 = new javax.swing.JTextField(); jTextField10 = new javax.swing.JTextField(); jLabel13 = new javax.swing.JLabel(); jLabel5 = new javax.swing.JLabel(); jLabel14 = new javax.swing.JLabel(); jComboBox1 = new javax.swing.JComboBox(); jLabel15 = new javax.swing.JLabel(); jLabel16 = new javax.swing.JLabel(); setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE); getContentPane().setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout()); getContentPane().add(jLabel2, new org.netbeans.lib.awtextra.AbsoluteConstraints(477, 52, -1, -1)); jLabel1.setText("Pasajero:"); getContentPane().add(jLabel1, new org.netbeans.lib.awtextra.AbsoluteConstraints(50, 60, -1, -1)); jLabel3.setText("Destino:"); getContentPane().add(jLabel3, new org.netbeans.lib.awtextra.AbsoluteConstraints(60, 100, -1, -1)); jLabel4.setText("VueloN°:"); getContentPane().add(jLabel4, new org.netbeans.lib.awtextra.AbsoluteConstraints(60, 150, -1, -1)); jLabel6.setText("SobreEquipaje:"); getContentPane().add(jLabel6, new org.netbeans.lib.awtextra.AbsoluteConstraints(30, 320, -1, -1)); jLabel7.setText("Valor_SobreEquipaje:"); getContentPane().add(jLabel7, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 360, -1, -1)); getContentPane().add(jLabel8, new org.netbeans.lib.awtextra.AbsoluteConstraints(198, 22, -1, -1)); jLabel9.setText("Cantidad:"); getContentPane().add(jLabel9, new org.netbeans.lib.awtextra.AbsoluteConstraints(50, 280, -1, -1)); getContentPane().add(jTextField1, new org.netbeans.lib.awtextra.AbsoluteConstraints(130, 60, 225, -1)); getContentPane().add(jTextField4, new org.netbeans.lib.awtextra.AbsoluteConstraints(130, 280, 120, -1)); getContentPane().add(jTextField6, new org.netbeans.lib.awtextra.AbsoluteConstraints(130, 320, 50, -1)); getContentPane().add(jTextField2, new org.netbeans.lib.awtextra.AbsoluteConstraints(130, 100, 225, -1)); getContentPane().add(jTextField3, new org.netbeans.lib.awtextra.AbsoluteConstraints(130, 150, 90, -1)); jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder("Ingrese Pago")); jLabel10.setText("Pago"); jButton1.setText("Pagar"); jButton1.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButton1ActionPerformed(evt); } }); javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1); jPanel1.setLayout(jPanel1Layout); jPanel1Layout.setHorizontalGroup( jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel1Layout.createSequentialGroup() .addGap(51, 51, 51) .addComponent(jLabel10) .addGap(38, 38, 38) .addComponent(jTextField8, javax.swing.GroupLayout.PREFERRED_SIZE, 84, javax.swing.GroupLayout.PREFERRED_SIZE) .addGap(37, 37, 37) .addComponent(jButton1) .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) ); jPanel1Layout.setVerticalGroup( jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel1Layout.createSequentialGroup() .addGap(34, 34, 34) .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jLabel10) .addComponent(jTextField8, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(jButton1)) .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) ); getContentPane().add(jPanel1, new org.netbeans.lib.awtextra.AbsoluteConstraints(30, 390, 320, 100)); jTextField7.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jTextField7ActionPerformed(evt); } }); getContentPane().add(jTextField7, new org.netbeans.lib.awtextra.AbsoluteConstraints(130, 360, 70, -1)); jLabel11.setText("Equipajes:"); getContentPane().add(jLabel11, new org.netbeans.lib.awtextra.AbsoluteConstraints(50, 200, -1, -1)); jLabel12.setText("Peso:"); getContentPane().add(jLabel12, new org.netbeans.lib.awtextra.AbsoluteConstraints(70, 240, -1, -1)); getContentPane().add(jTextField9, new org.netbeans.lib.awtextra.AbsoluteConstraints(130, 200, 270, -1)); getContentPane().add(jTextField10, new org.netbeans.lib.awtextra.AbsoluteConstraints(130, 240, 70, -1)); jLabel13.setText("Kg"); getContentPane().add(jLabel13, new org.netbeans.lib.awtextra.AbsoluteConstraints(210, 240, -1, -1)); jLabel5.setText("Kg"); getContentPane().add(jLabel5, new org.netbeans.lib.awtextra.AbsoluteConstraints(190, 320, -1, -1)); jLabel14.setText("pesos"); getContentPane().add(jLabel14, new org.netbeans.lib.awtextra.AbsoluteConstraints(210, 360, -1, -1)); jComboBox1.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" })); jComboBox1.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jComboBox1ActionPerformed(evt); } }); getContentPane().add(jComboBox1, new org.netbeans.lib.awtextra.AbsoluteConstraints(460, 30, 100, -1)); jLabel15.setText("jLabel15"); jLabel15.addKeyListener(new java.awt.event.KeyAdapter() { public void keyPressed(java.awt.event.KeyEvent evt) { jLabel15KeyPressed(evt); } }); getContentPane().add(jLabel15, new org.netbeans.lib.awtextra.AbsoluteConstraints(530, 290, 150, 110)); jLabel16.setIcon(new javax.swing.ImageIcon(getClass().getResource("/imagenes/EnvioPOR_Ftransportadora.jpg"))); // NOI18N jLabel16.setText("jLabel16"); getContentPane().add(jLabel16, new org.netbeans.lib.awtextra.AbsoluteConstraints(430, 0, 720, 490)); pack(); }// </editor-fold> private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) { // TODO add your handling code here: double total=Double.parseDouble(this.jTextField7.getText()); double pago=Double.parseDouble(this.jTextField8.getText()); double diferencia=pago-total; // esto respresenta el boton salir en la clase y si el pago se puede efectuar y su difencia en el pago if (diferencia<0){ JOptionPane.showMessageDialog(this,"el pago no se puede efectuar","error",JOptionPane.ERROR_MESSAGE); } // paga la diferencia del comprobante del precio else{ JOptionPane.showMessageDialog(this,"Vuelto: "+diferencia,"ventana de pago",JOptionPane.INFORMATION_MESSAGE); this.dispose(); } } private void jTextField7ActionPerformed(java.awt.event.ActionEvent evt) { } private void jComboBox1ActionPerformed(java.awt.event.ActionEvent evt) { // int selector = jComboBox1.getSelectedIndex(); switch (selector){ case 0: break; case 1: jLabel15.setIcon(iconos[jComboBox1.getSelectedIndex()]); break; case 2: jLabel15.setIcon(iconos[jComboBox1.getSelectedIndex()]); break; case 3: jLabel15.setIcon(iconos[jComboBox1.getSelectedIndex()]); break; } } private void jLabel15KeyPressed(java.awt.event.KeyEvent evt) { switch(evt.getKeyCode()) { case KeyEvent.VK_RIGHT: //en esta parte es donde tengo problemas tablero1.moverDerecha(); break; case KeyEvent.VK_LEFT: tablero1.moverIzquierda(); break; } // TODO add your handling code here: } /** * @param args the command line arguments */ public static void main(String args[]) { java.awt.EventQueue.invokeLater(new Runnable() { @Override public void run() { Envio_Equipaje dialog = new Envio_Equipaje(new javax.swing.JFrame(), true); dialog.addWindowListener(new java.awt.event.WindowAdapter() { @Override public void windowClosing(java.awt.event.WindowEvent e) { System.exit(0); } }); dialog.setVisible(true); } }); } // Variables declaration - do not modify private javax.swing.JButton jButton1; private javax.swing.JComboBox jComboBox1; private javax.swing.JLabel jLabel1; private javax.swing.JLabel jLabel10; private javax.swing.JLabel jLabel11; private javax.swing.JLabel jLabel12; private javax.swing.JLabel jLabel13; private javax.swing.JLabel jLabel14; private javax.swing.JLabel jLabel15; private javax.swing.JLabel jLabel16; private javax.swing.JLabel jLabel2; private javax.swing.JLabel jLabel3; private javax.swing.JLabel jLabel4; private javax.swing.JLabel jLabel5; private javax.swing.JLabel jLabel6; private javax.swing.JLabel jLabel7; private javax.swing.JLabel jLabel8; private javax.swing.JLabel jLabel9; private javax.swing.JPanel jPanel1; private javax.swing.JTextField jTextField1; private javax.swing.JTextField jTextField10; private javax.swing.JTextField jTextField2; private javax.swing.JTextField jTextField3; private javax.swing.JTextField jTextField4; private javax.swing.JTextField jTextField6; private javax.swing.JTextField jTextField7; private javax.swing.JTextField jTextField8; private javax.swing.JTextField jTextField9; // End of variables declaration } Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now