/* * To change this template, choose Tools | Templates * and open the template in the editor. */ /* * SpielGUI.java * * Created on 12.06.2012, 13:37:56 */ package spiel; import com.sun.corba.se.impl.orb.ParserTable.TestAcceptor1; import java.awt.Color; import java.awt.Component; import java.awt.event.KeyEvent; /** * * @author 0wg3viol */ public class SpielGUI extends javax.swing.JFrame { /** Creates new form SpielGUI */ public SpielGUI() { initComponents(); if (lblSpielfigur.getY() <= 718) { lblSpielfigur.setLocation(lblSpielfigur.getX(), 0); } else if (lblSpielfigur.getY() == 0) { lblSpielfigur.setLocation(lblSpielfigur.getX(), 718); } else if (lblSpielfigur.getX() <= 554) { lblSpielfigur.setLocation(0, lblSpielfigur.getY()); } else if (lblSpielfigur.getX() == 0) { lblSpielfigur.setLocation(554, lblSpielfigur.getY()); } } /** 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") // //GEN-BEGIN:initComponents private void initComponents() { jPanel1 = new javax.swing.JPanel(); lblSpielfigur = new javax.swing.JLabel(); lblSchuss = new javax.swing.JLabel(); setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); addKeyListener(new java.awt.event.KeyAdapter() { public void keyPressed(java.awt.event.KeyEvent evt) { formKeyPressed(evt); } }); jPanel1.setLayout(null); lblSpielfigur.setFont(new java.awt.Font("Wide Latin", 0, 12)); // NOI18N lblSpielfigur.setText("A"); jPanel1.add(lblSpielfigur); lblSpielfigur.setBounds(320, 280, 210, 20); lblSpielfigur.getAccessibleContext().setAccessibleName("Spielfigur"); lblSchuss.setText("o"); jPanel1.add(lblSchuss); lblSchuss.setBounds(310, 260, 200, 14); javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); getContentPane().setLayout(layout); layout.setHorizontalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, 718, Short.MAX_VALUE) ); layout.setVerticalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, 554, Short.MAX_VALUE) ); pack(); }// //GEN-END:initComponents private void formKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_formKeyPressed int spielfigurX = lblSpielfigur.getX(); int spielfigurY = lblSpielfigur.getY(); lblSpielfigur.setText("x:" + spielfigurX + ", y:" + spielfigurY); switch (evt.getKeyCode()) { case KeyEvent.VK_UP: lblSpielfigur.setLocation(lblSpielfigur.getX(), lblSpielfigur.getY() - 10); break; case KeyEvent.VK_DOWN: lblSpielfigur.setLocation(lblSpielfigur.getX(), lblSpielfigur.getY() + 10); break; case KeyEvent.VK_RIGHT: lblSpielfigur.setLocation(lblSpielfigur.getX() + 10, lblSpielfigur.getY()); break; case KeyEvent.VK_LEFT: lblSpielfigur.setLocation(lblSpielfigur.getX() - 10, lblSpielfigur.getY()); break; case KeyEvent.VK_SPACE: lblSchuss.setVisible(true); lblSchuss.setLocation(20, 20); schiessen(); break; } }//GEN-LAST:event_formKeyPressed /** * @param args the command line arguments */ public static void main(String args[]) { /* Set the Nimbus look and feel */ // /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel. * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html */ try { for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) { if ("Nimbus".equals(info.getName())) { javax.swing.UIManager.setLookAndFeel(info.getClassName()); break; } } } catch (ClassNotFoundException ex) { java.util.logging.Logger.getLogger(SpielGUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } catch (InstantiationException ex) { java.util.logging.Logger.getLogger(SpielGUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } catch (IllegalAccessException ex) { java.util.logging.Logger.getLogger(SpielGUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } catch (javax.swing.UnsupportedLookAndFeelException ex) { java.util.logging.Logger.getLogger(SpielGUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } // /* Create and display the form */ java.awt.EventQueue.invokeLater(new Runnable() { public void run() { new SpielGUI().setVisible(true); } }); } public void schiessen() { int linkerrand = (int) jPanel1.getBounds().getMinX(); int rechterrand = (int) jPanel1.getBounds().getMaxX(); int untererrand = (int) jPanel1.getBounds().getMaxY(); int obererrand = (int) jPanel1.getBounds().getMinY(); Component a = (Component) lblSchuss; Schuss schuss = new Schuss(a, lblSpielfigur, obererrand); schuss.start(); } // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.JPanel jPanel1; private javax.swing.JLabel lblSchuss; private javax.swing.JLabel lblSpielfigur; // End of variables declaration//GEN-END:variables }