|
1 | 1 | package view.components
|
2 | 2 |
|
| 3 | +import ice1000.average |
3 | 4 | import java.awt.BorderLayout
|
4 | 5 | import java.awt.Component
|
| 6 | +import java.io.File |
| 7 | +import javax.swing.JButton |
| 8 | +import javax.swing.JFileChooser |
5 | 9 | import javax.swing.JFrame
|
| 10 | +import javax.swing.filechooser.FileNameExtensionFilter |
6 | 11 |
|
7 | 12 | /**
|
8 | 13 | * @author ice1000
|
9 | 14 | * Created by ice1000 on 2016/8/8.
|
10 | 15 | */
|
11 | 16 |
|
12 |
| -class Frame666(title: String) : JFrame(title) { |
| 17 | +class Frame666(title: String, setupFrame: () -> Unit, changeGraph: (File) -> Unit) : JFrame(title) { |
13 | 18 |
|
14 | 19 | var spaceHeight = 0
|
15 | 20 | var spaceWidth = 0
|
16 | 21 |
|
| 22 | + init { |
| 23 | + layout = BorderLayout() |
| 24 | + |
| 25 | + val chooserButton = JButton("Open File") |
| 26 | + |
| 27 | + chooserButton.addActionListener { action -> |
| 28 | + |
| 29 | + val chooser = JFileChooser() |
| 30 | + chooser.fileSelectionMode = JFileChooser.FILES_ONLY |
| 31 | + chooser.fileFilter = FileNameExtensionFilter("Supported Image Format", "png", "jpg") |
| 32 | + |
| 33 | + if (chooser.showOpenDialog(chooser) == JFileChooser.APPROVE_OPTION) { |
| 34 | + changeGraph(chooser.selectedFile) |
| 35 | + setupFrame() |
| 36 | + } |
| 37 | + } |
| 38 | + add(chooserButton, BorderLayout.SOUTH) |
| 39 | + |
| 40 | + fun manageAverage(number: Int) { |
| 41 | + average += number |
| 42 | + if (average > 0b11111111) average = 0b11111111 |
| 43 | + if (average < 0b0) average = 0b0 |
| 44 | + println(average) |
| 45 | + setupFrame() |
| 46 | + } |
| 47 | + |
| 48 | + val plusButton = JButton("+\n+\n+") |
| 49 | + plusButton.addActionListener { action -> manageAverage(5) } |
| 50 | + add(plusButton, BorderLayout.WEST) |
| 51 | + |
| 52 | + val minusButton = JButton("-\n-\n-") |
| 53 | + minusButton.addActionListener { action -> manageAverage(-5) } |
| 54 | + add(minusButton, BorderLayout.EAST) |
| 55 | + |
| 56 | + defaultCloseOperation = JFrame.EXIT_ON_CLOSE |
| 57 | + isResizable = false |
| 58 | + } |
| 59 | + |
17 | 60 | override fun add(comp: Component, constraints: Any?) {
|
18 | 61 | super.add(comp, constraints)
|
19 | 62 | when (constraints) {
|
|
0 commit comments