From 1c4a2c25f0bcd196ae674ff52598ebb2d4bde06b Mon Sep 17 00:00:00 2001 From: Przemek Grondek Date: Wed, 13 Apr 2011 01:36:49 +0000 Subject: [PATCH] M Winda/src/winda/animation/ElevatorAnimation.java M Winda/src/winda/animation/ElevatorMovement.java M Winda/src/winda/gui/WindaView.form M Winda/src/winda/gui/WindaView.java M Winda/src/winda/logic/Pietro.java MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Próba uruchomienia animacji --- .../winda/animation/ElevatorAnimation.java | 2 +- .../src/winda/animation/ElevatorMovement.java | 80 +++++++++++++++---- Winda/src/winda/gui/WindaView.form | 7 ++ Winda/src/winda/gui/WindaView.java | 37 ++++++--- Winda/src/winda/logic/Pietro.java | 5 +- 5 files changed, 99 insertions(+), 32 deletions(-) diff --git a/Winda/src/winda/animation/ElevatorAnimation.java b/Winda/src/winda/animation/ElevatorAnimation.java index d5983f7..2c70054 100644 --- a/Winda/src/winda/animation/ElevatorAnimation.java +++ b/Winda/src/winda/animation/ElevatorAnimation.java @@ -53,7 +53,7 @@ public class ElevatorAnimation extends JApplet { } /* - * Buforowana klatka + * Buforowana klatki */ private BufferedImage buffImage(){ BufferedImage buffi = new BufferedImage(this.x_dimension, this.y_dmension, BufferedImage.TYPE_BYTE_GRAY); diff --git a/Winda/src/winda/animation/ElevatorMovement.java b/Winda/src/winda/animation/ElevatorMovement.java index b64d706..c83ddca 100644 --- a/Winda/src/winda/animation/ElevatorMovement.java +++ b/Winda/src/winda/animation/ElevatorMovement.java @@ -1,16 +1,16 @@ package winda.animation; +import java.awt.ScrollPane; import java.util.logging.Level; import java.util.logging.Logger; +import winda.gui.WindaApp; +import winda.logic.Pietro; /** * * @author Przemo */ -public class ElevatorMovement { -// private final int FPS = 50; /* Frames Per Second */ -// private final int THREAD_WAIT_TIME = 1000/this.FPS; - +public class ElevatorMovement { private ElevatorAnimation ea; private int floor_count; @@ -18,26 +18,32 @@ public class ElevatorMovement { private int time_for_floor; // Tymczasowo /* Miliseconds */ private int actual_floor; private double jump_time; + private double speed; + private int enter_exit_time; public ElevatorMovement(int floor_count){ this.floor_count = floor_count; this.init(); } - public void goToFloor(int number){ - if(this.actual_floornumber) - this.goDown(number); - this.actual_floor = number; + public void goToFloor(Pietro pietro){ + if(this.actual_floorpietro.numerPietra) + this.goDown(pietro.numerPietra); + this.actual_floor = pietro.numerPietra; + + this.exitElevator(pietro.pasazerowieWysiadajacy.size()); + this.enterElevator(pietro.pasazerowieWsiadający.size(), pietro.numerPietra); } private void goUp(int number){ + System.out.println(""+(this.jump_time*this.speed)); while(this.ea.shift>(this.floor_size*(this.floor_count-(number+1)))){ try { this.ea.shift--; this.ea.repaint(); - Thread.sleep((long) jump_time); + Thread.sleep((long) (this.jump_time*this.speed)); } catch (InterruptedException ex) { Logger.getLogger(ElevatorMovement.class.getName()).log(Level.SEVERE, null, ex); } @@ -49,13 +55,36 @@ public class ElevatorMovement { try { this.ea.shift++; this.ea.repaint(); - Thread.sleep((long) jump_time); + Thread.sleep((long) (this.jump_time)); } catch (InterruptedException ex) { Logger.getLogger(ElevatorMovement.class.getName()).log(Level.SEVERE, null, ex); } } } + private void exitElevator(int number){ + for(int i=0;i + + + @@ -699,6 +702,10 @@ + + + + diff --git a/Winda/src/winda/gui/WindaView.java b/Winda/src/winda/gui/WindaView.java index 1c990c8..210f69d 100644 --- a/Winda/src/winda/gui/WindaView.java +++ b/Winda/src/winda/gui/WindaView.java @@ -17,8 +17,9 @@ import javax.swing.Icon; import javax.swing.JDialog; import javax.swing.JFileChooser; import javax.swing.JFrame; -import winda.animation.ElevatorAnimation; import winda.animation.ElevatorMovement; +import winda.logic.Pasazer; +import winda.logic.Pietro; import winda.logic.Winda; /** @@ -26,7 +27,6 @@ import winda.logic.Winda; */ public class WindaView extends FrameView { private ElevatorMovement em; - private ElevatorAnimation ea; Winda w = new Winda(); public WindaView(SingleFrameApplication app) { super(app); @@ -91,19 +91,15 @@ public class WindaView extends FrameView { private void drawAnimation(){ this.em = new ElevatorMovement(12); - this.ea = this.em.getElevatorAnimation(); - this.scrollPane1.add(ea); + this.scrollPane1.add(em.getElevatorAnimation()); } - /** - * Not working yet :/ - * @param floor_count - */ private void newAnimation(int floor_count){ - this.scrollPane1.remove(this.ea); + this.scrollPane1.remove(this.em.getElevatorAnimation()); this.em.setFloorsCount(floor_count); - this.ea = this.em.getElevatorAnimation(); - this.scrollPane1.add(this.ea); + this.scrollPane1.add(this.em.getElevatorAnimation()); + this.scrollPane1.doLayout(); + this.scrollPane1.repaint(); } @Action @@ -510,6 +506,11 @@ public class WindaView extends FrameView { jButton4.setName("jButton4"); // NOI18N jSlider1.setName("jSlider1"); // NOI18N + jSlider1.addChangeListener(new javax.swing.event.ChangeListener() { + public void stateChanged(javax.swing.event.ChangeEvent evt) { + jSlider1StateChanged(evt); + } + }); jPanel5.setBorder(javax.swing.BorderFactory.createEtchedBorder()); jPanel5.setName("jPanel5"); // NOI18N @@ -733,6 +734,7 @@ public class WindaView extends FrameView { String ip = (String) jSpinner1.getValue().toString(); int iloscPieter = Integer.parseInt(ip); w.SetIloscPieter(iloscPieter); + this.newAnimation(iloscPieter); }//GEN-LAST:event_jSpinner1StateChanged private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed @@ -756,6 +758,12 @@ public class WindaView extends FrameView { private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed // TODO add your handling code here: + Pietro p = new Pietro(); + p.numerPietra = 2; + p.pasazerowieWsiadający.add(new Pasazer(0,2,2)); + this.em.setPassangersOnFloor(2, 1); + em.setTimeForFloor(1000); + this.em.goToFloor(p); }//GEN-LAST:event_jButton1ActionPerformed private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed @@ -774,6 +782,11 @@ public class WindaView extends FrameView { w.ZapiszPasazerow(fc.getSelectedFile().getPath()); }//GEN-LAST:event_jMenuItem2ActionPerformed + private void jSlider1StateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_jSlider1StateChanged + this.em.setSpeed(this.jSlider1.getValue()); + // TODO add your handling code here: + }//GEN-LAST:event_jSlider1StateChanged + // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.ButtonGroup buttonGroup1; private javax.swing.ButtonGroup buttonGroup2; @@ -825,7 +838,7 @@ public class WindaView extends FrameView { private javax.swing.JTextField jTextField1; private javax.swing.JPanel mainPanel; private javax.swing.JMenuBar menuBar; - private java.awt.ScrollPane scrollPane1; + public transient java.awt.ScrollPane scrollPane1; // End of variables declaration//GEN-END:variables private final Timer messageTimer; diff --git a/Winda/src/winda/logic/Pietro.java b/Winda/src/winda/logic/Pietro.java index 1d62cea..29cc50e 100644 --- a/Winda/src/winda/logic/Pietro.java +++ b/Winda/src/winda/logic/Pietro.java @@ -5,6 +5,7 @@ package winda.logic; +import java.util.ArrayList; import java.util.List; /** @@ -12,7 +13,7 @@ import java.util.List; * @author Tomek */ public class Pietro { - public List pasazerowieWsiadający; - public List pasazerowieWysiadajacy; + public List pasazerowieWsiadający = new ArrayList(); + public List pasazerowieWysiadajacy = new ArrayList(); public int numerPietra; }