├── .github └── stale.yml ├── .gitignore ├── ClaseJavaFX ├── .classpath ├── .project ├── README.md ├── pom.xml ├── src │ └── main │ │ ├── java │ │ └── main │ │ │ ├── Main.java │ │ │ ├── Mario.java │ │ │ └── SpriteAnimation.java │ │ └── resources │ │ ├── die.wav │ │ ├── mario-background.png │ │ └── mario-sprites.png └── target │ ├── classes │ ├── die.wav │ ├── main │ │ ├── Main$1.class │ │ ├── Main$2.class │ │ ├── Main$3.class │ │ ├── Main$4.class │ │ ├── Main.class │ │ ├── Mario$1.class │ │ ├── Mario$2.class │ │ ├── Mario.class │ │ └── SpriteAnimation.class │ ├── mario-background.png │ └── mario-sprites.png │ └── maven-status │ └── maven-compiler-plugin │ └── compile │ └── default-compile │ ├── createdFiles.lst │ └── inputFiles.lst ├── GraphicsJavaFX ├── .classpath ├── .gitignore ├── .project ├── src │ └── main │ │ └── App.java └── tutorialJavaFX.txt ├── README.md ├── codegolf ├── .classpath ├── .project ├── src │ └── edu │ │ └── unlam │ │ └── taller │ │ └── codegolf │ │ └── SumaPrefijos.java └── test │ └── edu │ └── unlam │ └── taller │ └── codegolf │ └── SumaPrefijosTest.java ├── graphics ├── .classpath ├── .project ├── background.jpg ├── hit.wav ├── left.wav ├── lib │ └── javafx sdk 11 │ │ └── .javafx-jars ├── right.wav └── src │ ├── basics │ ├── javafx │ │ └── JavaFX.java │ └── swing │ │ ├── Frame.java │ │ ├── Main.java │ │ └── Panel.java │ └── demo_ball_real_time_with_gravity │ ├── Ball.java │ ├── JavaFXGame.java │ ├── Player.java │ ├── Sound.java │ ├── Sound2Channels.java │ ├── Sound2ChannelsFX.java │ └── SwingGame.java ├── hibernate-basico ├── .classpath ├── .project ├── lib │ ├── antlr-2.7.7.jar │ ├── classmate-1.3.0.jar │ ├── dom4j-1.6.1.jar │ ├── hibernate-commons-annotations-5.0.1.Final.jar │ ├── hibernate-core-5.2.11.Final.jar │ ├── hibernate-entitymanager.jar │ ├── hibernate-jpa-2.1-api-1.0.0.Final.jar │ ├── hibernate4-sqlite-dialect-0.1.2.jar │ ├── javassist-3.20.0-GA.jar │ ├── jboss-logging-3.3.0.Final.jar │ ├── jboss-transaction-api_1.2_spec-1.0.1.Final.jar │ ├── jta.jar │ ├── slf4j-api-1.7.7.jar │ ├── slf4j-simple-1.7.7.jar │ └── sqlite-jdbc-3.7.2.jar ├── prueba.sqlite └── src │ ├── com │ └── jwt │ │ └── hibernate │ │ ├── Departamento.java │ │ ├── HibernateApp.java │ │ ├── Persona.java │ │ ├── departamento.hbm.xml │ │ └── persona.hbm.xml │ └── hibernate.cfg.xml ├── sockets-basico ├── .classpath ├── .project └── src │ └── edu │ └── unlam │ └── taller │ ├── client │ └── Cliente.java │ └── server │ └── Servidor.java ├── swing-basico ├── .classpath ├── .project ├── agregar.png ├── clientes.png ├── editar.png ├── eliminar.png ├── lib │ └── jcalendar-1.4.jar ├── src │ └── edu │ │ └── unlam │ │ └── taller │ │ └── ventanas │ │ ├── Cliente.java │ │ ├── JABMCliente.java │ │ └── JPrincipal.java └── ver.png ├── swing-multiventana ├── .classpath ├── .project ├── README.md ├── sonido.wav └── src │ └── edu │ └── unlam │ └── taller │ └── multiventanas │ ├── JApp.java │ └── JConfig.java ├── threads ├── .classpath ├── .project └── src │ └── edu │ └── unlam │ └── taller │ └── threads │ ├── MiThread.java │ └── ThreadProductorConsumidor.java └── utils └── plantuml.jar /.github/stale.yml: -------------------------------------------------------------------------------- 1 | # Number of days of inactivity before a stale issue is closed 2 | daysUntilClose: 7 3 | # Issues with these labels will never be considered stale 4 | exemptLabels: 5 | - pinned 6 | - security 7 | # Label to use when marking an issue as stale 8 | staleLabel: wontfix 9 | # Comment to post when marking an issue as stale. Set to `false` to disable 10 | markComment: > 11 | Este PR se marcó automáticamente como abandonado porque no ha tenido actividad 12 | recientemente. Será cerrado si no se aplica ninguna medida opuesta. 13 | Gracias por las contribuciones. 14 | # Comment to post when closing a stale issue. Set to `false` to disable 15 | closeComment: > 16 | Lamentablemente este PR se debió cerrar por falta de actividad. 17 | 18 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .metadata 2 | **/bin 3 | **/.settings 4 | -------------------------------------------------------------------------------- /ClaseJavaFX/.classpath: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | -------------------------------------------------------------------------------- /ClaseJavaFX/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | ClaseJavaFX 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.jdt.core.javabuilder 10 | 11 | 12 | 13 | 14 | org.eclipse.m2e.core.maven2Builder 15 | 16 | 17 | 18 | 19 | 20 | org.eclipse.jdt.core.javanature 21 | org.eclipse.m2e.core.maven2Nature 22 | 23 | 24 | 25 | 1710944783784 26 | 27 | 30 28 | 29 | org.eclipse.core.resources.regexFilterMatcher 30 | node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__ 31 | 32 | 33 | 34 | 35 | -------------------------------------------------------------------------------- /ClaseJavaFX/README.md: -------------------------------------------------------------------------------- 1 | # JavaFX en Maven 2 | 3 | ## Cómo ejecutarlo 4 | 5 | 1. Click Derecho en el proyecto 6 | 2. Run As... 7 | 3. maven build 8 | 4. en Goals, especificar `javafx:run` 9 | 5. Luego de descargar las bibliotecas, debería comenzar la ejecución 10 | 11 | > Nota: Probablemente haya que configurar las propiedades del proyecto para establecer la versión de compilación en 1.8 o superior. 12 | -------------------------------------------------------------------------------- /ClaseJavaFX/pom.xml: -------------------------------------------------------------------------------- 1 | 4 | 4.0.0 5 | Taller 6 | ClaseJavaFX 7 | 0.0.1-SNAPSHOT 8 | 9 | 10 | UTF-8 11 | 1.8 12 | 1.8 13 | 0.0.8 14 | 15 | 16 | 17 | 18 | org.openjfx 19 | javafx 20 | 18.0.1 21 | pom 22 | 23 | 24 | org.openjfx 25 | javafx-fxml 26 | 18.0.1 27 | 28 | 29 | org.openjfx 30 | javafx-controls 31 | 18.0.1 32 | 33 | 34 | org.openjfx 35 | javafx-media 36 | 18.0.1 37 | 38 | 39 | 40 | 41 | 42 | 43 | org.openjfx 44 | javafx-maven-plugin 45 | ${javafx.maven.plugin.version} 46 | 47 | main.Main 48 | 49 | 50 | 51 | 52 | 53 | -------------------------------------------------------------------------------- /ClaseJavaFX/src/main/java/main/Main.java: -------------------------------------------------------------------------------- 1 | package main; 2 | 3 | import javafx.animation.AnimationTimer; 4 | import javafx.application.Application; 5 | import javafx.event.EventHandler; 6 | import javafx.scene.Group; 7 | import javafx.scene.Scene; 8 | import javafx.scene.image.Image; 9 | import javafx.scene.image.ImageView; 10 | import javafx.scene.input.KeyEvent; 11 | import javafx.scene.input.MouseEvent; 12 | import javafx.stage.Stage; 13 | 14 | public class Main extends Application { 15 | private static final double NANOS_IN_SECOND_D = 1_000_000_000.0; 16 | 17 | Mario mario; 18 | Scene currentScene; 19 | long previousNanoFrame; 20 | 21 | @Override 22 | public void start(Stage stage) { 23 | Group root = new Group(); 24 | currentScene = new Scene(root); 25 | 26 | Image fondo = new Image("file:src/main/resources/mario-background.png", 720, 720, false, false); 27 | ImageView imageView = new ImageView(fondo); 28 | root.getChildren().add(imageView); 29 | 30 | mario = new Mario(100, 624); 31 | root.getChildren().add(mario.getRender()); 32 | 33 | addUpdateEachFrameTimer(); 34 | 35 | stage.setScene(currentScene); 36 | stage.setTitle("FX básico | Programación Avanzada"); 37 | stage.show(); 38 | 39 | 40 | addInputEvents(); 41 | } 42 | 43 | private void addInputEvents() { 44 | currentScene.addEventHandler(KeyEvent.KEY_PRESSED, new EventHandler() { 45 | @Override 46 | public void handle(KeyEvent e) { 47 | switch (e.getCode()) { 48 | case RIGHT: 49 | case D: 50 | mario.setDirectionRight(true); 51 | break; 52 | case LEFT: 53 | case A: 54 | mario.setDirectionLeft(true); 55 | break; 56 | case Q: 57 | mario.die(); 58 | break; 59 | default: 60 | break; 61 | } 62 | } 63 | }); 64 | 65 | currentScene.addEventHandler(KeyEvent.KEY_RELEASED, new EventHandler() { 66 | @Override 67 | public void handle(KeyEvent e) { 68 | switch (e.getCode()) { 69 | case RIGHT: 70 | case D: 71 | mario.setDirectionRight(false); 72 | break; 73 | case LEFT: 74 | case A: 75 | mario.setDirectionLeft(false); 76 | break; 77 | 78 | default: 79 | break; 80 | } 81 | } 82 | }); 83 | 84 | mario.getRender().addEventHandler(MouseEvent.MOUSE_CLICKED, new EventHandler() { 85 | @Override 86 | public void handle(MouseEvent e) { 87 | mario.die(); 88 | } 89 | }); 90 | } 91 | 92 | private void addUpdateEachFrameTimer() { 93 | previousNanoFrame = System.nanoTime(); 94 | AnimationTimer gameTimer = new AnimationTimer() { 95 | @Override 96 | public void handle(long currentNano) { 97 | // Update tick 98 | update((currentNano - previousNanoFrame) / NANOS_IN_SECOND_D); 99 | previousNanoFrame = currentNano; 100 | } 101 | }; 102 | gameTimer.start(); 103 | } 104 | 105 | protected void update(double deltaTime) { 106 | mario.update(deltaTime); 107 | } 108 | 109 | public static void main(String[] args) { 110 | launch(); 111 | } 112 | } 113 | -------------------------------------------------------------------------------- /ClaseJavaFX/src/main/java/main/Mario.java: -------------------------------------------------------------------------------- 1 | package main; 2 | 3 | import javafx.animation.Animation; 4 | import javafx.animation.Interpolator; 5 | import javafx.animation.SequentialTransition; 6 | import javafx.animation.TranslateTransition; 7 | import javafx.geometry.Rectangle2D; 8 | import javafx.scene.Node; 9 | import javafx.scene.image.Image; 10 | import javafx.scene.image.ImageView; 11 | import javafx.scene.media.AudioClip; 12 | import javafx.util.Duration; 13 | 14 | public class Mario { 15 | private final int imageSpacing = 6; 16 | private final int width = 48; 17 | private final int height = 48; 18 | private final int speed = 300; 19 | private ImageView render; 20 | 21 | private double x = 0; 22 | private double y = 0; 23 | private boolean directionRight = false; 24 | private boolean directionLeft = false; 25 | private boolean dead = false; 26 | 27 | private SpriteAnimation runningAnimation; 28 | 29 | public Mario(int x, int y) { 30 | Image spriteImages = new Image("file:src/main/resources/mario-sprites.png", 136 * 3, 90 * 3, false, false); 31 | 32 | render = new ImageView(spriteImages); 33 | resetViewport(); 34 | // Seteo ancla en la mitad del eje X y en el pie del eje Y 35 | render.relocate(-width / 2, -height); 36 | 37 | setX(x); 38 | setY(y); 39 | 40 | runningAnimation = new SpriteAnimation(render, Duration.millis(200), 3, 3, 63, imageSpacing, imageSpacing, 41 | width, height); 42 | runningAnimation.setCycleCount(Animation.INDEFINITE); 43 | } 44 | 45 | private void resetViewport() { 46 | render.setViewport(new Rectangle2D(imageSpacing, imageSpacing, width, height)); 47 | } 48 | 49 | private void setX(double x) { 50 | if (x < width / 2) { 51 | x = width / 2; 52 | } else if (x > 720 - width / 2) { 53 | x = 720 - width / 2; 54 | } 55 | this.x = x; 56 | render.setX(x); 57 | } 58 | 59 | private void setY(double y) { 60 | this.y = y; 61 | render.setY(y); 62 | } 63 | 64 | private void checkHorizontal() { 65 | if (!dead) { 66 | if (directionLeft) { 67 | render.setScaleX(-1); 68 | runningAnimation.play(); 69 | } else if (directionRight) { 70 | render.setScaleX(1); 71 | runningAnimation.play(); 72 | } else { 73 | runningAnimation.stop(); 74 | resetViewport(); 75 | } 76 | } 77 | } 78 | 79 | public Node getRender() { 80 | return render; 81 | } 82 | 83 | public void update(double deltaTime) { 84 | if (!dead) { 85 | int direction = directionLeft ? -1 : (directionRight ? 1 : 0); 86 | setX(x + direction * speed * deltaTime); 87 | } 88 | } 89 | 90 | public void setDirectionRight(boolean b) { 91 | this.directionRight = b; 92 | checkHorizontal(); 93 | } 94 | 95 | public void setDirectionLeft(boolean b) { 96 | this.directionLeft = b; 97 | checkHorizontal(); 98 | } 99 | 100 | public void die() { 101 | if (!dead) { 102 | dead = true; 103 | 104 | AudioClip audioDie = new AudioClip("file:src/main/resources/die.wav"); 105 | audioDie.play(); 106 | 107 | runningAnimation.stop(); 108 | 109 | render.setViewport(new Rectangle2D(118 * 3, imageSpacing, width, height)); 110 | 111 | Interpolator gravityInterpolator = new Interpolator() { 112 | @Override 113 | protected double curve(double t) { 114 | return t * t; 115 | } 116 | }; 117 | 118 | Interpolator inverseGravityInterpolator = new Interpolator() { 119 | @Override 120 | protected double curve(double t) { 121 | return 1 - Math.pow(1 - t, 2); 122 | } 123 | }; 124 | 125 | TranslateTransition noTranslate = new TranslateTransition(Duration.millis(500)); 126 | 127 | TranslateTransition translateUp = new TranslateTransition(Duration.millis(500)); 128 | translateUp.setToY(-200); 129 | translateUp.setInterpolator(inverseGravityInterpolator); 130 | 131 | TranslateTransition translateDown = new TranslateTransition(Duration.millis(1500)); 132 | translateDown.setToY(800); 133 | translateUp.setInterpolator(gravityInterpolator); 134 | 135 | SequentialTransition sq = new SequentialTransition(render, noTranslate, translateUp, translateDown); 136 | 137 | sq.play(); 138 | } 139 | 140 | } 141 | } 142 | -------------------------------------------------------------------------------- /ClaseJavaFX/src/main/java/main/SpriteAnimation.java: -------------------------------------------------------------------------------- 1 | package main; 2 | 3 | import javafx.animation.Interpolator; 4 | import javafx.animation.Transition; 5 | import javafx.geometry.Rectangle2D; 6 | import javafx.scene.image.ImageView; 7 | import javafx.util.Duration; 8 | 9 | public class SpriteAnimation extends Transition { 10 | private final ImageView imageView; 11 | private final int count; 12 | private final int columns; 13 | private final int offsetX; 14 | private final int offsetY; 15 | private final int spaceBetween; 16 | private final int width; 17 | private final int height; 18 | 19 | private int lastIndex; 20 | 21 | public SpriteAnimation(ImageView imageView, Duration duration, int count, int columns, int offsetX, int offsetY, 22 | int spaceBetween, int width, int height) { 23 | this.imageView = imageView; 24 | this.count = count; 25 | this.columns = columns; 26 | this.offsetX = offsetX; 27 | this.offsetY = offsetY; 28 | this.spaceBetween = spaceBetween; 29 | this.width = width; 30 | this.height = height; 31 | setCycleDuration(duration); 32 | setInterpolator(Interpolator.LINEAR); 33 | } 34 | 35 | protected void interpolate(double k) { 36 | final int index = Math.min((int) Math.floor(k * count), count - 1); 37 | if (index != lastIndex) { 38 | final int x = (index % columns) * width + offsetX + spaceBetween * index; 39 | final int y = (index / columns) * height + offsetY; 40 | imageView.setViewport(new Rectangle2D(x, y, width, height)); 41 | lastIndex = index; 42 | } 43 | } 44 | } -------------------------------------------------------------------------------- /ClaseJavaFX/src/main/resources/die.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/programacion-avanzada/workspace-taller/b05546c78e064962434ef9543500d001452b7319/ClaseJavaFX/src/main/resources/die.wav -------------------------------------------------------------------------------- /ClaseJavaFX/src/main/resources/mario-background.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/programacion-avanzada/workspace-taller/b05546c78e064962434ef9543500d001452b7319/ClaseJavaFX/src/main/resources/mario-background.png -------------------------------------------------------------------------------- /ClaseJavaFX/src/main/resources/mario-sprites.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/programacion-avanzada/workspace-taller/b05546c78e064962434ef9543500d001452b7319/ClaseJavaFX/src/main/resources/mario-sprites.png -------------------------------------------------------------------------------- /ClaseJavaFX/target/classes/die.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/programacion-avanzada/workspace-taller/b05546c78e064962434ef9543500d001452b7319/ClaseJavaFX/target/classes/die.wav -------------------------------------------------------------------------------- /ClaseJavaFX/target/classes/main/Main$1.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/programacion-avanzada/workspace-taller/b05546c78e064962434ef9543500d001452b7319/ClaseJavaFX/target/classes/main/Main$1.class -------------------------------------------------------------------------------- /ClaseJavaFX/target/classes/main/Main$2.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/programacion-avanzada/workspace-taller/b05546c78e064962434ef9543500d001452b7319/ClaseJavaFX/target/classes/main/Main$2.class -------------------------------------------------------------------------------- /ClaseJavaFX/target/classes/main/Main$3.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/programacion-avanzada/workspace-taller/b05546c78e064962434ef9543500d001452b7319/ClaseJavaFX/target/classes/main/Main$3.class -------------------------------------------------------------------------------- /ClaseJavaFX/target/classes/main/Main$4.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/programacion-avanzada/workspace-taller/b05546c78e064962434ef9543500d001452b7319/ClaseJavaFX/target/classes/main/Main$4.class -------------------------------------------------------------------------------- /ClaseJavaFX/target/classes/main/Main.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/programacion-avanzada/workspace-taller/b05546c78e064962434ef9543500d001452b7319/ClaseJavaFX/target/classes/main/Main.class -------------------------------------------------------------------------------- /ClaseJavaFX/target/classes/main/Mario$1.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/programacion-avanzada/workspace-taller/b05546c78e064962434ef9543500d001452b7319/ClaseJavaFX/target/classes/main/Mario$1.class -------------------------------------------------------------------------------- /ClaseJavaFX/target/classes/main/Mario$2.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/programacion-avanzada/workspace-taller/b05546c78e064962434ef9543500d001452b7319/ClaseJavaFX/target/classes/main/Mario$2.class -------------------------------------------------------------------------------- /ClaseJavaFX/target/classes/main/Mario.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/programacion-avanzada/workspace-taller/b05546c78e064962434ef9543500d001452b7319/ClaseJavaFX/target/classes/main/Mario.class -------------------------------------------------------------------------------- /ClaseJavaFX/target/classes/main/SpriteAnimation.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/programacion-avanzada/workspace-taller/b05546c78e064962434ef9543500d001452b7319/ClaseJavaFX/target/classes/main/SpriteAnimation.class -------------------------------------------------------------------------------- /ClaseJavaFX/target/classes/mario-background.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/programacion-avanzada/workspace-taller/b05546c78e064962434ef9543500d001452b7319/ClaseJavaFX/target/classes/mario-background.png -------------------------------------------------------------------------------- /ClaseJavaFX/target/classes/mario-sprites.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/programacion-avanzada/workspace-taller/b05546c78e064962434ef9543500d001452b7319/ClaseJavaFX/target/classes/mario-sprites.png -------------------------------------------------------------------------------- /ClaseJavaFX/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/programacion-avanzada/workspace-taller/b05546c78e064962434ef9543500d001452b7319/ClaseJavaFX/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst -------------------------------------------------------------------------------- /ClaseJavaFX/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst: -------------------------------------------------------------------------------- 1 | D:\projects\WP\ClaseJavaFX\src\main\java\main\SpriteAnimation.java 2 | D:\projects\WP\ClaseJavaFX\src\main\java\main\Main.java 3 | D:\projects\WP\ClaseJavaFX\src\main\java\main\Mario.java 4 | -------------------------------------------------------------------------------- /GraphicsJavaFX/.classpath: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /GraphicsJavaFX/.gitignore: -------------------------------------------------------------------------------- 1 | /bin/ 2 | -------------------------------------------------------------------------------- /GraphicsJavaFX/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | GraphicsJavaFX 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.jdt.core.javabuilder 10 | 11 | 12 | 13 | 14 | 15 | org.eclipse.jdt.core.javanature 16 | 17 | 18 | 19 | 1710944783788 20 | 21 | 30 22 | 23 | org.eclipse.core.resources.regexFilterMatcher 24 | node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__ 25 | 26 | 27 | 28 | 29 | -------------------------------------------------------------------------------- /GraphicsJavaFX/src/main/App.java: -------------------------------------------------------------------------------- 1 | package main; 2 | 3 | import javafx.application.Application; 4 | import javafx.scene.Scene; 5 | import javafx.scene.input.KeyCode; 6 | import javafx.scene.layout.StackPane; 7 | import javafx.scene.paint.Color; 8 | import javafx.stage.Stage; 9 | import javafx.scene.shape.Rectangle; 10 | import javafx.scene.transform.Translate; 11 | 12 | public class App extends Application { 13 | double posX; 14 | double posY; 15 | @Override 16 | public void start(Stage stage) { 17 | Rectangle cuadrado = new Rectangle(100, 100); 18 | cuadrado.setFill(Color.RED); 19 | Translate translate = new Translate(); 20 | posX = cuadrado.getLayoutX(); 21 | posY = cuadrado.getLayoutY(); 22 | cuadrado.setOnMouseClicked(event -> { 23 | cuadrado.setFill(Color.color(Math.random(), Math.random(), Math.random())); 24 | }); 25 | cuadrado.getTransforms().add(translate); 26 | StackPane stackPane = new StackPane(cuadrado); 27 | Scene scene = new Scene(stackPane, 640, 480); 28 | scene.setOnKeyPressed(event -> { 29 | if(event.getCode() == KeyCode.RIGHT){ 30 | 31 | translate.setX(posX+10); 32 | posX = posX +10; 33 | } 34 | else if(event.getCode() == KeyCode.LEFT){ 35 | 36 | translate.setX(posX-10); 37 | posX = posX -10; 38 | } 39 | else if(event.getCode() == KeyCode.UP){ 40 | translate.setY(posY-10); 41 | posY = posY -10; 42 | } 43 | else if(event.getCode() == KeyCode.DOWN){ 44 | translate.setY(posY+10); 45 | posY = posY +10; 46 | } 47 | }); 48 | stage.setScene(scene); 49 | stage.show(); 50 | } 51 | 52 | 53 | public static void main(String[] args) { 54 | // ,javafx.media 55 | launch(); 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /GraphicsJavaFX/tutorialJavaFX.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/programacion-avanzada/workspace-taller/b05546c78e064962434ef9543500d001452b7319/GraphicsJavaFX/tutorialJavaFX.txt -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Workspace del Taller de Programación Avanzada 2 | 3 | [![Codacy Badge](https://api.codacy.com/project/badge/Grade/b5ae03bcb80f4719807b60c95087d41a)](https://app.codacy.com/gh/programacion-avanzada/workspace-taller?utm_source=github.com&utm_medium=referral&utm_content=programacion-avanzada/workspace-taller&utm_campaign=Badge_Grade_Dashboard) 4 | 5 | Este repositorio es canónico, y posee los ejemplos dados habitualmente para los temas dictados. 6 | Si bien es un workspace de Eclipse, puede utilizarse con otras herramientas e IDEs. 7 | 8 | ## Colaborar con este repositorio 9 | 10 | Si tuvieras una idea interesante que quisieras compartir, podrías utilizar el mecanismo de Pull Requests de GitHub para colaborar y sumar tu aporte a la materia. ¡Nos encanta recibir aportes! 11 | 12 | También podés abrir un Issue para que lo revisemos si encontrás algo que cambiar o mejorar. 13 | 14 | -------------------------------------------------------------------------------- /codegolf/.classpath: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /codegolf/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | Codegolf 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.jdt.core.javabuilder 10 | 11 | 12 | 13 | 14 | 15 | org.eclipse.jdt.core.javanature 16 | 17 | 18 | 19 | 1710944783786 20 | 21 | 30 22 | 23 | org.eclipse.core.resources.regexFilterMatcher 24 | node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__ 25 | 26 | 27 | 28 | 29 | -------------------------------------------------------------------------------- /codegolf/src/edu/unlam/taller/codegolf/SumaPrefijos.java: -------------------------------------------------------------------------------- 1 | package edu.unlam.taller.codegolf; 2 | 3 | public class SumaPrefijos { 4 | 5 | /** 6 | * 7 | * Construir un array b de sumas de prefijos del array dado a 8 | * 9 | * b está definido como: 10 | * 11 | * | b[0] = a[0] | b[1] = a[0] + a[1] | b[2] = a[0] + a[1] + a[2] | ... | b[n - 12 | * 1] = a[0] + a[1] + ... + a[n - 1] 13 | * 14 | * donde n es el largo de a 15 | * 16 | * Ejemplo 17 | * 18 | * Para a = [1, 2, 3], la salida deberá ser sumaPrefijos(a) = [1, 3, 6]. 19 | * 20 | * b será igual a [1, 1 + 2, 1 + 2 + 3] = [1, 3, 6] 21 | * 22 | * Input/Output 23 | * 24 | * [input] array.integer a 25 | * 26 | * Constantes garantizadas: 3 ≤ a.length ≤ 104, -1000 ≤ a[i] ≤ 1000. 27 | * 28 | * [output] array.integer 29 | */ 30 | 31 | // Nota: La suma de los chars es +2 por ser calculado con el nombre base "sumaPrefijos" y no "iteracionx" 32 | 33 | // 154 chars 34 | int[] iteracion1(int[] array) { 35 | int suma = 0; 36 | int largo = array.length; 37 | int[] nuevo = new int[largo]; 38 | 39 | for (int i = 0; i < largo; i++) { 40 | suma += array[i]; 41 | nuevo[i] = suma; 42 | } 43 | 44 | return nuevo; 45 | } 46 | 47 | // 104 chars 48 | int[] iteracion2(int[] a) { 49 | int s = 0, l = a.length, i = 0; 50 | int[] n = new int[l]; 51 | 52 | for (; i < l; i++) { 53 | s += a[i]; 54 | n[i] = s; 55 | } 56 | 57 | return n; 58 | } 59 | 60 | // 73 chars 61 | int[] iteracion3(int[] a) { 62 | for (int i = 1; i < a.length;) 63 | a[i] += a[i++ - 1]; 64 | return a; 65 | } 66 | 67 | // 75 chars 68 | int[] iteracion4(int[] a) { 69 | int s = 0, i = 0; 70 | for (int x : a) { 71 | s += x; 72 | a[i] = s; 73 | i++; 74 | } 75 | return a; 76 | } 77 | 78 | // Version final 69 chars (65 con globales sin inicializar) 79 | int[] iteracion5(int[] a) { 80 | int s = 0, i = 0; 81 | for (int x : a) 82 | a[i++] = s += x; 83 | return a; 84 | } 85 | } 86 | -------------------------------------------------------------------------------- /codegolf/test/edu/unlam/taller/codegolf/SumaPrefijosTest.java: -------------------------------------------------------------------------------- 1 | package edu.unlam.taller.codegolf; 2 | 3 | import org.junit.Assert; 4 | import org.junit.Before; 5 | import org.junit.Test; 6 | 7 | public class SumaPrefijosTest { 8 | 9 | SumaPrefijos sumaPrefijos; 10 | 11 | @Before 12 | public void before() { 13 | sumaPrefijos = new SumaPrefijos(); 14 | } 15 | 16 | private void testTodasIteraciones(int[] input, int[] expected) { 17 | int[] actual; 18 | actual = sumaPrefijos.iteracion1(input.clone()); 19 | Assert.assertArrayEquals(expected, actual); 20 | actual = sumaPrefijos.iteracion2(input.clone()); 21 | Assert.assertArrayEquals(expected, actual); 22 | actual = sumaPrefijos.iteracion3(input.clone()); 23 | Assert.assertArrayEquals(expected, actual); 24 | actual = sumaPrefijos.iteracion4(input.clone()); 25 | Assert.assertArrayEquals(expected, actual); 26 | actual = sumaPrefijos.iteracion5(input.clone()); 27 | Assert.assertArrayEquals(expected, actual); 28 | } 29 | 30 | @Test 31 | public void testSimple() { 32 | int[] input = { 1, 2, 3 }; 33 | int[] expected = { 1, 3, 6 }; 34 | 35 | testTodasIteraciones(input, expected); 36 | } 37 | 38 | @Test 39 | public void testConNegativo() { 40 | int[] input = { 1, 2, 3, -6, -6 }; 41 | int[] expected = { 1, 3, 6, 0, -6 }; 42 | 43 | testTodasIteraciones(input, expected); 44 | } 45 | 46 | @Test 47 | public void testValoresNulos() { 48 | int[] input = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; 49 | int[] expected = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; 50 | 51 | testTodasIteraciones(input, expected); 52 | } 53 | 54 | @Test 55 | public void testValoresBinarios() { 56 | int[] input = { 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096 }; 57 | int[] expected = { 1, 3, 7, 15, 31, 63, 127, 255, 511, 1023, 2047, 4095, 8191 }; 58 | 59 | testTodasIteraciones(input, expected); 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /graphics/.classpath: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /graphics/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | Graphics 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.jdt.core.javabuilder 10 | 11 | 12 | 13 | 14 | 15 | org.eclipse.jdt.core.javanature 16 | 17 | 18 | 19 | 1710944783787 20 | 21 | 30 22 | 23 | org.eclipse.core.resources.regexFilterMatcher 24 | node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__ 25 | 26 | 27 | 28 | 29 | -------------------------------------------------------------------------------- /graphics/background.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/programacion-avanzada/workspace-taller/b05546c78e064962434ef9543500d001452b7319/graphics/background.jpg -------------------------------------------------------------------------------- /graphics/hit.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/programacion-avanzada/workspace-taller/b05546c78e064962434ef9543500d001452b7319/graphics/hit.wav -------------------------------------------------------------------------------- /graphics/left.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/programacion-avanzada/workspace-taller/b05546c78e064962434ef9543500d001452b7319/graphics/left.wav -------------------------------------------------------------------------------- /graphics/lib/javafx sdk 11/.javafx-jars: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/programacion-avanzada/workspace-taller/b05546c78e064962434ef9543500d001452b7319/graphics/lib/javafx sdk 11/.javafx-jars -------------------------------------------------------------------------------- /graphics/right.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/programacion-avanzada/workspace-taller/b05546c78e064962434ef9543500d001452b7319/graphics/right.wav -------------------------------------------------------------------------------- /graphics/src/basics/javafx/JavaFX.java: -------------------------------------------------------------------------------- 1 | package basics.javafx; 2 | 3 | import javafx.application.Application; 4 | import javafx.scene.Scene; 5 | import javafx.scene.control.Label; 6 | import javafx.scene.layout.StackPane; 7 | import javafx.stage.Stage; 8 | 9 | public class JavaFX extends Application { 10 | @Override 11 | public void start(Stage stage) { 12 | String javaVersion = System.getProperty("java.version"); 13 | String javafxVersion = System.getProperty("javafx.version"); 14 | Label label = new Label("Hello, JavaFX " + javafxVersion + ", running on Java " + javaVersion + "."); 15 | StackPane stackPane = new StackPane(label); 16 | Scene scene = new Scene(stackPane, 640, 480); 17 | stage.setScene(scene); 18 | stage.show(); 19 | } 20 | 21 | public static void main(String[] args) { 22 | // https://gluonhq.com/products/javafx/ 23 | // Unzip 24 | // Include in project 25 | // Add e(fx)clipse from Help -> install new software 26 | // Run as -> Run configurations -> Arguments -> VM Arguments 27 | // --module-path "(...)\javafx-sdk-version\lib" --add-modules javafx.controls 28 | //,javafx.media 29 | launch(); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /graphics/src/basics/swing/Frame.java: -------------------------------------------------------------------------------- 1 | package basics.swing; 2 | 3 | import javax.swing.JFrame; 4 | 5 | public class Frame extends JFrame { 6 | private static final long serialVersionUID = 5313051202295035309L; 7 | 8 | Panel panel; 9 | 10 | public Frame() { 11 | panel = new Panel(); 12 | getContentPane().add(panel); 13 | 14 | // Esconde los bordes de ventana. Solo se puede hacer mientras no sea visible 15 | // setUndecorated(true); 16 | 17 | // Setteo el tamaño segun el tamaño de los hijos 18 | pack(); 19 | // setSize(640, 480); 20 | 21 | setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 22 | setVisible(true); 23 | } 24 | 25 | // public void paint(Graphics g) { 26 | // g.drawString("Hola mundo", 50, 50); 27 | // } 28 | } 29 | -------------------------------------------------------------------------------- /graphics/src/basics/swing/Main.java: -------------------------------------------------------------------------------- 1 | package basics.swing; 2 | 3 | public class Main { 4 | public static void main(String[] args) { 5 | new Frame(); 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /graphics/src/basics/swing/Panel.java: -------------------------------------------------------------------------------- 1 | package basics.swing; 2 | 3 | import java.awt.BasicStroke; 4 | import java.awt.Color; 5 | import java.awt.Dimension; 6 | import java.awt.Font; 7 | import java.awt.Graphics; 8 | import java.awt.Graphics2D; 9 | import java.awt.image.BufferedImage; 10 | import java.io.File; 11 | import java.io.IOException; 12 | 13 | import javax.imageio.ImageIO; 14 | import javax.swing.JPanel; 15 | 16 | public class Panel extends JPanel { 17 | private static final long serialVersionUID = -6313969776795988484L; 18 | 19 | public Panel() { 20 | } 21 | 22 | @Override 23 | protected void paintComponent(Graphics g) { 24 | super.paintComponent(g); 25 | Graphics2D g2d = (Graphics2D) g; 26 | 27 | g2d.setFont(new Font("Consolas", Font.BOLD, 24)); 28 | g2d.drawString("¡Hola mundo!", 30, 50); 29 | 30 | g2d.setColor(Color.WHITE); 31 | g2d.setStroke(new BasicStroke(50)); 32 | g2d.drawRect(300, 100, 200, 100); 33 | 34 | BufferedImage img = null; 35 | try { 36 | img = ImageIO.read(new File("background.jpg")); 37 | } catch (IOException e) { 38 | e.printStackTrace(); 39 | } 40 | g2d.drawImage(img, 300, 300, 200, 100, null); 41 | 42 | } 43 | 44 | @Override 45 | public Dimension getPreferredSize() { 46 | return new Dimension(960, 540); 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /graphics/src/demo_ball_real_time_with_gravity/Ball.java: -------------------------------------------------------------------------------- 1 | package demo_ball_real_time_with_gravity; 2 | 3 | import java.awt.Color; 4 | 5 | // If multiple balls are created, physics methods must run with 'synchronized' 6 | public class Ball { 7 | final double GRAVITY = 9.8; 8 | final double GROUNDED_ERROR_POS = .02; 9 | final double GROUNDED_ERROR_VEL = .1; 10 | 11 | private double x; 12 | private double y; 13 | private double size; 14 | private double floor; 15 | private double ceil; 16 | private double left; 17 | private double right; 18 | private double vy = 0; 19 | private double vx = 0; 20 | private double elasticity; // [0, 1] 21 | private boolean grounded; 22 | //private Sound2Channels sound; 23 | private Sound2ChannelsFX sound; 24 | private Color color = Color.YELLOW; 25 | 26 | public Ball(double size, double x, double y, double floor, double ceil, double right, double left, 27 | double elasticity) { 28 | this.size = size; 29 | this.x = x; 30 | this.y = y; 31 | this.floor = floor - size / 2; 32 | this.ceil = ceil + size / 2; 33 | this.right = right - size / 2; 34 | this.left = left + size / 2; 35 | this.elasticity = elasticity; 36 | this.sound = new Sound2ChannelsFX("hit.wav"); 37 | 38 | //try { 39 | // this.sound = new Sound2Channels("./left.wav", "./right.wav"); 40 | //} catch (Exception e) { 41 | // e.printStackTrace(); 42 | //} 43 | 44 | } 45 | 46 | public void move(double deltaTime) { 47 | calcForces(deltaTime); 48 | y += vy * deltaTime; // TODO change to MRUV 49 | crashY(); 50 | x += vx * deltaTime; 51 | crashX(); 52 | } 53 | 54 | private void crashY() { 55 | double vaux = 0; 56 | while (y > floor || y < ceil) { 57 | vaux = vy; 58 | if (y > floor) { 59 | y = floor - (y - floor); 60 | if (vy > 0) { // Necessary if ball is out of bounds at the start 61 | vy = -vy * elasticity; 62 | } 63 | squash(); 64 | } else { 65 | y = ceil - (y - ceil); 66 | if (vy < 0) { 67 | vy = -vy * elasticity; 68 | } 69 | } 70 | } 71 | if (vaux != 0) { 72 | onCrash(vaux); 73 | } 74 | } 75 | 76 | private void crashX() { 77 | double vaux = 0; 78 | while (x > right || x < left) { 79 | vaux = vx; 80 | if (x > right) { 81 | x = right - (x - right); 82 | if (vx > 0) { 83 | vx = -vx * elasticity; 84 | } 85 | } else { 86 | x = left - (x - left); 87 | if (vx < 0) { 88 | vx = -vx * elasticity; 89 | } 90 | } 91 | } 92 | if (vaux != 0) { 93 | onCrash(vaux); 94 | } 95 | } 96 | 97 | public void squash() { 98 | if (floor - y < GROUNDED_ERROR_POS && Math.abs(vy) < GROUNDED_ERROR_VEL) { 99 | y = floor; 100 | vy = 0; 101 | grounded = true; 102 | } 103 | } 104 | 105 | private void calcForces(double deltaTime) { 106 | if (!grounded) { 107 | vy = vy + GRAVITY * deltaTime; 108 | } 109 | } 110 | 111 | private void onCrash(double v) { 112 | float volumeStrength = (float) Math.min(Math.abs(v) / 20, 1f); 113 | double halfRange = (this.right - this.left) / 2; 114 | double position = this.right - this.x; 115 | sound.setBalance((halfRange - position) / halfRange); 116 | sound.setVolume(volumeStrength); 117 | sound.play(); 118 | } 119 | 120 | public boolean isInside(double x, double y) { 121 | return Math.pow(this.x - x, 2) + Math.pow(this.y - y, 2) < Math.pow(size / 2, 2); 122 | } 123 | 124 | public double getX() { 125 | return x; 126 | } 127 | 128 | public double getY() { 129 | return y; 130 | } 131 | 132 | public void pushTop(double force) { 133 | grounded = false; 134 | vy -= force; 135 | } 136 | 137 | public void pushBottom(double force) { 138 | grounded = false; 139 | vy += force; 140 | } 141 | 142 | public void pushLeft(double force) { 143 | vx -= force; 144 | } 145 | 146 | public void pushRight(double force) { 147 | vx += force; 148 | } 149 | 150 | public double getSize() { 151 | return size; 152 | } 153 | 154 | public Color getColor() { 155 | return color; 156 | } 157 | 158 | public void setColor(Color color) { 159 | this.color = color; 160 | } 161 | } 162 | -------------------------------------------------------------------------------- /graphics/src/demo_ball_real_time_with_gravity/JavaFXGame.java: -------------------------------------------------------------------------------- 1 | package demo_ball_real_time_with_gravity; 2 | 3 | import java.awt.Point; 4 | import java.io.FileInputStream; 5 | 6 | import javafx.animation.KeyFrame; 7 | import javafx.animation.Timeline; 8 | import javafx.application.Application; 9 | import javafx.event.Event; 10 | import javafx.event.EventHandler; 11 | import javafx.scene.Group; 12 | import javafx.scene.Scene; 13 | import javafx.scene.image.Image; 14 | import javafx.scene.image.ImageView; 15 | import javafx.scene.input.KeyEvent; 16 | import javafx.scene.input.MouseEvent; 17 | import javafx.scene.paint.Color; 18 | import javafx.scene.shape.Circle; 19 | import javafx.scene.shape.Rectangle; 20 | import javafx.scene.text.Font; 21 | import javafx.scene.text.FontPosture; 22 | import javafx.scene.text.FontWeight; 23 | import javafx.scene.text.Text; 24 | import javafx.scene.transform.Scale; 25 | import javafx.stage.Stage; 26 | import javafx.util.Duration; 27 | 28 | public class JavaFXGame extends Application { 29 | private final int SECOND = 1000; 30 | private final int FRAMES_PER_SECOND = 60; 31 | private final int TICKS_PER_SECOND = 1000; 32 | private final int SKIP_TICKS = SECOND / TICKS_PER_SECOND; 33 | 34 | private final int SQUARE = 50; 35 | private final int WIDTH = SQUARE * 16; 36 | private final int HEIGHT = SQUARE * 9; 37 | 38 | private Player player; 39 | private Ball ball; 40 | 41 | private int loops = 0; 42 | private int fps = 0; 43 | private int frames = 0; 44 | 45 | private Group group; 46 | private Scene scene; 47 | private Scale scale; 48 | 49 | private Circle ballImage; 50 | private Rectangle playerDeltaImage; 51 | private Rectangle playerImage; 52 | private ImageView backgroundImage; 53 | private Text textTime; 54 | private Text textFps; 55 | private Text textBallX; 56 | private Text textBallY; 57 | 58 | @Override 59 | public void start(final Stage primaryStage) throws Exception { 60 | player = new Player(1, 3); 61 | playerDeltaImage = new Rectangle(SQUARE, SQUARE); 62 | playerDeltaImage.setFill(Color.BLUE); 63 | playerImage = new Rectangle(SQUARE, SQUARE); 64 | playerImage.setFill(Color.TRANSPARENT); 65 | playerImage.setStroke(Color.RED); 66 | 67 | ball = new Ball(2, 8, 2, 9, 0, 16, 0, 0.8); 68 | ballImage = new Circle(0, 0, (int) (SQUARE * ball.getSize() / 2)); 69 | 70 | Image image = new Image(new FileInputStream("background.jpg")); 71 | backgroundImage = new ImageView(image); 72 | backgroundImage.setX(0); 73 | backgroundImage.setY(0); 74 | backgroundImage.setFitHeight(HEIGHT); 75 | backgroundImage.setFitWidth(WIDTH); 76 | backgroundImage.setPreserveRatio(false); 77 | 78 | Font font = Font.font("Consolas", FontWeight.BOLD, FontPosture.REGULAR, 24); 79 | textTime = new Text(20, 25, ""); 80 | textTime.setFill(Color.WHITE); 81 | textTime.setFont(font); 82 | textFps = new Text(240, 25, ""); 83 | textFps.setFill(Color.WHITE); 84 | textFps.setFont(font); 85 | textBallX = new Text(20, 60, ""); 86 | textBallX.setFill(Color.WHITE); 87 | textBallX.setFont(font); 88 | textBallY = new Text(240, 60, ""); 89 | textBallY.setFill(Color.WHITE); 90 | textBallY.setFont(font); 91 | 92 | @SuppressWarnings({ "unchecked", "rawtypes" }) 93 | final Timeline game_timeline = new Timeline(new KeyFrame(Duration.ZERO, new EventHandler() { 94 | @Override 95 | public void handle(Event event) { 96 | frames++; 97 | display(); 98 | } 99 | }), new KeyFrame(Duration.millis(SECOND / FRAMES_PER_SECOND))); 100 | game_timeline.setCycleCount(Timeline.INDEFINITE); 101 | 102 | @SuppressWarnings({ "unchecked", "rawtypes" }) 103 | final Timeline frame_timeline = new Timeline(new KeyFrame(Duration.ZERO, new EventHandler() { 104 | @Override 105 | public void handle(Event event) { 106 | loops++; 107 | update(); 108 | } 109 | }), new KeyFrame(Duration.millis(SKIP_TICKS))); 110 | frame_timeline.setCycleCount(Timeline.INDEFINITE); 111 | 112 | @SuppressWarnings({ "unchecked", "rawtypes" }) 113 | final Timeline second_timeline = new Timeline(new KeyFrame(Duration.ZERO, new EventHandler() { 114 | @Override 115 | public void handle(Event event) { 116 | fps = frames; 117 | frames = 0; 118 | } 119 | }), new KeyFrame(Duration.millis(SECOND))); 120 | second_timeline.setCycleCount(Timeline.INDEFINITE); 121 | 122 | group = new Group(backgroundImage, playerDeltaImage, playerImage, ballImage, textTime, textFps, textBallX, 123 | textBallY); 124 | scene = new Scene(group, WIDTH, HEIGHT); 125 | 126 | scene.addEventHandler(MouseEvent.MOUSE_CLICKED, new EventHandler() { 127 | @Override 128 | public void handle(MouseEvent e) { 129 | Point point = new Point((int) e.getX(), (int) e.getY()); 130 | System.out.print("Click en: [" + (point.x * WIDTH / scene.getWidth()) + ", "); 131 | System.out.println(point.y * HEIGHT / scene.getHeight() + "]"); 132 | if (ball.isInside((point.x * WIDTH / scene.getWidth()) / SQUARE, 133 | (point.y * HEIGHT / scene.getHeight()) / SQUARE)) { 134 | ball.setColor(new java.awt.Color((int) (Math.random() * Math.pow(2, 24)))); 135 | } 136 | } 137 | }); 138 | 139 | scene.addEventHandler(KeyEvent.KEY_PRESSED, new EventHandler() { 140 | @SuppressWarnings("incomplete-switch") 141 | @Override 142 | public void handle(KeyEvent e) { 143 | switch (e.getCode()) { 144 | 145 | case W: 146 | player.goUp(); 147 | break; 148 | case A: 149 | player.goLeft(); 150 | break; 151 | case S: 152 | player.goDown(); 153 | break; 154 | case D: 155 | player.goRight(); 156 | break; 157 | 158 | case UP: 159 | ball.pushTop(5); 160 | break; 161 | case DOWN: 162 | ball.pushBottom(5000); 163 | break; 164 | case LEFT: 165 | ball.pushLeft(2); 166 | break; 167 | case RIGHT: 168 | ball.pushRight(2); 169 | break; 170 | } 171 | } 172 | }); 173 | 174 | scale = new Scale(); 175 | scale.setX(1.5); 176 | scale.setY(1.5); 177 | group.getTransforms().add(scale); 178 | primaryStage.setTitle("¡JavaFX!"); 179 | primaryStage.setScene(scene); 180 | primaryStage.show(); 181 | 182 | game_timeline.play(); 183 | frame_timeline.play(); 184 | second_timeline.play(); 185 | } 186 | 187 | private void update() { 188 | player.move(1.0 / TICKS_PER_SECOND); 189 | ball.move(1.0 / TICKS_PER_SECOND); 190 | } 191 | 192 | private void display() { 193 | scale.setX(scene.getWidth() / WIDTH); 194 | scale.setY(scene.getHeight() / HEIGHT); 195 | 196 | textTime.setText("Time: " + String.format("%6s", loops * SKIP_TICKS) + "ms"); 197 | textFps.setText("FPS: " + fps + ""); 198 | textBallX.setText("Ball X: " + String.format("%8.6s", ball.getX())); 199 | textBallY.setText("Ball Y: " + String.format("%8.6s", ball.getY())); 200 | 201 | playerDeltaImage.setX(player.getDeltaX() * SQUARE); 202 | playerDeltaImage.setY(player.getDeltaY() * SQUARE); 203 | playerImage.setX(player.getX() * SQUARE); 204 | playerImage.setY(player.getY() * SQUARE); 205 | 206 | ballImage.setCenterX((int) (ball.getX() * SQUARE)); 207 | ballImage.setCenterY((int) (ball.getY() * SQUARE)); 208 | java.awt.Color awtColor = ball.getColor(); 209 | javafx.scene.paint.Color fxColor = javafx.scene.paint.Color.rgb(awtColor.getRed(), awtColor.getGreen(), 210 | awtColor.getBlue(), awtColor.getAlpha() / 255.0); 211 | ballImage.setFill(fxColor); 212 | } 213 | 214 | public static void main(String[] args) throws Exception { 215 | launch(args); 216 | } 217 | } -------------------------------------------------------------------------------- /graphics/src/demo_ball_real_time_with_gravity/Player.java: -------------------------------------------------------------------------------- 1 | package demo_ball_real_time_with_gravity; 2 | 3 | public class Player { 4 | private double x; 5 | private double y; 6 | private double deltaX; 7 | private double deltaY; 8 | private boolean move = true; 9 | 10 | public Player(double x, double y) { 11 | this.x = x; 12 | this.y = y; 13 | this.deltaX = x; 14 | this.deltaY = y; 15 | } 16 | 17 | public Player() { 18 | this(0.0, 0.0); 19 | } 20 | 21 | public double getX() { 22 | return x; 23 | } 24 | 25 | public double getY() { 26 | return y; 27 | } 28 | 29 | public double getDeltaY() { 30 | return deltaY; 31 | } 32 | 33 | public double getDeltaX() { 34 | return deltaX; 35 | } 36 | 37 | public void move(double delta) { 38 | if (x > deltaX) { 39 | deltaX = Math.min(x, deltaX + delta); 40 | } else if (x < deltaX) { 41 | deltaX = Math.max(x, deltaX - delta); 42 | } 43 | 44 | if (y > deltaY) { 45 | deltaY = Math.min(y, deltaY + delta); 46 | } else if (y < deltaY) { 47 | deltaY = Math.max(y, deltaY - delta); 48 | } 49 | 50 | if (x == deltaX && y == deltaY) { 51 | newMovement(); 52 | } 53 | } 54 | 55 | public void goUp() { 56 | if (move) { 57 | this.y--; 58 | move = false; 59 | } 60 | } 61 | 62 | public void goDown() { 63 | if (move) { 64 | this.y++; 65 | move = false; 66 | } 67 | } 68 | 69 | public void goLeft() { 70 | if (move) { 71 | this.x--; 72 | move = false; 73 | } 74 | } 75 | 76 | public void goRight() { 77 | if (move) { 78 | this.x++; 79 | move = false; 80 | } 81 | } 82 | 83 | public void newMovement() { 84 | move = true; 85 | } 86 | } 87 | -------------------------------------------------------------------------------- /graphics/src/demo_ball_real_time_with_gravity/Sound.java: -------------------------------------------------------------------------------- 1 | package demo_ball_real_time_with_gravity; 2 | 3 | import java.io.File; 4 | 5 | import javax.sound.sampled.AudioInputStream; 6 | import javax.sound.sampled.AudioSystem; 7 | import javax.sound.sampled.Clip; 8 | import javax.sound.sampled.FloatControl; 9 | 10 | public class Sound { 11 | Clip clip; 12 | 13 | public Sound(String path) throws Exception { 14 | AudioInputStream audioIn = AudioSystem.getAudioInputStream(new File(path)); 15 | clip = AudioSystem.getClip(); 16 | clip.open(audioIn); 17 | } 18 | 19 | public void play() { 20 | clip.stop(); 21 | clip.flush(); 22 | clip.setMicrosecondPosition(0); 23 | clip.start(); 24 | } 25 | 26 | public void setVolume(float volume) { 27 | if (volume < 0f || volume > 1f) 28 | throw new IllegalArgumentException("Volume not valid: " + volume); 29 | FloatControl gainControl = (FloatControl) clip.getControl(FloatControl.Type.MASTER_GAIN); 30 | gainControl.setValue(20f * (float) Math.log10(volume)); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /graphics/src/demo_ball_real_time_with_gravity/Sound2Channels.java: -------------------------------------------------------------------------------- 1 | package demo_ball_real_time_with_gravity; 2 | 3 | import java.io.File; 4 | 5 | import javax.sound.sampled.AudioInputStream; 6 | import javax.sound.sampled.AudioSystem; 7 | import javax.sound.sampled.Clip; 8 | import javax.sound.sampled.FloatControl; 9 | 10 | public class Sound2Channels { 11 | float volume = 1f; 12 | double balance = 0.0; 13 | 14 | Clip leftClip; 15 | Clip rightClip; 16 | 17 | public Sound2Channels(String left, String right) throws Exception { 18 | AudioInputStream audioIn = AudioSystem.getAudioInputStream(new File(left)); 19 | leftClip = AudioSystem.getClip(); 20 | leftClip.open(audioIn); 21 | audioIn = AudioSystem.getAudioInputStream(new File(right)); 22 | rightClip = AudioSystem.getClip(); 23 | rightClip.open(audioIn); 24 | } 25 | 26 | public void play() { 27 | leftClip.stop(); 28 | leftClip.flush(); 29 | leftClip.setMicrosecondPosition(0); 30 | rightClip.stop(); 31 | rightClip.flush(); 32 | rightClip.setMicrosecondPosition(0); 33 | 34 | synchronized (this) { 35 | leftClip.start(); 36 | rightClip.start(); 37 | } 38 | } 39 | 40 | private void setGainControl() { 41 | double rightBalance = (balance + 1) / 2; 42 | double leftBalance = 1 - rightBalance; 43 | FloatControl gainControl = (FloatControl) leftClip.getControl(FloatControl.Type.MASTER_GAIN); 44 | gainControl.setValue(Math.max(-80f, 20f * (float) Math.log10(leftBalance * volume))); 45 | gainControl = (FloatControl) rightClip.getControl(FloatControl.Type.MASTER_GAIN); 46 | gainControl.setValue(Math.max(-80f, 20f * (float) Math.log10(rightBalance * volume))); 47 | } 48 | 49 | public void setBalance(double balance) { 50 | if (balance < -1.0 || balance > 1.0) 51 | throw new IllegalArgumentException("Balance " + balance + "must be between -1.0 and 1.0"); 52 | this.balance = balance; 53 | setGainControl(); 54 | } 55 | 56 | public void setVolume(float volume) { 57 | if (volume < 0f || volume > 1f) 58 | throw new IllegalArgumentException("Volume " + volume + "must be between 0f and 1f"); 59 | this.volume = volume; 60 | setGainControl(); 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /graphics/src/demo_ball_real_time_with_gravity/Sound2ChannelsFX.java: -------------------------------------------------------------------------------- 1 | package demo_ball_real_time_with_gravity; 2 | 3 | import javafx.scene.media.AudioClip; 4 | 5 | public class Sound2ChannelsFX { 6 | AudioClip audioClip; 7 | 8 | public Sound2ChannelsFX(String sound) { 9 | audioClip = new AudioClip("file:/D:/projects/eclipse-workspace/Graphics/" + sound); 10 | } 11 | 12 | public void play() { 13 | audioClip.play(); 14 | } 15 | 16 | public void setBalance(double balance) { 17 | audioClip.setBalance(balance); 18 | } 19 | 20 | public void setVolume(double volume) { 21 | audioClip.setVolume(volume); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /graphics/src/demo_ball_real_time_with_gravity/SwingGame.java: -------------------------------------------------------------------------------- 1 | package demo_ball_real_time_with_gravity; 2 | 3 | import java.awt.Color; 4 | import java.awt.Dimension; 5 | import java.awt.Font; 6 | import java.awt.Graphics; 7 | import java.awt.Graphics2D; 8 | import java.awt.Point; 9 | import java.awt.event.KeyEvent; 10 | import java.awt.event.KeyListener; 11 | import java.awt.event.MouseAdapter; 12 | import java.awt.event.MouseEvent; 13 | import java.awt.image.BufferedImage; 14 | import java.io.File; 15 | import java.io.IOException; 16 | 17 | import javax.imageio.ImageIO; 18 | import javax.swing.JFrame; 19 | import javax.swing.JPanel; 20 | 21 | public class SwingGame extends JFrame implements Runnable { 22 | private static final long serialVersionUID = 1L; 23 | 24 | // OJO: Los valores de SKIP son un resultado de una división entera! 25 | private final int SECOND = 1000; 26 | private final int FRAMES_PER_SECOND = 60; 27 | private final int SKIP_FRAMES = SECOND / FRAMES_PER_SECOND; 28 | private final int TICKS_PER_SECOND = 60; 29 | private final int SKIP_TICKS = SECOND / TICKS_PER_SECOND; 30 | 31 | private final int SQUARES_X = 16; 32 | private final int SQUARES_Y = 9; 33 | 34 | private boolean isRunning = true; 35 | 36 | private Player player; 37 | private Ball ball; 38 | private DrawPanel drawPanel; 39 | private BufferedImage background; 40 | 41 | private int loops = 0; 42 | private int fps = 0; 43 | 44 | public SwingGame() { 45 | } 46 | 47 | public void init() { 48 | try { 49 | background = ImageIO.read(new File("background.jpg")); 50 | } catch (IOException e1) { 51 | e1.printStackTrace(); 52 | } 53 | 54 | player = new Player(1, 3); 55 | 56 | ball = new Ball(2, 8, 2, SQUARES_Y, 0, SQUARES_X, 0, 0.8); 57 | 58 | drawPanel = new DrawPanel(); 59 | add(drawPanel); 60 | 61 | addKeyListener(new KeyListener() { 62 | @Override 63 | public void keyPressed(KeyEvent e) { 64 | switch (e.getKeyCode()) { 65 | 66 | case KeyEvent.VK_W: 67 | player.goUp(); 68 | break; 69 | case KeyEvent.VK_A: 70 | player.goLeft(); 71 | break; 72 | case KeyEvent.VK_S: 73 | player.goDown(); 74 | break; 75 | case KeyEvent.VK_D: 76 | player.goRight(); 77 | break; 78 | 79 | case KeyEvent.VK_UP: 80 | ball.pushTop(5); 81 | break; 82 | case KeyEvent.VK_DOWN: 83 | ball.pushBottom(5000); 84 | break; 85 | case KeyEvent.VK_LEFT: 86 | ball.pushLeft(2); 87 | break; 88 | case KeyEvent.VK_RIGHT: 89 | ball.pushRight(2); 90 | break; 91 | case KeyEvent.VK_ESCAPE: 92 | isRunning = false; 93 | break; 94 | } 95 | } 96 | 97 | @Override 98 | public void keyReleased(KeyEvent e) { 99 | } 100 | 101 | @Override 102 | public void keyTyped(KeyEvent arg0) { 103 | } 104 | }); 105 | 106 | pack(); 107 | setDefaultCloseOperation(EXIT_ON_CLOSE); 108 | setLocationRelativeTo(null); 109 | setVisible(true); 110 | setFocusable(true); 111 | requestFocusInWindow(); 112 | } 113 | 114 | @Override 115 | public void run() { 116 | // System.nanoTime no es seguro entre distintos Threads 117 | // En caso de querer utilizarse igual para aumentar la precision en 118 | // valores altos de fps o de ticks se debe aumentar también el valor 119 | // de las constantes, para que esten en ns y no en ms 120 | 121 | long next_game_tick = System.currentTimeMillis(); 122 | long next_game_frame = System.currentTimeMillis(); 123 | long next_frame_calc = System.currentTimeMillis(); 124 | int frames = 0; 125 | 126 | while (isRunning) { 127 | if (System.currentTimeMillis() > next_game_tick) { 128 | loops++; 129 | next_game_tick += SKIP_TICKS; 130 | update(); 131 | } 132 | if (System.currentTimeMillis() > next_game_frame) { 133 | frames++; 134 | next_game_frame += SKIP_FRAMES; 135 | display(); 136 | } 137 | if (System.currentTimeMillis() > next_frame_calc) { 138 | fps = frames; 139 | next_frame_calc += SECOND; 140 | frames = 0; 141 | } 142 | } 143 | } 144 | 145 | public void update() { 146 | player.move(1.0 / TICKS_PER_SECOND); 147 | ball.move(1.0 / TICKS_PER_SECOND); 148 | } 149 | 150 | public void display() { 151 | drawPanel.repaint(); 152 | } 153 | 154 | private class DrawPanel extends JPanel { 155 | private static final long serialVersionUID = 91574813372177663L; 156 | 157 | private final int SQUARE = 120; 158 | private final int WIDTH = SQUARE * SQUARES_X; 159 | private final int HEIGHT = SQUARE * SQUARES_Y; 160 | 161 | public DrawPanel() { 162 | addMouseListener(new MouseAdapter() { 163 | @Override 164 | public void mousePressed(MouseEvent me) { 165 | super.mouseClicked(me); 166 | Point point = me.getPoint(); 167 | Dimension currentDimension = getContentPane().getSize(); 168 | System.out.print("Click en: [" + (point.x * WIDTH / currentDimension.getWidth()) + ", "); 169 | System.out.println(point.y * HEIGHT / currentDimension.getHeight() + "]"); 170 | 171 | if (ball.isInside((point.x * WIDTH / currentDimension.getWidth()) / SQUARE, 172 | (point.y * HEIGHT / currentDimension.getHeight()) / SQUARE)) { 173 | ball.setColor(new Color((int) (Math.random() * Math.pow(2, 24)))); 174 | } 175 | } 176 | }); 177 | } 178 | 179 | @Override 180 | protected void paintComponent(Graphics g) { 181 | super.paintComponent(g); 182 | Graphics2D g2d = (Graphics2D) g; 183 | 184 | Dimension currentDimension = getContentPane().getSize(); 185 | g2d.scale(currentDimension.getWidth() / WIDTH, currentDimension.getHeight() / HEIGHT); 186 | 187 | g2d.drawImage(background, 0, 0, WIDTH, HEIGHT, null); 188 | 189 | g2d.setColor(Color.WHITE); 190 | g2d.setFont(new Font("Consolas", Font.BOLD, 24)); 191 | g2d.drawString("Time: " + String.format("%6s", loops * SKIP_TICKS) + "ms", 20, 25); 192 | g2d.drawString("FPS: " + fps + "", 240, 25); 193 | 194 | g2d.drawString("Ball X: " + String.format("%8.6s", ball.getX()), 20, 60); 195 | g2d.drawString("Ball Y: " + String.format("%8.6s", ball.getY()), 240, 60); 196 | 197 | g2d.setColor(Color.BLUE); 198 | g2d.fillRect((int) (player.getDeltaX() * SQUARE), (int) (player.getDeltaY() * SQUARE), SQUARE, SQUARE); 199 | g2d.setColor(Color.RED); 200 | g2d.drawRect((int) (player.getX() * SQUARE), (int) (player.getY() * SQUARE), SQUARE - 1, SQUARE - 1); 201 | 202 | g2d.setColor(ball.getColor()); 203 | g2d.fillOval((int) (ball.getX() * SQUARE - SQUARE * ball.getSize() / 2), 204 | (int) (ball.getY() * SQUARE - SQUARE * ball.getSize() / 2), (int) (SQUARE * ball.getSize()), 205 | (int) (SQUARE * ball.getSize())); 206 | } 207 | 208 | @Override 209 | public Dimension getPreferredSize() { 210 | return new Dimension(WIDTH, HEIGHT); 211 | } 212 | } 213 | 214 | public static void main(String[] args) throws Exception { 215 | SwingGame game = new SwingGame(); 216 | game.init(); 217 | game.run(); 218 | } 219 | } 220 | -------------------------------------------------------------------------------- /hibernate-basico/.classpath: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /hibernate-basico/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | hibernate-basico 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.jdt.core.javabuilder 10 | 11 | 12 | 13 | 14 | 15 | org.eclipse.jdt.core.javanature 16 | 17 | 18 | 19 | 1710944783790 20 | 21 | 30 22 | 23 | org.eclipse.core.resources.regexFilterMatcher 24 | node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__ 25 | 26 | 27 | 28 | 29 | -------------------------------------------------------------------------------- /hibernate-basico/lib/antlr-2.7.7.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/programacion-avanzada/workspace-taller/b05546c78e064962434ef9543500d001452b7319/hibernate-basico/lib/antlr-2.7.7.jar -------------------------------------------------------------------------------- /hibernate-basico/lib/classmate-1.3.0.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/programacion-avanzada/workspace-taller/b05546c78e064962434ef9543500d001452b7319/hibernate-basico/lib/classmate-1.3.0.jar -------------------------------------------------------------------------------- /hibernate-basico/lib/dom4j-1.6.1.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/programacion-avanzada/workspace-taller/b05546c78e064962434ef9543500d001452b7319/hibernate-basico/lib/dom4j-1.6.1.jar -------------------------------------------------------------------------------- /hibernate-basico/lib/hibernate-commons-annotations-5.0.1.Final.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/programacion-avanzada/workspace-taller/b05546c78e064962434ef9543500d001452b7319/hibernate-basico/lib/hibernate-commons-annotations-5.0.1.Final.jar -------------------------------------------------------------------------------- /hibernate-basico/lib/hibernate-core-5.2.11.Final.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/programacion-avanzada/workspace-taller/b05546c78e064962434ef9543500d001452b7319/hibernate-basico/lib/hibernate-core-5.2.11.Final.jar -------------------------------------------------------------------------------- /hibernate-basico/lib/hibernate-entitymanager.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/programacion-avanzada/workspace-taller/b05546c78e064962434ef9543500d001452b7319/hibernate-basico/lib/hibernate-entitymanager.jar -------------------------------------------------------------------------------- /hibernate-basico/lib/hibernate-jpa-2.1-api-1.0.0.Final.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/programacion-avanzada/workspace-taller/b05546c78e064962434ef9543500d001452b7319/hibernate-basico/lib/hibernate-jpa-2.1-api-1.0.0.Final.jar -------------------------------------------------------------------------------- /hibernate-basico/lib/hibernate4-sqlite-dialect-0.1.2.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/programacion-avanzada/workspace-taller/b05546c78e064962434ef9543500d001452b7319/hibernate-basico/lib/hibernate4-sqlite-dialect-0.1.2.jar -------------------------------------------------------------------------------- /hibernate-basico/lib/javassist-3.20.0-GA.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/programacion-avanzada/workspace-taller/b05546c78e064962434ef9543500d001452b7319/hibernate-basico/lib/javassist-3.20.0-GA.jar -------------------------------------------------------------------------------- /hibernate-basico/lib/jboss-logging-3.3.0.Final.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/programacion-avanzada/workspace-taller/b05546c78e064962434ef9543500d001452b7319/hibernate-basico/lib/jboss-logging-3.3.0.Final.jar -------------------------------------------------------------------------------- /hibernate-basico/lib/jboss-transaction-api_1.2_spec-1.0.1.Final.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/programacion-avanzada/workspace-taller/b05546c78e064962434ef9543500d001452b7319/hibernate-basico/lib/jboss-transaction-api_1.2_spec-1.0.1.Final.jar -------------------------------------------------------------------------------- /hibernate-basico/lib/jta.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/programacion-avanzada/workspace-taller/b05546c78e064962434ef9543500d001452b7319/hibernate-basico/lib/jta.jar -------------------------------------------------------------------------------- /hibernate-basico/lib/slf4j-api-1.7.7.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/programacion-avanzada/workspace-taller/b05546c78e064962434ef9543500d001452b7319/hibernate-basico/lib/slf4j-api-1.7.7.jar -------------------------------------------------------------------------------- /hibernate-basico/lib/slf4j-simple-1.7.7.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/programacion-avanzada/workspace-taller/b05546c78e064962434ef9543500d001452b7319/hibernate-basico/lib/slf4j-simple-1.7.7.jar -------------------------------------------------------------------------------- /hibernate-basico/lib/sqlite-jdbc-3.7.2.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/programacion-avanzada/workspace-taller/b05546c78e064962434ef9543500d001452b7319/hibernate-basico/lib/sqlite-jdbc-3.7.2.jar -------------------------------------------------------------------------------- /hibernate-basico/prueba.sqlite: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/programacion-avanzada/workspace-taller/b05546c78e064962434ef9543500d001452b7319/hibernate-basico/prueba.sqlite -------------------------------------------------------------------------------- /hibernate-basico/src/com/jwt/hibernate/Departamento.java: -------------------------------------------------------------------------------- 1 | package com.jwt.hibernate; 2 | 3 | public class Departamento { 4 | 5 | private int codigo; 6 | private String descripcion; 7 | 8 | public int getCodigo() { 9 | return codigo; 10 | } 11 | 12 | public void setCodigo(int codigo) { 13 | this.codigo = codigo; 14 | } 15 | 16 | public String getDescripcion() { 17 | return descripcion; 18 | } 19 | public void setDescripcion(String descripcion) { 20 | this.descripcion = descripcion; 21 | } 22 | 23 | 24 | } 25 | -------------------------------------------------------------------------------- /hibernate-basico/src/com/jwt/hibernate/HibernateApp.java: -------------------------------------------------------------------------------- 1 | package com.jwt.hibernate; 2 | 3 | import java.util.List; 4 | import javax.persistence.Query; 5 | import javax.persistence.criteria.CriteriaBuilder; 6 | import javax.persistence.criteria.CriteriaQuery; 7 | import javax.persistence.criteria.Root; 8 | 9 | //import javax.persistence.criteria.Root; 10 | import org.hibernate.HibernateException; 11 | import org.hibernate.Session; 12 | import org.hibernate.SessionFactory; 13 | import org.hibernate.Transaction; 14 | import org.hibernate.cfg.Configuration; 15 | 16 | public class HibernateApp { 17 | 18 | @SuppressWarnings("unchecked") 19 | public static void main(String[] args) { 20 | 21 | Configuration cfg = new Configuration(); 22 | cfg.configure("hibernate.cfg.xml"); 23 | 24 | SessionFactory factory = cfg.buildSessionFactory(); 25 | Session session = factory.openSession(); 26 | 27 | Departamento dpto = new Departamento(); 28 | 29 | dpto.setDescripcion("Finanzas"); 30 | 31 | Persona persona = new Persona(); 32 | 33 | persona.setDni(12345670); 34 | persona.setApellido("Sepulveda"); 35 | persona.setNombre("Lolote"); 36 | persona.setSexo('M'); 37 | persona.setCodigo_depto(1); 38 | 39 | Transaction tx = session.beginTransaction(); 40 | try { 41 | //session.saveOrUpdate(dpto); 42 | 43 | //session.saveOrUpdate(persona); 44 | //System.out.println("Se genero el registro con éxito.....!!"); 45 | 46 | tx.commit(); 47 | 48 | CriteriaBuilder cb = session.getCriteriaBuilder(); 49 | CriteriaQuery cq = cb.createQuery(Persona.class); 50 | cq.from(Persona.class); 51 | //Root rp = cq.from(Persona.class); 52 | //cq.select(rp).where(cb.like(rp.get("nombre"), "f%")); 53 | List lista = session.createQuery(cq).getResultList(); 54 | for(Persona p : lista) { 55 | System.out.println(p); 56 | } 57 | 58 | System.out.println("\nSolo DNI de las Personas"); 59 | 60 | Query q = session.getNamedQuery("DniPersonas"); 61 | List listaConDni = q.getResultList(); 62 | for(Integer i : listaConDni) 63 | System.out.println(i); 64 | 65 | System.out.println("\nOtra forma de consultar personas"); 66 | q = session.createQuery("Select p from Persona p"); 67 | List listaDePersonas = q.getResultList(); 68 | for(Persona p : listaDePersonas) 69 | System.out.println(p); 70 | 71 | System.out.println("\nSolo las personas de sexo femenino"); 72 | q = session.createQuery("Select p from Persona p where p.sexo = 'F'"); 73 | listaDePersonas = q.getResultList(); 74 | for(Persona p : listaDePersonas) 75 | System.out.println(p); 76 | 77 | long totalPersonas = (long) session.createQuery("select count(p) from Persona p").uniqueResult(); 78 | System.out.println("\nCantidad de personas: " + totalPersonas); 79 | 80 | System.out.println("\nPersonas y su Departamento"); 81 | q = session.createQuery("Select p.dni, p.apellido, d.descripcion from Persona p, Departamento d where p.codigo_depto = d.codigo"); 82 | List listaDeDatos = q.getResultList(); 83 | for(Object[] registro : listaDeDatos) 84 | System.out.println(registro[0] + " " + registro[1] + " (" + registro[2] + ")"); 85 | 86 | } catch (HibernateException e) { 87 | if (tx != null) 88 | tx.rollback(); 89 | e.printStackTrace(); 90 | } finally { 91 | session.close(); 92 | factory.close(); 93 | } 94 | 95 | } 96 | } 97 | -------------------------------------------------------------------------------- /hibernate-basico/src/com/jwt/hibernate/Persona.java: -------------------------------------------------------------------------------- 1 | package com.jwt.hibernate; 2 | 3 | public class Persona { 4 | 5 | private int dni; 6 | private String apellido; 7 | private String nombre; 8 | private char sexo; 9 | private int codigo_depto; 10 | 11 | public int getDni() { 12 | return dni; 13 | } 14 | 15 | public void setDni(int dni) { 16 | this.dni = dni; 17 | } 18 | 19 | public String getApellido() { 20 | return apellido; 21 | } 22 | 23 | public void setApellido(String apellido) { 24 | this.apellido = apellido; 25 | } 26 | 27 | public String getNombre() { 28 | return nombre; 29 | } 30 | 31 | public void setNombre(String nombre) { 32 | this.nombre = nombre; 33 | } 34 | 35 | public char getSexo() { 36 | return sexo; 37 | } 38 | 39 | public void setSexo(char sexo) { 40 | this.sexo = sexo; 41 | } 42 | 43 | public int getCodigo_depto() { 44 | return codigo_depto; 45 | } 46 | 47 | public void setCodigo_depto(int codigo_depto) { 48 | this.codigo_depto = codigo_depto; 49 | } 50 | 51 | public String toString() { 52 | return dni + " " + apellido + ", " + nombre + " (" + sexo + ") Dpto[" + codigo_depto + "]"; 53 | } 54 | 55 | } 56 | -------------------------------------------------------------------------------- /hibernate-basico/src/com/jwt/hibernate/departamento.hbm.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /hibernate-basico/src/com/jwt/hibernate/persona.hbm.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /hibernate-basico/src/hibernate.cfg.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 | org.sqlite.JDBC 9 | jdbc:sqlite:./prueba.sqlite 10 | com.enigmabridge.hibernate.dialect.SQLiteDialect 11 | true 12 | true 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /sockets-basico/.classpath: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /sockets-basico/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | sockets-basico 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.jdt.core.javabuilder 10 | 11 | 12 | 13 | 14 | 15 | org.eclipse.jdt.core.javanature 16 | 17 | 18 | 19 | 1710944783794 20 | 21 | 30 22 | 23 | org.eclipse.core.resources.regexFilterMatcher 24 | node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__ 25 | 26 | 27 | 28 | 29 | -------------------------------------------------------------------------------- /sockets-basico/src/edu/unlam/taller/client/Cliente.java: -------------------------------------------------------------------------------- 1 | package edu.unlam.taller.client; 2 | 3 | import java.io.DataInputStream; 4 | import java.io.DataOutputStream; 5 | import java.io.IOException; 6 | import java.net.Socket; 7 | import java.net.UnknownHostException; 8 | import java.util.Scanner; 9 | 10 | // Importante: Checkear enconding -> UTF8 11 | 12 | public class Cliente { 13 | 14 | public Cliente(String ip, int puerto) throws UnknownHostException, IOException { 15 | // Conecta a un Server. Si no esta activo da Exception: 16 | // java.net.ConnectException 17 | Socket socket = new Socket(ip, puerto); 18 | 19 | // Flujos de información 20 | DataInputStream entrada = new DataInputStream(socket.getInputStream()); 21 | DataOutputStream salida = new DataOutputStream(socket.getOutputStream()); 22 | 23 | // Recibir mensaje 24 | System.out.println("Soy el cliente número: " + entrada.readUTF()); 25 | 26 | // Enviar mensaje escrito por consola 27 | Scanner scanner = new Scanner(System.in); 28 | String mensajeConsola = scanner.nextLine(); 29 | salida.writeUTF(mensajeConsola); 30 | 31 | // Cierre de recursos 32 | scanner.close(); 33 | entrada.close(); 34 | salida.close(); 35 | socket.close(); 36 | System.out.println("Me cierro"); 37 | } 38 | 39 | public static void main(String[] args) { 40 | try { 41 | new Cliente("localhost", 20000); 42 | } catch (IOException e) { 43 | e.printStackTrace(); 44 | } 45 | } 46 | 47 | } 48 | -------------------------------------------------------------------------------- /sockets-basico/src/edu/unlam/taller/server/Servidor.java: -------------------------------------------------------------------------------- 1 | package edu.unlam.taller.server; 2 | 3 | import java.io.DataInputStream; 4 | import java.io.DataOutputStream; 5 | import java.io.IOException; 6 | import java.net.ServerSocket; 7 | import java.net.Socket; 8 | 9 | public class Servidor { 10 | 11 | public Servidor(int puerto) throws IOException { 12 | ServerSocket servidor = new ServerSocket(puerto); 13 | 14 | System.out.println("Server inicializando..."); 15 | 16 | for (int numeroCliente = 1; numeroCliente <= 3; numeroCliente++) { 17 | // Se "congela" en la siguiente linea, hasta que llegue un pedido 18 | Socket socket = servidor.accept(); 19 | 20 | // Flujos de información 21 | DataOutputStream salida = new DataOutputStream(socket.getOutputStream()); 22 | DataInputStream entrada = new DataInputStream(socket.getInputStream()); 23 | 24 | System.out.println("Conectado cliente: " + numeroCliente); 25 | salida.writeUTF("" + numeroCliente); 26 | 27 | // El read también es bloqueante, como el accept 28 | System.out.println("Cliente \"" + numeroCliente + "\" dice: \"" + entrada.readUTF() + "\""); 29 | 30 | // Se cierran recursos 31 | entrada.close(); 32 | salida.close(); 33 | socket.close(); 34 | } 35 | 36 | System.out.println("Server Finalizado"); 37 | servidor.close(); 38 | } 39 | 40 | public static void main(String[] args) { 41 | try { 42 | new Servidor(20000); 43 | } catch (IOException e) { 44 | e.printStackTrace(); 45 | } 46 | } 47 | 48 | } 49 | -------------------------------------------------------------------------------- /swing-basico/.classpath: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /swing-basico/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | swing-basico 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.jdt.core.javabuilder 10 | 11 | 12 | 13 | 14 | 15 | org.eclipse.jdt.core.javanature 16 | 17 | 18 | 19 | 1710944783795 20 | 21 | 30 22 | 23 | org.eclipse.core.resources.regexFilterMatcher 24 | node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__ 25 | 26 | 27 | 28 | 29 | -------------------------------------------------------------------------------- /swing-basico/agregar.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/programacion-avanzada/workspace-taller/b05546c78e064962434ef9543500d001452b7319/swing-basico/agregar.png -------------------------------------------------------------------------------- /swing-basico/clientes.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/programacion-avanzada/workspace-taller/b05546c78e064962434ef9543500d001452b7319/swing-basico/clientes.png -------------------------------------------------------------------------------- /swing-basico/editar.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/programacion-avanzada/workspace-taller/b05546c78e064962434ef9543500d001452b7319/swing-basico/editar.png -------------------------------------------------------------------------------- /swing-basico/eliminar.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/programacion-avanzada/workspace-taller/b05546c78e064962434ef9543500d001452b7319/swing-basico/eliminar.png -------------------------------------------------------------------------------- /swing-basico/lib/jcalendar-1.4.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/programacion-avanzada/workspace-taller/b05546c78e064962434ef9543500d001452b7319/swing-basico/lib/jcalendar-1.4.jar -------------------------------------------------------------------------------- /swing-basico/src/edu/unlam/taller/ventanas/Cliente.java: -------------------------------------------------------------------------------- 1 | package edu.unlam.taller.ventanas; 2 | 3 | import java.util.Date; 4 | 5 | public class Cliente { 6 | private String dni; 7 | private String tipoDoc; 8 | private String apellido; 9 | private String nombre; 10 | private Date fechaNac; 11 | private String observaciones; 12 | 13 | public Cliente(String dni, String tipoDoc, String apellido, String nombre, Date fechaNac, String observaciones) { 14 | this.dni = dni; 15 | this.tipoDoc = tipoDoc; 16 | this.apellido = apellido; 17 | this.nombre = nombre; 18 | this.fechaNac = fechaNac; 19 | this.observaciones = observaciones; 20 | } 21 | 22 | public String getDni() { 23 | return dni; 24 | } 25 | 26 | public void setDni(String dni) { 27 | this.dni = dni; 28 | } 29 | 30 | public String getTipoDoc() { 31 | return tipoDoc; 32 | } 33 | 34 | public void setTipoDoc(String tipoDoc) { 35 | this.tipoDoc = tipoDoc; 36 | } 37 | 38 | public String getApellido() { 39 | return apellido; 40 | } 41 | 42 | public void setApellido(String apellido) { 43 | this.apellido = apellido; 44 | } 45 | 46 | public String getNombre() { 47 | return nombre; 48 | } 49 | 50 | public void setNombre(String nombre) { 51 | this.nombre = nombre; 52 | } 53 | 54 | public Date getFechaNac() { 55 | return fechaNac; 56 | } 57 | 58 | public void setFechaNac(Date fechaNac) { 59 | this.fechaNac = fechaNac; 60 | } 61 | 62 | public String getObservaciones() { 63 | return observaciones; 64 | } 65 | 66 | public void setObservaciones(String observaciones) { 67 | this.observaciones = observaciones; 68 | } 69 | 70 | } 71 | -------------------------------------------------------------------------------- /swing-basico/src/edu/unlam/taller/ventanas/JABMCliente.java: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/programacion-avanzada/workspace-taller/b05546c78e064962434ef9543500d001452b7319/swing-basico/src/edu/unlam/taller/ventanas/JABMCliente.java -------------------------------------------------------------------------------- /swing-basico/src/edu/unlam/taller/ventanas/JPrincipal.java: -------------------------------------------------------------------------------- 1 | package edu.unlam.taller.ventanas; 2 | 3 | import java.awt.BorderLayout; 4 | import java.awt.EventQueue; 5 | 6 | import javax.swing.JFrame; 7 | import javax.swing.JPanel; 8 | import javax.swing.border.EmptyBorder; 9 | import javax.swing.table.DefaultTableModel; 10 | 11 | import java.awt.GridBagLayout; 12 | import java.awt.Image; 13 | 14 | import javax.swing.JButton; 15 | import java.awt.GridBagConstraints; 16 | import java.awt.event.ActionListener; 17 | import java.util.HashMap; 18 | import java.awt.event.ActionEvent; 19 | import javax.swing.ImageIcon; 20 | import javax.swing.JScrollPane; 21 | import javax.swing.JTable; 22 | 23 | public class JPrincipal extends JFrame { 24 | 25 | private JPanel contentPane; 26 | private JButton btnAlta; 27 | private JButton btnEditar; 28 | private JButton btnEliminar; 29 | private JButton btnVer; 30 | private JTable tblClientes; 31 | 32 | private HashMap clientes; 33 | 34 | /** 35 | * Create the frame. 36 | */ 37 | public JPrincipal() { 38 | super("Clientes"); 39 | 40 | clientes = new HashMap(); 41 | 42 | this.setBounds(50, 50, 1024, 600); 43 | 44 | this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 45 | this.setLocationRelativeTo(null); 46 | getContentPane().setLayout(null); 47 | 48 | ImageIcon icoPrincipal = new ImageIcon(".\\clientes.png"); 49 | this.setIconImage(icoPrincipal.getImage()); 50 | 51 | ImageIcon icoAlta = new ImageIcon(".\\agregar.png"); 52 | Image imgAlta = icoAlta.getImage(); 53 | Image imagAltaRed = imgAlta.getScaledInstance(30, 30, Image.SCALE_SMOOTH); 54 | ImageIcon icoAltaRed = new ImageIcon(imagAltaRed); 55 | 56 | btnAlta = new JButton(icoAltaRed); 57 | btnAlta.addActionListener(new ActionListener() { 58 | public void actionPerformed(ActionEvent e) { 59 | abrirVentanaModoAltaDeCliente(); 60 | } 61 | }); 62 | btnAlta.setToolTipText("Alta de Nuevo Cliente"); 63 | btnAlta.setBounds(5, 5, 40, 40); 64 | 65 | getContentPane().add(btnAlta); 66 | 67 | ImageIcon icoEditar = new ImageIcon(".\\editar.png"); 68 | Image imgEditar = icoEditar.getImage(); 69 | Image imagEditarRed = imgEditar.getScaledInstance(30, 30, Image.SCALE_SMOOTH); 70 | ImageIcon icoEditarRed = new ImageIcon(imagEditarRed); 71 | 72 | JButton btnEditar = new JButton(icoEditarRed); 73 | btnEditar.addActionListener(new ActionListener() { 74 | public void actionPerformed(ActionEvent e) { 75 | abrirVentanaModoEdicionDeCliente(); 76 | } 77 | }); 78 | btnEditar.setToolTipText("Editar datos del Cliente"); 79 | btnEditar.setBounds(50, 5, 40, 40); 80 | getContentPane().add(btnEditar); 81 | 82 | ImageIcon icoEliminar = new ImageIcon(".\\eliminar.png"); 83 | Image imgEliminar = icoEliminar.getImage(); 84 | Image imagEliminarRed = imgEliminar.getScaledInstance(30, 30, Image.SCALE_SMOOTH); 85 | ImageIcon icoEliminarRed = new ImageIcon(imagEliminarRed); 86 | 87 | JButton btnEliminar = new JButton(icoEliminarRed); 88 | btnEliminar.addActionListener(new ActionListener() { 89 | public void actionPerformed(ActionEvent e) { 90 | abrirVentanaModoBajaDeCliente(); 91 | } 92 | }); 93 | btnEliminar.setToolTipText("Eliminar datos del Cliente seleccionado"); 94 | btnEliminar.setBounds(95, 5, 40, 40); 95 | getContentPane().add(btnEliminar); 96 | 97 | ImageIcon icoVer = new ImageIcon(".\\ver.png"); 98 | Image imgVer = icoVer.getImage(); 99 | Image imgVerRed = imgVer.getScaledInstance(30, 30, Image.SCALE_SMOOTH); 100 | ImageIcon icoVerRed = new ImageIcon(imgVerRed); 101 | 102 | JButton btnVer = new JButton(icoVerRed); 103 | btnVer.addActionListener(new ActionListener() { 104 | public void actionPerformed(ActionEvent e) { 105 | abrirVentanaModoVisualizarCliente(); 106 | } 107 | }); 108 | btnVer.setToolTipText("Mostrar datos del Cliente seleccionado"); 109 | btnVer.setBounds(140, 5, 40, 40); 110 | getContentPane().add(btnVer); 111 | 112 | JScrollPane scrollPane = new JScrollPane(); 113 | scrollPane.setBounds(5, 50, 1005, 516); 114 | getContentPane().add(scrollPane); 115 | 116 | tblClientes = new JTable(); 117 | DefaultTableModel modelo = (DefaultTableModel) tblClientes.getModel(); 118 | modelo.addColumn("Documento"); 119 | modelo.addColumn("Tipo Doc."); 120 | modelo.addColumn("Apellido/s"); 121 | modelo.addColumn("Nombre/s"); 122 | 123 | scrollPane.setViewportView(tblClientes); 124 | 125 | this.setResizable(false); 126 | this.setDefaultCloseOperation(EXIT_ON_CLOSE); 127 | this.setLocationRelativeTo(null); 128 | this.setVisible(true); 129 | } 130 | 131 | public void agregarNuevoCliente(Cliente cli)throws Exception{ 132 | if(clientes.containsKey(cli.getDni())) 133 | throw new Exception(); 134 | clientes.put(cli.getDni(), cli); 135 | } 136 | 137 | public void agregarNuevoClienteGrilla(Cliente cli) { 138 | int filas = clientes.size() - 1; 139 | DefaultTableModel modelo = (DefaultTableModel) tblClientes.getModel(); 140 | modelo.addRow(new Object[filas]); 141 | 142 | tblClientes.setValueAt(cli.getDni(), filas, 0); 143 | tblClientes.setValueAt(cli.getTipoDoc(), filas, 1); 144 | tblClientes.setValueAt(cli.getApellido(), filas, 2); 145 | tblClientes.setValueAt(cli.getNombre(), filas, 3); 146 | 147 | } 148 | 149 | public void modificarCliente(Cliente cli) { 150 | Cliente modi = clientes.get(cli.getDni()); 151 | clientes.put(modi.getDni(), cli); 152 | } 153 | 154 | public void modificarClienteGrilla(Cliente cli, int fila) { 155 | tblClientes.setValueAt(cli.getDni(), fila, 0); 156 | tblClientes.setValueAt(cli.getTipoDoc(), fila, 1); 157 | tblClientes.setValueAt(cli.getApellido(), fila, 2); 158 | tblClientes.setValueAt(cli.getNombre(), fila, 3); 159 | } 160 | 161 | public void eliminarCliente(Cliente cli) { 162 | clientes.remove(cli.getDni()); 163 | } 164 | 165 | public void eliminarClienteGrilla(Cliente cli, int fila) { 166 | DefaultTableModel modelo = (DefaultTableModel) tblClientes.getModel(); 167 | modelo.removeRow(fila); 168 | } 169 | 170 | public void abrirVentanaModoAltaDeCliente() { 171 | JABMCliente jCliente = new JABMCliente(this); 172 | jCliente.cargaIconoVentana(".\\agregar.png"); 173 | jCliente.seteaComportamientoBoton("Alta"); 174 | jCliente.setVisible(true); 175 | } 176 | 177 | public void abrirVentanaModoEdicionDeCliente() { 178 | Cliente cli = this.obtenerDatosDelCliente(this.obtenerFilaSeleccionadaGrilla()); 179 | if(cli == null) return; 180 | JABMCliente jCliente = new JABMCliente(this); 181 | jCliente.setTitle("Modificar Datos del Cliente"); 182 | jCliente.cargaIconoVentana(".\\editar.png"); 183 | jCliente.seteaComportamientoBoton("Modificar"); 184 | jCliente.cargaDatosDeClienteEnComponentes(cli); 185 | jCliente.seteaComponentesEditables(true); 186 | jCliente.setVisible(true); 187 | } 188 | 189 | public void abrirVentanaModoBajaDeCliente() { 190 | Cliente cli = this.obtenerDatosDelCliente(this.obtenerFilaSeleccionadaGrilla()); 191 | if(cli == null) return; 192 | JABMCliente jCliente = new JABMCliente(this); 193 | jCliente.setTitle("Eliminar Datos del Cliente"); 194 | jCliente.cargaIconoVentana(".\\eliminar.png"); 195 | jCliente.seteaComportamientoBoton("Eliminar"); 196 | jCliente.cargaDatosDeClienteEnComponentes(cli); 197 | jCliente.seteaComponentesEditables(false); 198 | jCliente.setVisible(true); 199 | } 200 | 201 | public void abrirVentanaModoVisualizarCliente() { 202 | Cliente cli = this.obtenerDatosDelCliente(this.obtenerFilaSeleccionadaGrilla()); 203 | if(cli == null) return; 204 | 205 | JABMCliente jCliente = new JABMCliente(this); 206 | jCliente.setTitle("Visualizar Datos del Cliente"); 207 | jCliente.cargaIconoVentana(".\\ver.png"); 208 | jCliente.seteaComportamientoBoton("Salir"); 209 | jCliente.seteaComponentesEditables(false); 210 | jCliente.cargaDatosDeClienteEnComponentes(cli); 211 | jCliente.setVisible(true); 212 | } 213 | 214 | public int obtenerFilaSeleccionadaGrilla() { 215 | int filaSeleccionada = tblClientes.getSelectedRow(); 216 | if(filaSeleccionada >= 0) return filaSeleccionada; 217 | return -1; 218 | } 219 | 220 | private Cliente obtenerDatosDelCliente(int fila) { 221 | if(fila >=0) return clientes.get(tblClientes.getValueAt(fila, 0)); 222 | return null; 223 | } 224 | 225 | /** 226 | * Launch the application. 227 | */ 228 | public static void main(String[] args) { 229 | new JPrincipal().setVisible(true); 230 | } 231 | } 232 | -------------------------------------------------------------------------------- /swing-basico/ver.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/programacion-avanzada/workspace-taller/b05546c78e064962434ef9543500d001452b7319/swing-basico/ver.png -------------------------------------------------------------------------------- /swing-multiventana/.classpath: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /swing-multiventana/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | swing-multiventana 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.jdt.core.javabuilder 10 | 11 | 12 | 13 | 14 | 15 | org.eclipse.jdt.core.javanature 16 | 17 | 18 | 19 | 1710944783797 20 | 21 | 30 22 | 23 | org.eclipse.core.resources.regexFilterMatcher 24 | node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__ 25 | 26 | 27 | 28 | 29 | -------------------------------------------------------------------------------- /swing-multiventana/README.md: -------------------------------------------------------------------------------- 1 | # Cambio de ventana en Swing 2 | Es frecuente ver aplicaciones que en vez de ejecutarse directamente usan un "launcher" o lanzador, el cual le da al usuario algún tipo de control sobre cómo quiere ejecutar 3 | la aplicación, generalmente permitiendo elegir la resolución de la misma, el volumen de los sonidos, o incluso un menu sobre el cual elegir una sala para comenzar una partida 4 | de un juego; entre otras cosas. 5 | Algunos ejemplos son: 6 | 7 | 8 | ![EJ-1](https://user-images.githubusercontent.com/17636012/123115661-a35bbf00-d416-11eb-8761-0e18cecf1df4.png) 9 | 10 | ![EJ-2](https://user-images.githubusercontent.com/17636012/123116363-3ac11200-d417-11eb-9eee-10baedcab8a6.png) 11 | *** 12 | Para recrear este comportamiento con Swing se puede usar un JFrame (supongamos "ventana host") que al hacer clic en un JButton instancie a otro JFrame, 13 | enviandole la información necesaria según la entrada del usuario, en nuestro ejemplo: 14 | 15 | ![image](https://user-images.githubusercontent.com/17636012/123117041-cc308400-d417-11eb-8132-f9cef13ba6cb.png) 16 | *** 17 | Por lo tanto, tiene que existir un JFrame que reciba como parametros la resolución a la cuál debe mostrarse, y si debe reproducir o no sonido. Dicho JFrame va a ser 18 | instanciado por nuestra "ventana host", la cual luego puede cerrarse si es necesario. 19 | Es importante notar que la instancia del nuevo JFrame tiene que correr en un hilo separado, ya que en caso contrario la ejecución de dicha instancia estaría atada a 20 | nuestra "ventana host", lo que podría provocar problemas de concurrencia y comportamientos no deseados como que por ejemplo al cerrar la ventana host se cierre el 21 | JFrame instanciado. 22 | -------------------------------------------------------------------------------- /swing-multiventana/sonido.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/programacion-avanzada/workspace-taller/b05546c78e064962434ef9543500d001452b7319/swing-multiventana/sonido.wav -------------------------------------------------------------------------------- /swing-multiventana/src/edu/unlam/taller/multiventanas/JApp.java: -------------------------------------------------------------------------------- 1 | package edu.unlam.taller.multiventanas; 2 | 3 | import java.awt.BorderLayout; 4 | import java.awt.EventQueue; 5 | import java.io.File; 6 | import java.io.IOException; 7 | 8 | import javax.sound.sampled.AudioInputStream; 9 | import javax.sound.sampled.AudioSystem; 10 | import javax.sound.sampled.Clip; 11 | import javax.sound.sampled.UnsupportedAudioFileException; 12 | import javax.swing.JFrame; 13 | import javax.swing.JPanel; 14 | import javax.swing.border.EmptyBorder; 15 | 16 | public class JApp extends JFrame { 17 | 18 | private JPanel contentPane; 19 | 20 | /** 21 | * Create the frame. 22 | */ 23 | public JApp(int width, int height, boolean sound) throws Exception { 24 | setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 25 | setBounds(100, 100, width, height); 26 | contentPane = new JPanel(); 27 | contentPane.setBorder(new EmptyBorder(5, 5, 5, 5)); 28 | contentPane.setLayout(new BorderLayout(0, 0)); 29 | setContentPane(contentPane); 30 | if(sound) { 31 | AudioInputStream audioIn = AudioSystem.getAudioInputStream(new File("./sonido.wav")); 32 | Clip clip = AudioSystem.getClip(); 33 | clip.open(audioIn); 34 | clip.flush(); 35 | clip.setMicrosecondPosition(0); 36 | clip.loop(Clip.LOOP_CONTINUOUSLY); 37 | } 38 | setVisible(true); 39 | } 40 | 41 | } 42 | -------------------------------------------------------------------------------- /swing-multiventana/src/edu/unlam/taller/multiventanas/JConfig.java: -------------------------------------------------------------------------------- 1 | package edu.unlam.taller.multiventanas; 2 | 3 | import java.awt.BorderLayout; 4 | import java.awt.EventQueue; 5 | import java.awt.Font; 6 | 7 | import javax.swing.JFrame; 8 | import javax.swing.JPanel; 9 | import javax.swing.border.EmptyBorder; 10 | 11 | import java.awt.GridBagLayout; 12 | import javax.swing.JComboBox; 13 | import java.awt.GridBagConstraints; 14 | import java.awt.Insets; 15 | import java.awt.event.ActionEvent; 16 | import java.awt.event.ActionListener; 17 | 18 | import javax.swing.DefaultComboBoxModel; 19 | import javax.swing.JCheckBox; 20 | import javax.swing.JButton; 21 | import javax.swing.JTextPane; 22 | 23 | public class JConfig extends JFrame { 24 | 25 | private JPanel contentPane; 26 | private JComboBox comboBox; 27 | private JCheckBox checkBox; 28 | /** 29 | * Launch the application. 30 | */ 31 | public static void main(String[] args) { 32 | EventQueue.invokeLater(new Runnable() { 33 | public void run() { 34 | try { 35 | JConfig frame = new JConfig(); 36 | frame.setVisible(true); 37 | } catch (Exception e) { 38 | e.printStackTrace(); 39 | } 40 | } 41 | }); 42 | } 43 | 44 | /** 45 | * Create the frame. 46 | */ 47 | public JConfig() { 48 | setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 49 | setBounds(100, 100, 450, 300); 50 | contentPane = new JPanel(); 51 | contentPane.setBorder(new EmptyBorder(5, 5, 5, 5)); 52 | setContentPane(contentPane); 53 | GridBagLayout gbl_contentPane = new GridBagLayout(); 54 | gbl_contentPane.columnWidths = new int[]{0, 0, 0, 0, 0, 0}; 55 | gbl_contentPane.rowHeights = new int[]{0, 0, 0, 0, 0, 0, 0, 0, 0}; 56 | gbl_contentPane.columnWeights = new double[]{0.0, 0.0, 0.0, 0.0, 0.0, 0.0}; 57 | gbl_contentPane.rowWeights = new double[]{1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0}; 58 | contentPane.setLayout(gbl_contentPane); 59 | 60 | JTextPane textPane = new JTextPane(); 61 | textPane.setBackground(getForeground()); 62 | textPane.setEditable(false); 63 | textPane.setText("App launcher v0.1"); 64 | textPane.setFont(new Font("Arial",Font.BOLD,22)); 65 | GridBagConstraints gbc_textPane = new GridBagConstraints(); 66 | gbc_textPane.gridheight = 2; 67 | gbc_textPane.gridwidth = 6; 68 | gbc_textPane.insets = new Insets(0, 0, 5, 5); 69 | //gbc_textPane.fill = GridBagConstraints.BOTH; 70 | gbc_textPane.gridx = 0; 71 | gbc_textPane.gridy = 0; 72 | contentPane.add(textPane, gbc_textPane); 73 | 74 | JComboBox comboBox = new JComboBox(); 75 | comboBox.setModel(new DefaultComboBoxModel(new String[] {"1920x1080", "1280x720", "800x600"})); 76 | GridBagConstraints gbc_comboBox = new GridBagConstraints(); 77 | gbc_comboBox.gridwidth = 2; 78 | gbc_comboBox.insets = new Insets(0, 0, 5, 5); 79 | gbc_comboBox.fill = GridBagConstraints.HORIZONTAL; 80 | gbc_comboBox.gridx = 2; 81 | gbc_comboBox.gridy = 2; 82 | contentPane.add(comboBox, gbc_comboBox); 83 | 84 | JCheckBox chckbxNewCheckBox = new JCheckBox("Sonido"); 85 | GridBagConstraints gbc_chckbxNewCheckBox = new GridBagConstraints(); 86 | gbc_chckbxNewCheckBox.insets = new Insets(0, 0, 5, 5); 87 | gbc_chckbxNewCheckBox.gridx = 2; 88 | gbc_chckbxNewCheckBox.gridy = 4; 89 | contentPane.add(chckbxNewCheckBox, gbc_chckbxNewCheckBox); 90 | 91 | JButton btnNewButton = new JButton("Lanzar app"); 92 | GridBagConstraints gbc_btnNewButton = new GridBagConstraints(); 93 | gbc_btnNewButton.gridwidth = 2; 94 | gbc_btnNewButton.insets = new Insets(0, 0, 0, 5); 95 | gbc_btnNewButton.gridx = 2; 96 | gbc_btnNewButton.gridy = 7; 97 | btnNewButton.addActionListener(new ActionListener() { 98 | public void actionPerformed(ActionEvent e) { 99 | enviarDatosApp(); 100 | } 101 | }); 102 | contentPane.add(btnNewButton, gbc_btnNewButton); 103 | 104 | this.comboBox = comboBox; 105 | this.checkBox = chckbxNewCheckBox; 106 | } 107 | 108 | protected void enviarDatosApp() { 109 | Thread thread =new Thread(new Runnable() { 110 | @Override 111 | public void run() { 112 | int[][] resoluciones = { {1920,1080}, {1280,720}, {800,600}}; 113 | try { 114 | JApp otraVentana = new JApp(resoluciones[comboBox.getSelectedIndex()][0],resoluciones[comboBox.getSelectedIndex()][1],checkBox.isSelected()); 115 | } catch (Exception e) { 116 | // TODO Auto-generated catch block 117 | e.printStackTrace(); 118 | } 119 | 120 | } 121 | }); 122 | thread.start(); 123 | this.dispose(); 124 | 125 | } 126 | 127 | } 128 | -------------------------------------------------------------------------------- /threads/.classpath: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /threads/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | threads 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.jdt.core.javabuilder 10 | 11 | 12 | 13 | 14 | 15 | org.eclipse.jdt.core.javanature 16 | 17 | 18 | 19 | 1710944783799 20 | 21 | 30 22 | 23 | org.eclipse.core.resources.regexFilterMatcher 24 | node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__ 25 | 26 | 27 | 28 | 29 | -------------------------------------------------------------------------------- /threads/src/edu/unlam/taller/threads/MiThread.java: -------------------------------------------------------------------------------- 1 | package edu.unlam.taller.threads; 2 | 3 | public class MiThread extends Thread { 4 | public MiThread(String name) { 5 | super(name); 6 | } 7 | 8 | @Override 9 | public void run() { 10 | for (int i = 1; i <= 10; i++) { 11 | System.out.println(i + " " + getName()); 12 | 13 | try { 14 | sleep((int)(Math.random() * 500)); 15 | } catch (InterruptedException e) { 16 | e.printStackTrace(); 17 | } 18 | 19 | } 20 | System.out.println(getName() + " Listo!!!"); 21 | } 22 | 23 | public static void main(String arg[]) { 24 | MiThread mt = new MiThread("Alfa"); 25 | mt.start(); 26 | 27 | new MiThread("Beta").start(); 28 | 29 | Thread x = new Thread("Gamma") { 30 | @Override 31 | public void run() { 32 | System.out.println(getName() + " hasta aquí llegó..."); 33 | } 34 | }; 35 | x.start(); 36 | 37 | System.out.println("chau"); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /threads/src/edu/unlam/taller/threads/ThreadProductorConsumidor.java: -------------------------------------------------------------------------------- 1 | package edu.unlam.taller.threads; 2 | 3 | import java.util.LinkedList; 4 | 5 | public class ThreadProductorConsumidor { 6 | public final static int MAX_CANTIDAD = 10; 7 | 8 | public static void main(String[] args) throws InterruptedException { 9 | final ProductorConsumidor pc = new ProductorConsumidor(); 10 | 11 | // Se crea el thread productor 12 | Thread t1 = new Thread(new Runnable() { 13 | @Override 14 | public void run() { 15 | try { 16 | pc.producir(); 17 | } catch (InterruptedException e) { 18 | e.printStackTrace(); 19 | } 20 | } 21 | }); 22 | 23 | // Se crea el thread consumidor 24 | Thread t2 = new Thread(new Runnable() { 25 | @Override 26 | public void run() { 27 | try { 28 | pc.consumir(); 29 | } catch (InterruptedException e) { 30 | e.printStackTrace(); 31 | } 32 | } 33 | }); 34 | 35 | // Se inician ambos threads 36 | t1.start(); 37 | t2.start(); 38 | 39 | // Se espera por la finalización de ambos threads 40 | t1.join(); 41 | t2.join(); 42 | 43 | System.out.println("Fin"); 44 | } 45 | 46 | public static class ProductorConsumidor { 47 | LinkedList almacen = new LinkedList<>(); 48 | private int capacidad = 5; 49 | static int id = 1; 50 | 51 | // Metodo invocado por el productor 52 | public synchronized void producir() throws InterruptedException { 53 | 54 | while (id <= MAX_CANTIDAD) { 55 | // El thread del productor espera mientras el almacen esta lleno 56 | if (almacen.size() == capacidad) { 57 | // Notifico al consumidor para que sepa que puede consumir (activa el wait) 58 | notify(); 59 | wait(); 60 | } 61 | 62 | System.out.println("🌳 -> 🍎 #" + id); 63 | almacen.add(id++); 64 | 65 | Thread.sleep(100); 66 | } 67 | notify(); 68 | System.out.println("Terminé de producir"); 69 | } 70 | 71 | // Metodo invocado por el consumidor 72 | public synchronized void consumir() throws InterruptedException { 73 | boolean continuar = true; 74 | while (continuar) { 75 | // El thread del productor espera mientras el almacen esta vacio 76 | if (almacen.size() == 0) { 77 | // Notifico al productor para que sepa que hay lugar para producir 78 | notify(); 79 | wait(); 80 | } 81 | 82 | int producto = almacen.removeFirst(); 83 | System.out.println("😋 <- 🍎 #" + producto); 84 | 85 | continuar = producto < MAX_CANTIDAD; 86 | 87 | Thread.sleep(100); 88 | } 89 | System.out.println("Terminé de consumir"); 90 | } 91 | } 92 | } 93 | -------------------------------------------------------------------------------- /utils/plantuml.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/programacion-avanzada/workspace-taller/b05546c78e064962434ef9543500d001452b7319/utils/plantuml.jar --------------------------------------------------------------------------------