├── .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 | [](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