-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGui.rb
71 lines (57 loc) · 1.62 KB
/
Gui.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
include Java
import javax.swing.JButton
import javax.swing.JFrame
import javax.swing.JPanel
import java.awt.Color
class Gui < JFrame
attr_accessor :used
def initialize
super "Tooltips"
@buttons = []
@used = false
self.initUI
end
def initUI
panel = JPanel.new
self.getContentPane.add panel
panel.setLayout nil
panel.setToolTipText "A Panel container"
(0..7).each do |i|
@buttons[i]=[]
(0..7).each do |j|
button = JButton.new "-"
button.setBounds(i*50, j*50, 50,50)
button.setToolTipText "A button component"
# button.setBackground(Color.new(0,0,0))
@buttons[i][j]=button
panel.add button
end
end
self.setDefaultCloseOperation JFrame::EXIT_ON_CLOSE
self.setSize 450, 450
self.setLocationRelativeTo nil
self.setVisible true
end
def draw board
# puts board
(0..7).each do |i|
(0..7).each do |j|
piece = board[i*8 + j]
# puts piece
if piece != '-'
# puts piece
@buttons[i][j].setText piece.split('_')[1]
if piece.split('_')[0] == 'W'
@buttons[i][j].setBackground(Color.new(255,255,255))
else
@buttons[i][j].setBackground(Color.new(0,0,0))
end
else
@buttons[i][j].setText '-'
@buttons[i][j].setBackground(Color.new(100,100,100))
end
end
end
end
end
# Gui.new