Skip to content

Commit fa1f526

Browse files
committed
差不多了,把CUI的信息移植到GUI
1 parent f9f33a4 commit fa1f526

File tree

3 files changed

+16
-12
lines changed

3 files changed

+16
-12
lines changed

src/core/models/Graph.kt

+10-3
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,20 @@ class Graph(file: File) {
4141
}
4242
}
4343

44-
operator fun plusAssign(point: Point) {
45-
if (pointCache connect point) LogConsole.log("Yes!! Connected!!")
46-
else LogConsole.log("Not connected!!")
44+
/**
45+
* @param point send a clicked point
46+
* @return connected
47+
*/
48+
fun send(point: Point): Boolean {
49+
val ret = pointCache connect point
50+
// LogConsole.log("Yes!! Connected!!")
51+
// else
52+
// LogConsole.log("Not connected!!")
4753
val line = Line(pointCache, point)
4854
line.getAllPoints().forEach { p -> image.setRGB(p.x, p.y, Color.BLUE.rgb) }
4955
pointCache = point
5056
pointCache.getColor = getColor
57+
return ret
5158
}
5259

5360
/**

src/core/models/Point.kt

+1-6
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,7 @@ class Point(val x: Int, val y: Int, internal var getColor: (Int, Int) -> Boolean
2222
/** 判断两点是否连通 (。ŏ﹏ŏ) */
2323
infix fun connect(point: Point): Boolean {
2424
val line = Line(this, point)
25-
(Math.min(this.x, point.x)..Math.max(this.x, point.x)).forEach { x ->
26-
if (!getColor(x, line.f(x).toInt())) return false
27-
}
28-
(Math.min(this.y, point.y)..Math.max(this.y, point.y)).forEach { y ->
29-
if (!getColor(line.fa(y).toInt(), y)) return false
30-
}
25+
line.getAllPoints().forEach { p -> if (!getColor(p.x, p.y)) return false }
3126
return true
3227
}
3328

src/view/components/ImagePanel.kt

+5-3
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@ package view.components
22

33
import core.models.Graph
44
import core.models.Point
5-
import utils.debug.LogConsole
65
import java.awt.Graphics
76
import java.awt.event.MouseEvent
87
import java.awt.event.MouseListener
8+
import javax.swing.JOptionPane
99
import javax.swing.JPanel
1010

1111
/**
@@ -22,9 +22,11 @@ class ImagePanel(var graph: Graph) : JPanel() {
2222
override fun mousePressed(e: MouseEvent) = Unit
2323
override fun mouseClicked(e: MouseEvent) {
2424
graph.init()
25-
graph += Point(e.x, e.y)
25+
val connected = graph.send(Point(e.x, e.y))
2626
repaint()
27-
LogConsole.log("e.x = ${e.x}, e.y = ${e.y}")
27+
JOptionPane.showMessageDialog(null, if (connected) "Connected" else "Not Connected",
28+
"Information", JOptionPane.INFORMATION_MESSAGE)
29+
// LogConsole.log("e.x = ${e.x}, e.y = ${e.y}")
2830
}
2931
})
3032
}

0 commit comments

Comments
 (0)