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
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
197 additions
and
180 deletions
+197
-180
README.md
+3
-2
Something.java
+194
-178
No files found.
README.md
View file @
090633c1
# ANOTACIONES
### Para compilar y ejecutar
*
compilar con
`javac Something.java`
*
luego, ejecutar con
`java Something`
\ No newline at end of file
*
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,29 +31,11 @@ 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
();
/*
mover(gc, bicicleta, 50);
mover(gc, bicicleta, 50, 1.5708);
mover(gc, bicicleta, 50, 0);
mover(gc, bicicleta, 50, 1.5708);
mover(gc, bicicleta, 50, 0);
mover(gc, bicicleta, 50, 1.5708);
mover(gc, bicicleta, 50, 3.14159);
mover(gc, bicicleta, 25, 4.71239);
mover(gc, bicicleta, 100, 0.523599);
mover(gc, bicicleta, 100, 5.23599);
*/
//gc.strokeLine(200, 50, 300, 50);
//gc.strokeLine(0, 0, 300, 50);
try
{
//FileInputStream inputstream = new FileInputStream("file:javacleta.png");
FileInputStream
inputstream
=
new
FileInputStream
(
"bici.png"
);
...
...
@@ -61,7 +43,195 @@ public class Something extends Application
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
);
//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);
mover(gc, bicicleta, 50, 1.5708);
mover(gc, bicicleta, 50, 0);
mover(gc, bicicleta, 50, 1.5708);
mover(gc, bicicleta, 50, 0);
mover(gc, bicicleta, 50, 1.5708);
mover(gc, bicicleta, 50, 3.14159);
mover(gc, bicicleta, 25, 4.71239);
mover(gc, bicicleta, 100, 0.523599);
mover(gc, bicicleta, 100, 5.23599);
*/
//gc.strokeLine(200, 50, 300, 50);
//gc.strokeLine(0, 0, 300, 50);
//Crea los botones
Button
boton1
=
new
Button
();
Button
boton2
=
new
Button
();
Button
boton3
=
new
Button
();
Button
boton4
=
new
Button
();
Button
boton5
=
new
Button
();
Button
boton6
=
new
Button
();
Button
boton7
=
new
Button
();
Button
boton8
=
new
Button
();
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
,
imagen
);
}
});
boton2
.
setText
(
"N"
);
boton2
.
setPrefSize
(
40
,
40
);
boton2
.
setLayoutX
(
50
);
boton2
.
setLayoutY
(
0
);
boton2
.
setOnAction
(
new
EventHandler
<
ActionEvent
>()
{
@Override
public
void
handle
(
ActionEvent
event
)
{
mover
(
gc
,
bicicleta
,
distancia
,
1.570796326791001
,
imagen
);
}
});
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.5235987755970001
,
imagen
);
}
});
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
,
imagen
);
}
});
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
,
imagen
);
}
});
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
,
imagen
);
}
});
boton7
.
setText
(
"S"
);
boton7
.
setPrefSize
(
40
,
40
);
boton7
.
setLayoutX
(
50
);
boton7
.
setLayoutY
(
100
);
boton7
.
setOnAction
(
new
EventHandler
<
ActionEvent
>()
{
@Override
public
void
handle
(
ActionEvent
event
)
{
mover
(
gc
,
bicicleta
,
distancia
,
4.712388980373
,
imagen
);
}
});
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
,
imagen
);
}
});
root
.
setStyle
(
"-fx-border-style: solid inside;"
+
"-fx-border-width: 2;"
+
"-fx-border-insets: 5;"
+
"-fx-border-radius: 5;"
+
"-fx-border-color: blue;"
);
root
.
getChildren
().
add
(
canvas
);
root
.
getChildren
().
add
(
boton1
);
root
.
getChildren
().
add
(
boton2
);
root
.
getChildren
().
add
(
boton3
);
root
.
getChildren
().
add
(
boton4
);
root
.
getChildren
().
add
(
boton5
);
root
.
getChildren
().
add
(
boton6
);
root
.
getChildren
().
add
(
boton7
);
root
.
getChildren
().
add
(
boton8
);
Scene
scene
=
new
Scene
(
root
);
scene
.
setOnKeyPressed
(
e
->
{
if
(
e
.
getCode
()
==
KeyCode
.
NUMPAD1
)
{
mover
(
gc
,
bicicleta
,
distancia
,
3.665191429179
,
imagen
);
}
else
if
(
e
.
getCode
()
==
KeyCode
.
NUMPAD2
)
{
mover
(
gc
,
bicicleta
,
distancia
,
4.712388980373
,
imagen
);
}
else
if
(
e
.
getCode
()
==
KeyCode
.
NUMPAD3
)
{
mover
(
gc
,
bicicleta
,
distancia
,
5.23598775597
,
imagen
);
}
else
if
(
e
.
getCode
()
==
KeyCode
.
NUMPAD4
)
{
mover
(
gc
,
bicicleta
,
distancia
,
3.141592653582001
,
imagen
);
}
else
if
(
e
.
getCode
()
==
KeyCode
.
NUMPAD6
)
{
mover
(
gc
,
bicicleta
,
distancia
,
0
,
imagen
);
}
else
if
(
e
.
getCode
()
==
KeyCode
.
NUMPAD7
)
{
mover
(
gc
,
bicicleta
,
distancia
,
2.09439510238807
,
imagen
);
}
else
if
(
e
.
getCode
()
==
KeyCode
.
NUMPAD8
)
{
mover
(
gc
,
bicicleta
,
distancia
,
1.570796326791001
,
imagen
);
}
else
if
(
e
.
getCode
()
==
KeyCode
.
NUMPAD9
)
{
mover
(
gc
,
bicicleta
,
distancia
,
0.5235987755970001
,
imagen
);
}
else
if
(
e
.
getCode
()
==
KeyCode
.
PLUS
)
{
//distancia++;
}
else
if
(
e
.
getCode
()
==
KeyCode
.
MINUS
)
{
//distancia--;
}
});
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
());
...
...
@@ -69,169 +239,13 @@ public class Something extends Application
System
.
out
.
println
(
"error: no se pudo cargar la imagen"
);
System
.
out
.
println
(
e
.
getMessage
());
}
//Crea los botones
Button
boton1
=
new
Button
();
Button
boton2
=
new
Button
();
Button
boton3
=
new
Button
();
Button
boton4
=
new
Button
();
Button
boton5
=
new
Button
();
Button
boton6
=
new
Button
();
Button
boton7
=
new
Button
();
Button
boton8
=
new
Button
();
boton1
.
setText
(
"NE"
);
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
);
}
});
boton2
.
setText
(
"N"
);
boton2
.
setPrefSize
(
40
,
40
);
boton2
.
setLayoutX
(
50
);
boton2
.
setLayoutY
(
0
);
boton2
.
setOnAction
(
new
EventHandler
<
ActionEvent
>()
{
@Override
public
void
handle
(
ActionEvent
event
)
{
mover
(
gc
,
bicicleta
,
distancia
,
1.570796326791001
);
}
});
boton3
.
setText
(
"NO"
);
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
);
}
});
boton4
.
setText
(
"E"
);
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
);
}
});
boton5
.
setText
(
"O"
);
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
);
}
});
boton6
.
setText
(
"SE"
);
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
);
}
});
boton7
.
setText
(
"S"
);
boton7
.
setPrefSize
(
40
,
40
);
boton7
.
setLayoutX
(
50
);
boton7
.
setLayoutY
(
100
);
boton7
.
setOnAction
(
new
EventHandler
<
ActionEvent
>()
{
@Override
public
void
handle
(
ActionEvent
event
)
{
mover
(
gc
,
bicicleta
,
distancia
,
4.712388980373
);
}
});
boton8
.
setText
(
"SO"
);
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
);
}
});
Pane
root
=
new
Pane
();
root
.
setStyle
(
"-fx-border-style: solid inside;"
+
"-fx-border-width: 2;"
+
"-fx-border-insets: 5;"
+
"-fx-border-radius: 5;"
+
"-fx-border-color: blue;"
);
root
.
getChildren
().
add
(
canvas
);
root
.
getChildren
().
add
(
boton1
);
root
.
getChildren
().
add
(
boton2
);
root
.
getChildren
().
add
(
boton3
);
root
.
getChildren
().
add
(
boton4
);
root
.
getChildren
().
add
(
boton5
);
root
.
getChildren
().
add
(
boton6
);
root
.
getChildren
().
add
(
boton7
);
root
.
getChildren
().
add
(
boton8
);
Scene
scene
=
new
Scene
(
root
);
scene
.
setOnKeyPressed
(
e
->
{
if
(
e
.
getCode
()
==
KeyCode
.
NUMPAD1
)
{
mover
(
gc
,
bicicleta
,
distancia
,
3.665191429179
);
}
else
if
(
e
.
getCode
()
==
KeyCode
.
NUMPAD2
)
{
mover
(
gc
,
bicicleta
,
distancia
,
4.712388980373
);
}
else
if
(
e
.
getCode
()
==
KeyCode
.
NUMPAD3
)
{
mover
(
gc
,
bicicleta
,
distancia
,
5.23598775597
);
}
else
if
(
e
.
getCode
()
==
KeyCode
.
NUMPAD4
)
{
mover
(
gc
,
bicicleta
,
distancia
,
3.141592653582001
);
}
else
if
(
e
.
getCode
()
==
KeyCode
.
NUMPAD6
)
{
mover
(
gc
,
bicicleta
,
distancia
,
0
);
}
else
if
(
e
.
getCode
()
==
KeyCode
.
NUMPAD7
)
{
mover
(
gc
,
bicicleta
,
distancia
,
2.09439510238807
);
}
else
if
(
e
.
getCode
()
==
KeyCode
.
NUMPAD8
)
{
mover
(
gc
,
bicicleta
,
distancia
,
1.570796326791001
);
}
else
if
(
e
.
getCode
()
==
KeyCode
.
NUMPAD9
)
{
mover
(
gc
,
bicicleta
,
distancia
,
0.523598775597001
);
}
else
if
(
e
.
getCode
()
==
KeyCode
.
PLUS
)
{
//distancia++;
}
else
if
(
e
.
getCode
()
==
KeyCode
.
MINUS
)
{
//distancia--;
}
});
stage
.
setScene
(
scene
);
stage
.
setTitle
(
"Óyeme Carlos llévame en tu Bicicleta"
);
stage
.
show
();
}
//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