本文整理汇总了Scala中javax.swing.JPanel类的典型用法代码示例。如果您正苦于以下问题:Scala JPanel类的具体用法?Scala JPanel怎么用?Scala JPanel使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了JPanel类的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Scala代码示例。
示例1: MNISTVisualizer
//设置package包名称以及导入依赖的类
package org.dl4scala.examples.feedforward.anomalydetection
import java.awt.{GridLayout, Image}
import java.awt.image.BufferedImage
import javax.swing.{ImageIcon, JFrame, JLabel, JPanel}
import org.nd4j.linalg.api.ndarray.INDArray
import scala.collection.mutable.ArrayBuffer
class MNISTVisualizer(imageScale: Double, digits: ArrayBuffer[INDArray], title: String, gridWidth: Int) {
def this(imageScale: Double, digits: ArrayBuffer[INDArray], title: String) = {
this(imageScale, digits, title, 5)
}
def visualize(): Unit = {
val frame = new JFrame
frame.setTitle(title)
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE)
val panel = new JPanel
panel.setLayout(new GridLayout(0, gridWidth))
val list = getComponents
for (image <- list) {
panel.add(image)
}
frame.add(panel)
frame.setVisible(true)
frame.pack()
}
def getComponents: ArrayBuffer[JLabel] = {
val images = new ArrayBuffer[JLabel]()
for (arr <- digits) {
val bi = new BufferedImage(28, 28, BufferedImage.TYPE_BYTE_GRAY)
for(i <- 0 until 784) {
bi.getRaster.setSample(i % 28, i / 28, 0, (255 * arr.getDouble(i)).asInstanceOf[Int])
}
val orig = new ImageIcon(bi)
val imageScaled = orig.getImage.getScaledInstance((imageScale * 28).asInstanceOf[Int],
(imageScale * 28).asInstanceOf[Int], Image.SCALE_REPLICATE)
val scaled = new ImageIcon(imageScaled)
images.append(new JLabel(scaled))
}
images
}
}
示例2: ResultPanel
//设置package包名称以及导入依赖的类
package ui.premiseView
import java.awt.BorderLayout
import javax.swing.{JPanel, JTabbedPane}
import compiler.Parser
class ResultPanel(expression: String) extends JPanel {
private val tokens = Parser.tokenizer(expression)
private val ast = Parser.generateAST(tokens)
private val tabbedPane = new JTabbedPane
private val graphPanel = new GraphTab(ast, tokens)
private val tokensPanel = new TokensTab(tokens)
private val truthTablePanel = new TruthTableTab(ast, tokens)
start
private def start = {
setLayout(new BorderLayout())
tabbedPane.add("Expression Graph", graphPanel)
tabbedPane.add("Expression Tokens", tokensPanel)
tabbedPane.add("Truth Table", truthTablePanel)
this.add(tabbedPane, BorderLayout.CENTER)
}
}
示例3: TokensTab
//设置package包名称以及导入依赖的类
package ui.premiseView
import java.awt.{BorderLayout, FlowLayout}
import javax.swing.table.AbstractTableModel
import javax.swing.{JLabel, JPanel, JScrollPane, JTable}
import structure._
class TokensTab(tokens: List[Token]) extends JPanel {
private val statusBar = new JPanel(new FlowLayout(FlowLayout.LEFT))
start
draw
private def start = {
setLayout(new BorderLayout())
}
private def draw: Unit = {
val dataModel = new AbstractTableModel() {
private val _tokens = tokens
override def getColumnName(i: Int): String = {
i match {
case 0 => "Category"
case 1 => "Value"
}
}
def getColumnCount: Int = 2
def getRowCount: Int = _tokens.size
def getValueAt(row: Int, col: Int): Object = {
col match {
case 0 => _tokens.lift(row).get.category
case 1 => _tokens.lift(row).get.value
}
}
}
val table = new JTable(dataModel)
add(new JScrollPane(table), BorderLayout.CENTER)
statusBar.add(new JLabel(s"Total: ${tokens.size}"))
add(statusBar, BorderLayout.SOUTH)
}
}
示例4: Scatter3D
//设置package包名称以及导入依赖的类
import java.awt.Color
import javax.swing.{JFrame, JPanel, WindowConstants}
import org.math.plot._
object Scatter3D {
def loadDataFromCSV(csvPath: String): JPanel = {
val data = scala.io.Source.fromFile(csvPath).getLines().map(_.split(",").map(_.trim.toDouble).toSeq)
val (x, y, z) = (data map {
case Seq(x_, y_, z_) => (x_, y_, z_)
}).toArray.unzip3
val colors = z map (x => new Color(Color.HSBtoRGB(x.toFloat, 1.0f, 0.5f)))
val plot = new Plot3DPanel()
plot.addScatterPlot("Fractal in 3D", colors, x, y, z)
plot
}
def main(args: Array[String]): Unit = {
val plot = loadDataFromCSV(args.headOption.getOrElse("D:/Programming/Projects/FractalGenerator/output.csv"))
val frame = new JFrame("Fractal3D")
frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE)
frame.setSize(900, 900)
frame.setContentPane(plot)
frame.setVisible(true)
}
}
示例5: PointPanel
//设置package包名称以及导入依赖的类
package com.ganchurin.view
import java.awt.geom.Rectangle2D
import java.awt.{Color, Graphics2D}
import javax.swing.JPanel
class PointPanel(width: Int, height: Int, cellSize: Int, gridSize: Int) extends JPanel {
def initRectangles(): Unit = {
val rectangles = for {
i <- 0 until width by (cellSize + gridSize)
j <- 0 until height by (cellSize + gridSize)
} yield new Rectangle2D.Double(i, j, cellSize, cellSize)
clearRectangles(rectangles)
}
def paintRectangles(rectangles: Seq[Rectangle2D.Double]): Unit = {
fillRectangles(rectangles, Color.BLACK)
}
def clearRectangles(rectangles: Seq[Rectangle2D.Double]): Unit = {
fillRectangles(rectangles, Color.WHITE)
}
private def fillRectangles(rectangles: Seq[Rectangle2D.Double], color: Color) {
val g = getGraphics
val g2d = g.asInstanceOf[Graphics2D]
g2d setColor color
rectangles foreach g2d.fill
}
}
示例6: Window
//设置package包名称以及导入依赖的类
import java.awt.BorderLayout
import java.awt.BorderLayout.{CENTER, PAGE_END, PAGE_START}
import javax.swing.JFrame.EXIT_ON_CLOSE
import javax.swing.{JFrame, ImageIcon, JLabel, JPanel, BorderFactory}
class Window extends JFrame with StatusChangeCallback {
private val instructions = "<html><br>'m' - Exit<br>'z' - Start<br>'x' - Stop<br>'p' - Play/Pause</html>"
private val icon = new ImageIcon("src/main/resources/mch.png")
private val lblLogo = new JLabel(icon)
private val lblStatus = new JLabel("Waiting")
private val panel = new JPanel()
private val lblInstructions = new JLabel(instructions)
setDefaultCloseOperation(EXIT_ON_CLOSE)
setTitle("MyClickHolder")
setResizable(false)
setIconImage(icon.getImage)
panel.setLayout(new BorderLayout())
panel.setBorder(BorderFactory.createEmptyBorder(50, 50, 50, 50))
panel.add(lblLogo, PAGE_START)
panel.add(lblStatus, CENTER)
panel.add(lblInstructions, PAGE_END)
add(panel)
pack()
setVisible(true)
override def statusChanged(status: String): Unit = {
lblStatus.setText(status)
}
override def engineExit(): Unit = {
System.exit(0)
}
}
示例7: MongoConfigPanel
//设置package包名称以及导入依赖的类
package aug.gui.settings
import java.awt.GridBagConstraints
import javax.swing.{JLabel, JPanel}
class MongoConfigPanel(profileConfigPanel: ProfileConfigPanel) extends GridPanel {
private val txtWidth = 90
private val fieldWeight = 6
val enabledBox = new EnabledBox(profileConfigPanel.setDirty())
val userField = new RegexTextField("^.{1,60}", txtWidth, () => profileConfigPanel.setDirty())
val passField = new PasswordField(txtWidth, profileConfigPanel.setDirty())
val dbField = new RegexTextField("^.{1,60}", txtWidth, () => profileConfigPanel.setDirty())
val hostField = new RegexTextField("^.{1,100}", txtWidth, () => profileConfigPanel.setDirty())
c.fill = GridBagConstraints.HORIZONTAL
margins(bot = 20)
addToGrid(enabledBox, 0, 0, 1, 1, 2, 1)
margins()
addToGrid(new JLabel("user"), 0, 1)
addToGrid(userField, 1, 1, fieldWeight)
margins(left = 20)
addToGrid(new JLabel("password"), 2, 1)
margins()
addToGrid(passField, 3, 1, fieldWeight)
addToGrid(new JLabel("database"), 0, 2)
addToGrid(dbField, 1, 2, fieldWeight)
margins(left = 20)
addToGrid(new JLabel("host"), 2, 2)
margins()
addToGrid(hostField, 3, 2, fieldWeight)
addToGrid(new JPanel(), 0, 3, 100, 100, 4, 1)
setMargin(10)
}
示例8: SystemPanel
//设置package包名称以及导入依赖的类
package aug.gui
import java.awt._
import javax.swing.border.EmptyBorder
import javax.swing.{JPanel, JTabbedPane}
import aug.profile.ProfileConfig
import aug.util.Util
import com.bulenkov.darcula.ui.DarculaTabbedPaneUI
class SystemPanel(mainWindow: MainWindow) extends JPanel with HasHighlight {
setLayout(new GridLayout(1, 1))
val textArea = new SplittableTextArea(ProfileConfig(""), this)
val text: Text = textArea.text
textArea.setActiveFont(Util.defaultFont)
add(textArea)
setBorder(new EmptyBorder(0, 0, 0, 0))
}
class TabbedPane(mainWindow: MainWindow) extends JTabbedPane {
setUI(new DarculaTabbedPaneUI() {
override def paintFocusIndicator(g: Graphics, tabPlacement: Int, rects: Array[Rectangle], tabIndex: Int,
iconRect: Rectangle, textRect: Rectangle, isSelected: Boolean): Unit = {}
})
def active : Option[ProfilePanel] = {
val c = getComponentAt(getSelectedIndex)
c match {
case panel: ProfilePanel => Some(panel)
case _ => None
}
}
def addProfile(name: String, profilePanel: ProfilePanel): Unit = {
addTab(name, profilePanel)
setSelectedComponent(profilePanel)
}
}
示例9: ProfilePanel
//设置package包名称以及导入依赖的类
package aug.gui
import java.awt.event.{ComponentEvent, ComponentListener}
import java.awt.{Component, GridLayout}
import javax.swing.border.EmptyBorder
import javax.swing.{JPanel, SpringLayout}
import aug.profile.{Profile, ProfileConfig}
class ProfilePanel(val mainWindow: MainWindow, val profile: Profile) extends JPanel with HasHighlight {
private val springLayout = new SpringLayout
private val container = new JPanel
container.setLayout(new GridLayout(1, 1))
val commandLine = new CommandLine(profile)
setLayout(springLayout)
add(container)
add(commandLine)
setBorder(new EmptyBorder(0, 0, 0, 0))
springLayout.putConstraint(SpringLayout.WEST, container, 0, SpringLayout.WEST, this)
springLayout.putConstraint(SpringLayout.NORTH, container, 0, SpringLayout.NORTH, this)
springLayout.putConstraint(SpringLayout.EAST, container, 0, SpringLayout.EAST, this)
springLayout.putConstraint(SpringLayout.WEST, commandLine, 0, SpringLayout.WEST, this)
springLayout.putConstraint(SpringLayout.SOUTH, commandLine, 0, SpringLayout.SOUTH, this)
springLayout.putConstraint(SpringLayout.EAST, commandLine, 0, SpringLayout.EAST, this)
springLayout.putConstraint(SpringLayout.SOUTH, container, 0, SpringLayout.NORTH, commandLine)
def setContents(component: Component): Unit = {
container.removeAll()
container.add(component)
container.revalidate()
}
def setProfileConfig(profileConfig: ProfileConfig): Unit = {
commandLine.setFont(profileConfig.commandLineFont.toFont)
repaint()
}
override def copyText(): Unit = profile.copyText()
addComponentListener(new ComponentListener {
override def componentShown(e: ComponentEvent): Unit = commandLine.grabFocus()
override def componentHidden(e: ComponentEvent): Unit = {}
override def componentMoved(e: ComponentEvent): Unit = {}
override def componentResized(e: ComponentEvent): Unit = {}
})
}
示例10: Cell
//设置package包名称以及导入依赖的类
package snake
import scala.swing._
import java.awt.Color
import javax.swing.border._
import javax.swing.JPanel
class Cell extends Panel {
override lazy val peer: JPanel = new JPanel with SuperMixin {
override def getMinimumSize = new Dimension(32, 32)
override def getPreferredSize = new Dimension(32, 32)
override def getMaximumSize = new Dimension(32, 32)
}
//border = new LineBorder(Color.GREEN)
var on: Boolean = false;
var food: Boolean = false;
setChanges
def setOnStatus(bool: Boolean) = {
on = bool
setChanges
}
def setFoodStatus(bool: Boolean) = {
food = bool
setChanges
}
def setChanges = {
if (on) {
background = Color.BLACK
} else if (food) {
background = Color.RED
} else {
background = Color.WHITE
}
this
}
override def toString(): String = {
if(on) "X" else "O"
}
}
示例11: Animation
//设置package包名称以及导入依赖的类
package view
import java.awt._
import java.awt.image.BufferedImage
import java.io.{File, IOException}
import javax.imageio.ImageIO
import javax.swing.JPanel
import data.Cfg
case class Animation(var dt: Double) extends JPanel {
val world = Cfg.world
def update(): Unit = {
val ti = System.currentTimeMillis()
world.advance(dt)
val elapsed = System.currentTimeMillis() - ti
val remTime = (dt * 1000).round - elapsed
if (remTime > 0) Thread.sleep(remTime)
}
override def paint(G: Graphics) {
val canvas = new BufferedImage(Cfg.frameWidth, Cfg.frameHeight, BufferedImage.TYPE_INT_RGB)
val g = canvas.createGraphics()
// g.scale(0.5,0.5)
g.setColor(Color.BLACK)
g.setRenderingHint(java.awt.RenderingHints.KEY_ANTIALIASING, java.awt.RenderingHints.VALUE_ANTIALIAS_ON)
g.fillRect(0, 0, canvas.getWidth, canvas.getHeight)
world.walls ++ world.orgs foreach (_.draw(g))
// println("asd")
g.dispose()
// javax.imageio.ImageIO.write(canvas, "png", new java.io.File("drawing.png"))
G.drawImage(canvas, 0, 0, this)
}
def createImage(): BufferedImage = {
try ImageIO.read(new File("drawing.png")) catch {
case e: IOException => e.printStackTrace()
}
null
}
}