Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
J
java-e006-javacleta
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Pedro Rolon
java-e006-javacleta
Commits
090633c1
Commit
090633c1
authored
Nov 07, 2018
by
Pedro Rolon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Se agregó un dibujito de una bicicleta
parent
73c3e557
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
57 additions
and
39 deletions
+57
-39
README.md
+2
-0
Something.java
+55
-39
No files found.
README.md
View file @
090633c1
...
...
@@ -2,3 +2,4 @@
### Para compilar y ejecutar
*
compilar con
`javac Something.java`
*
luego, ejecutar con
`java Something`
*
Se puede controlar el movimiento mediante el teclado numérico
\ No newline at end of file
Something.java
View file @
090633c1
...
...
@@ -31,9 +31,28 @@ public class Something extends Application
Canvas
canvas
=
new
Canvas
(
700
,
700
);
GraphicsContext
gc
=
canvas
.
getGraphicsContext2D
();
gc
.
setLineWidth
(
2.0
);
Pane
root
=
new
Pane
();
ImageView
imagen
;
Bicicleta
bicicleta
=
new
Bicicleta
();
try
{
//FileInputStream inputstream = new FileInputStream("file:javacleta.png");
FileInputStream
inputstream
=
new
FileInputStream
(
"bici.png"
);
//se setea el tamaño de la imagen!
Image
img
=
new
Image
(
inputstream
,
50
,
50
,
false
,
false
);
//gc.drawImage(img, 0, 0);
//es 350 menos porque se toma en cuenta el tamaño de la imagen!
//gc.drawImage(img, bicicleta.x, 350-bicicleta.y);
imagen
=
new
ImageView
(
img
);
imagen
.
setX
(
5
+
bicicleta
.
x
);
imagen
.
setY
(
300
-
bicicleta
.
y
);
root
.
getChildren
().
add
(
imagen
);
/*
mover(gc, bicicleta, 50);
...
...
@@ -54,21 +73,7 @@ public class Something extends Application
//gc.strokeLine(0, 0, 300, 50);
try
{
//FileInputStream inputstream = new FileInputStream("file:javacleta.png");
FileInputStream
inputstream
=
new
FileInputStream
(
"bici.png"
);
//se setea el tamaño de la imagen!
Image
img
=
new
Image
(
inputstream
,
50
,
50
,
false
,
false
);
//gc.drawImage(img, 0, 0);
//es 350 menos porque se toma en cuenta el tamaño de la imagen!
gc
.
drawImage
(
img
,
bicicleta
.
x
,
350
-
bicicleta
.
y
);
}
catch
(
FileNotFoundException
e
){
System
.
out
.
println
(
"Ocurió un error en la carga de imagen!"
);
System
.
out
.
println
(
e
.
getMessage
());
}
catch
(
Exception
e
){
System
.
out
.
println
(
"error: no se pudo cargar la imagen"
);
System
.
out
.
println
(
e
.
getMessage
());
}
//Crea los botones
Button
boton1
=
new
Button
();
...
...
@@ -81,14 +86,14 @@ public class Something extends Application
Button
boton8
=
new
Button
();
boton1
.
setText
(
"NE
"
);
boton1
.
setText
(
"NO
"
);
boton1
.
setPrefSize
(
40
,
40
);
boton1
.
setLayoutX
(
0
);
boton1
.
setLayoutY
(
0
);
boton1
.
setOnAction
(
new
EventHandler
<
ActionEvent
>()
{
@Override
public
void
handle
(
ActionEvent
event
)
{
mover
(
gc
,
bicicleta
,
distancia
,
2.09439510238807
);
mover
(
gc
,
bicicleta
,
distancia
,
2.09439510238807
,
imagen
);
}
});
...
...
@@ -99,51 +104,51 @@ public class Something extends Application
boton2
.
setOnAction
(
new
EventHandler
<
ActionEvent
>()
{
@Override
public
void
handle
(
ActionEvent
event
)
{
mover
(
gc
,
bicicleta
,
distancia
,
1.570796326791001
);
mover
(
gc
,
bicicleta
,
distancia
,
1.570796326791001
,
imagen
);
}
});
boton3
.
setText
(
"NO
"
);
boton3
.
setText
(
"NE
"
);
boton3
.
setPrefSize
(
40
,
40
);
boton3
.
setLayoutX
(
100
);
boton3
.
setLayoutY
(
0
);
boton3
.
setOnAction
(
new
EventHandler
<
ActionEvent
>()
{
@Override
public
void
handle
(
ActionEvent
event
)
{
mover
(
gc
,
bicicleta
,
distancia
,
0.523598775597001
);
mover
(
gc
,
bicicleta
,
distancia
,
0.5235987755970001
,
imagen
);
}
});
boton4
.
setText
(
"E
"
);
boton4
.
setText
(
"O
"
);
boton4
.
setPrefSize
(
40
,
40
);
boton4
.
setLayoutX
(
0
);
boton4
.
setLayoutY
(
50
);
boton4
.
setOnAction
(
new
EventHandler
<
ActionEvent
>()
{
@Override
public
void
handle
(
ActionEvent
event
)
{
mover
(
gc
,
bicicleta
,
distancia
,
3.141592653582001
);
mover
(
gc
,
bicicleta
,
distancia
,
3.141592653582001
,
imagen
);
}
});
boton5
.
setText
(
"O
"
);
boton5
.
setText
(
"E
"
);
boton5
.
setPrefSize
(
40
,
40
);
boton5
.
setLayoutX
(
100
);
boton5
.
setLayoutY
(
50
);
boton5
.
setOnAction
(
new
EventHandler
<
ActionEvent
>()
{
@Override
public
void
handle
(
ActionEvent
event
)
{
mover
(
gc
,
bicicleta
,
distancia
,
0
);
mover
(
gc
,
bicicleta
,
distancia
,
0
,
imagen
);
}
});
boton6
.
setText
(
"SE
"
);
boton6
.
setText
(
"SO
"
);
boton6
.
setPrefSize
(
40
,
40
);
boton6
.
setLayoutX
(
0
);
boton6
.
setLayoutY
(
100
);
boton6
.
setOnAction
(
new
EventHandler
<
ActionEvent
>()
{
@Override
public
void
handle
(
ActionEvent
event
)
{
mover
(
gc
,
bicicleta
,
distancia
,
3.665191429179
);
mover
(
gc
,
bicicleta
,
distancia
,
3.665191429179
,
imagen
);
}
});
...
...
@@ -154,23 +159,23 @@ public class Something extends Application
boton7
.
setOnAction
(
new
EventHandler
<
ActionEvent
>()
{
@Override
public
void
handle
(
ActionEvent
event
)
{
mover
(
gc
,
bicicleta
,
distancia
,
4.712388980373
);
mover
(
gc
,
bicicleta
,
distancia
,
4.712388980373
,
imagen
);
}
});
boton8
.
setText
(
"SO
"
);
boton8
.
setText
(
"SE
"
);
boton8
.
setPrefSize
(
40
,
40
);
boton8
.
setLayoutX
(
100
);
boton8
.
setLayoutY
(
100
);
boton8
.
setOnAction
(
new
EventHandler
<
ActionEvent
>()
{
@Override
public
void
handle
(
ActionEvent
event
)
{
mover
(
gc
,
bicicleta
,
distancia
,
5.23598775597
);
mover
(
gc
,
bicicleta
,
distancia
,
5.23598775597
,
imagen
);
}
});
Pane
root
=
new
Pane
();
root
.
setStyle
(
"-fx-border-style: solid inside;"
+
"-fx-border-width: 2;"
+
"-fx-border-insets: 5;"
+
...
...
@@ -192,28 +197,28 @@ public class Something extends Application
scene
.
setOnKeyPressed
(
e
->
{
if
(
e
.
getCode
()
==
KeyCode
.
NUMPAD1
)
{
mover
(
gc
,
bicicleta
,
distancia
,
3.665191429179
);
mover
(
gc
,
bicicleta
,
distancia
,
3.665191429179
,
imagen
);
}
else
if
(
e
.
getCode
()
==
KeyCode
.
NUMPAD2
)
{
mover
(
gc
,
bicicleta
,
distancia
,
4.712388980373
);
mover
(
gc
,
bicicleta
,
distancia
,
4.712388980373
,
imagen
);
}
else
if
(
e
.
getCode
()
==
KeyCode
.
NUMPAD3
)
{
mover
(
gc
,
bicicleta
,
distancia
,
5.23598775597
);
mover
(
gc
,
bicicleta
,
distancia
,
5.23598775597
,
imagen
);
}
else
if
(
e
.
getCode
()
==
KeyCode
.
NUMPAD4
)
{
mover
(
gc
,
bicicleta
,
distancia
,
3.141592653582001
);
mover
(
gc
,
bicicleta
,
distancia
,
3.141592653582001
,
imagen
);
}
else
if
(
e
.
getCode
()
==
KeyCode
.
NUMPAD6
)
{
mover
(
gc
,
bicicleta
,
distancia
,
0
);
mover
(
gc
,
bicicleta
,
distancia
,
0
,
imagen
);
}
else
if
(
e
.
getCode
()
==
KeyCode
.
NUMPAD7
)
{
mover
(
gc
,
bicicleta
,
distancia
,
2.09439510238807
);
mover
(
gc
,
bicicleta
,
distancia
,
2.09439510238807
,
imagen
);
}
else
if
(
e
.
getCode
()
==
KeyCode
.
NUMPAD8
)
{
mover
(
gc
,
bicicleta
,
distancia
,
1.570796326791001
);
mover
(
gc
,
bicicleta
,
distancia
,
1.570796326791001
,
imagen
);
}
else
if
(
e
.
getCode
()
==
KeyCode
.
NUMPAD9
)
{
mover
(
gc
,
bicicleta
,
distancia
,
0.523598775597001
);
mover
(
gc
,
bicicleta
,
distancia
,
0.5235987755970001
,
imagen
);
}
else
if
(
e
.
getCode
()
==
KeyCode
.
PLUS
)
{
//distancia++;
...
...
@@ -227,11 +232,20 @@ public class Something extends Application
stage
.
setScene
(
scene
);
stage
.
setTitle
(
"Óyeme Carlos llévame en tu Bicicleta"
);
stage
.
show
();
}
catch
(
FileNotFoundException
e
){
System
.
out
.
println
(
"Ocurió un error en la carga de imagen!"
);
System
.
out
.
println
(
e
.
getMessage
());
}
catch
(
Exception
e
){
System
.
out
.
println
(
"error: no se pudo cargar la imagen"
);
System
.
out
.
println
(
e
.
getMessage
());
}
}
//Mueve la bicicleta y dibuja su recorrido
//Recibe como parámetro la distancia y dirección de la bicicleta
private
void
mover
(
GraphicsContext
gc
,
Bicicleta
bicicleta
,
double
distancia
,
double
direccion
){
private
void
mover
(
GraphicsContext
gc
,
Bicicleta
bicicleta
,
double
distancia
,
double
direccion
,
ImageView
imagen
){
double
xInicial
=
10
+
bicicleta
.
x
;
//El 400 se le resta para que aparezca hacia abajo, pues las coordenadas están invertidas
double
yInicial
=
400
-
bicicleta
.
y
;
...
...
@@ -245,6 +259,8 @@ public class Something extends Application
gc
.
strokeLine
(
xInicial
,
yInicial
,
xFinal
,
yFinal
);
System
.
out
.
println
(
bicicleta
.
x
+
" "
+
bicicleta
.
y
+
" elo"
);
imagen
.
setX
(
xFinal
);
imagen
.
setY
(
yFinal
-
40
);
}
//Mueve la bicicleta y dibuja su recorrido
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment