package io.github.apollozhu.lottery import io.github.apollozhu.lottery.lottery.LotteryPanel import io.github.apollozhu.lottery.settings.LotteryPreferences import io.github.apollozhu.lottery.settings.LotterySettingsPanel import io.github.apollozhu.lottery.utils.BackgroundMusicPlayer import java.awt.Color import java.awt.Container import java.awt.GraphicsEnvironment import java.awt.Image import javax.swing.ImageIcon import javax.swing.JButton import javax.swing.JFrame import javax.swing.JTabbedPane private val settingsPanel = LotterySettingsPanel() val frame = JFrame("抽獎軟件(開源代碼 github.com/ApolloZhu/Lottery)") val tabbedPane = JTabbedPane() fun main(args: Array) { val lotteryPanel = LotteryPanel() tabbedPane.addTab("抽獎", lotteryPanel) LotteryPreferences.addListener { setBackgroundRecursively(container = lotteryPanel) } setBackgroundRecursively(container = lotteryPanel) tabbedPane.addTab("設置", settingsPanel) tabbedPane.selectedIndex = 1 frame.contentPane = tabbedPane frame.bounds = GraphicsEnvironment.getLocalGraphicsEnvironment().maximumWindowBounds frame.defaultCloseOperation = JFrame.EXIT_ON_CLOSE LotteryPreferences.addListener { frame.background = LotteryPreferences.backgroundColor } frame.background = LotteryPreferences.backgroundColor frame.isVisible = true BackgroundMusicPlayer.play(/*"/Users/Apollonian/Music/Music Converter/m.wav"*/) } fun setBackgroundRecursively(color: Color = LotteryPreferences.backgroundColor, container: Container) { for (component in container.components) { component.background = color if (component is Container) { setBackgroundRecursively(color, component) } } } fun imageAspectFit(image: Image, width: Int, height: Int): Image { val icon = ImageIcon(image) val isLongThin = icon.iconWidth < icon.iconHeight val toWidth = if (isLongThin) -1 else width val toHeight = if (isLongThin) height else -1 return image.getScaledInstance(toWidth, toHeight, Image.SCALE_DEFAULT) }