Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
Daniel Vogel
cs349-code
Commits
fb689418
Commit
fb689418
authored
Nov 01, 2017
by
Daniel Vogel
Browse files
just formatting
parent
cef8f1a5
Changes
5
Show whitespace changes
Inline
Side-by-side
java/7-mvc/triangle/Main1.java
View file @
fb689418
...
@@ -5,7 +5,9 @@ import model.TriangleModel;
...
@@ -5,7 +5,9 @@ import model.TriangleModel;
public
class
Main1
{
public
class
Main1
{
public
static
void
main
(
String
[]
args
)
{
public
static
void
main
(
String
[]
args
)
{
TriangleModel
model
=
new
TriangleModel
();
TriangleModel
model
=
new
TriangleModel
();
view
.
SimpleTextView
view
=
new
view
.
SimpleTextView
(
model
);
view
.
SimpleTextView
view
=
new
view
.
SimpleTextView
(
model
);
JFrame
frame
=
new
JFrame
(
"Triangle Main1"
);
JFrame
frame
=
new
JFrame
(
"Triangle Main1"
);
...
...
java/7-mvc/triangle/model/TriangleModel.java
View file @
fb689418
...
@@ -6,19 +6,20 @@ import javax.swing.undo.AbstractUndoableEdit;
...
@@ -6,19 +6,20 @@ import javax.swing.undo.AbstractUndoableEdit;
import
javax.swing.undo.UndoableEdit
;
import
javax.swing.undo.UndoableEdit
;
public
class
TriangleModel
{
public
class
TriangleModel
{
/* A list of the model's views. */
/* A list of the model's views. */
private
ArrayList
<
IView
>
views
=
new
ArrayList
<
IView
>();
private
ArrayList
<
IView
>
views
=
new
ArrayList
<
IView
>();
// Limit the size of the triangle.
// Limit the size of the triangle.
public
static
final
double
MAX_SIDE
=
100.0
;
public
static
final
double
MAX_SIDE
=
100.0
;
public
static
final
double
MAX_HYPO
=
Math
.
sqrt
(
MAX_SIDE
*
MAX_SIDE
+
MAX_SIDE
*
MAX_SIDE
);
public
static
final
double
MAX_HYPO
=
Math
.
sqrt
(
MAX_SIDE
*
MAX_SIDE
+
MAX_SIDE
*
MAX_SIDE
);
private
double
base
=
50.0
;
// length of the base
private
double
base
=
50.0
;
// length of the base
private
double
height
=
50.0
;
// height of the triangle
private
double
height
=
50.0
;
// height of the triangle
public
TriangleModel
()
{
}
public
TriangleModel
()
{
}
/** Set the base to a new value. Must be between 0 and MAX_BASE. */
/** Set the base to a new value. Must be between 0 and MAX_BASE. */
public
void
setBase
(
double
theBase
)
{
public
void
setBase
(
double
theBase
)
{
double
tmp
=
Math
.
max
(
0
,
theBase
);
double
tmp
=
Math
.
max
(
0
,
theBase
);
...
...
java/7-mvc/triangle/view/GraphicalView.java
View file @
fb689418
...
@@ -17,9 +17,7 @@ public class GraphicalView extends JComponent {
...
@@ -17,9 +17,7 @@ public class GraphicalView extends JComponent {
private
double
scale
=
1.0
;
// how much should the triangle be scaled?
private
double
scale
=
1.0
;
// how much should the triangle be scaled?
private
int
handleSize
=
5
;
private
int
handleSize
=
5
;
// size of selectable square for dragging
// To format numbers consistently in the text fields.
// To format numbers consistently in the text fields.
private
static
final
NumberFormat
formatter
=
NumberFormat
private
static
final
NumberFormat
formatter
=
NumberFormat
...
@@ -51,7 +49,7 @@ public class GraphicalView extends JComponent {
...
@@ -51,7 +49,7 @@ public class GraphicalView extends JComponent {
this
.
addMouseMotionListener
(
mil
);
this
.
addMouseMotionListener
(
mil
);
}
}
/** Paint the triangle
, and
"handle
s
" for resizing
if it was selected.
*/
/** Paint the triangle
with
"handle" for resizing */
public
void
paintComponent
(
Graphics
g
)
{
public
void
paintComponent
(
Graphics
g
)
{
super
.
paintComponent
(
g
);
super
.
paintComponent
(
g
);
Insets
insets
=
this
.
getInsets
();
Insets
insets
=
this
.
getInsets
();
...
@@ -130,9 +128,9 @@ public class GraphicalView extends JComponent {
...
@@ -130,9 +128,9 @@ public class GraphicalView extends JComponent {
selected
=
onTopCorner
(
e
.
getX
(),
e
.
getY
());
selected
=
onTopCorner
(
e
.
getX
(),
e
.
getY
());
}
}
public
void
mouseReleased
(
MouseEvent
e
)
{
//
public void mouseReleased(MouseEvent e) {
selected
=
onTopCorner
(
e
.
getX
(),
e
.
getY
());
//
selected = onTopCorner(e.getX(), e.getY());
}
//
}
/** The user is dragging the mouse. Resize appropriately. */
/** The user is dragging the mouse. Resize appropriately. */
public
void
mouseDragged
(
MouseEvent
e
)
{
public
void
mouseDragged
(
MouseEvent
e
)
{
...
...
java/7-mvc/triangle/view/SimpleTextView.java
View file @
fb689418
...
@@ -17,7 +17,9 @@ import java.text.NumberFormat;
...
@@ -17,7 +17,9 @@ import java.text.NumberFormat;
* @author Byron Weber Becker
* @author Byron Weber Becker
*/
*/
public
class
SimpleTextView
extends
JPanel
implements
IView
{
public
class
SimpleTextView
extends
JPanel
implements
IView
{
private
TriangleModel
model
;
private
TriangleModel
model
;
private
JTextField
baseTF
=
new
JTextField
(
10
);
private
JTextField
baseTF
=
new
JTextField
(
10
);
private
JTextField
heightTF
=
new
JTextField
(
10
);
private
JTextField
heightTF
=
new
JTextField
(
10
);
private
JTextField
hypoTF
=
new
JTextField
(
10
);
private
JTextField
hypoTF
=
new
JTextField
(
10
);
...
...
java/7-mvc/triangle/view/TextView.java
View file @
fb689418
...
@@ -13,7 +13,9 @@ import java.text.NumberFormat;
...
@@ -13,7 +13,9 @@ import java.text.NumberFormat;
* @author Byron Weber Becker
* @author Byron Weber Becker
*/
*/
public
class
TextView
extends
JPanel
{
public
class
TextView
extends
JPanel
{
private
TriangleModel
model
;
private
TriangleModel
model
;
private
JTextField
baseTF
=
new
JTextField
(
10
);
private
JTextField
baseTF
=
new
JTextField
(
10
);
private
JTextField
heightTF
=
new
JTextField
(
10
);
private
JTextField
heightTF
=
new
JTextField
(
10
);
private
JTextField
hypoTF
=
new
JTextField
(
10
);
private
JTextField
hypoTF
=
new
JTextField
(
10
);
...
@@ -37,6 +39,7 @@ public class TextView extends JPanel {
...
@@ -37,6 +39,7 @@ public class TextView extends JPanel {
heightTF
.
setText
(
formatter
.
format
(
model
.
getHeight
()));
heightTF
.
setText
(
formatter
.
format
(
model
.
getHeight
()));
}
}
});
});
this
.
model
.
addView
(
new
IView
()
{
this
.
model
.
addView
(
new
IView
()
{
public
void
updateView
()
{
public
void
updateView
()
{
hypoTF
.
setText
(
formatter
.
format
(
model
.
getHypotenuse
()));
hypoTF
.
setText
(
formatter
.
format
(
model
.
getHypotenuse
()));
...
@@ -54,8 +57,8 @@ public class TextView extends JPanel {
...
@@ -54,8 +57,8 @@ public class TextView extends JPanel {
this
.
add
(
this
.
hypoTF
);
this
.
add
(
this
.
hypoTF
);
// Don't allow the user to edit the hypotenuse
// Don't allow the user to edit the hypotenuse
this
.
hypoTF
.
setEditable
(
false
);
this
.
hypoTF
.
setEditable
(
false
);
// can still select and copy
//this.hypoTF.setEnabled(false);
//this.hypoTF.setEnabled(false);
// greyed out, can't select
}
}
private
void
registerControllers
()
{
private
void
registerControllers
()
{
...
...
Write
Preview
Supports
Markdown
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