当前位置: 首页>>代码示例>>Scala>>正文


Scala ActionEvent类代码示例

本文整理汇总了Scala中java.awt.event.ActionEvent的典型用法代码示例。如果您正苦于以下问题:Scala ActionEvent类的具体用法?Scala ActionEvent怎么用?Scala ActionEvent使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了ActionEvent类的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Scala代码示例。

示例1: TrayIcon

//设置package包名称以及导入依赖的类
package se.gigurra.dcs.remote

import java.awt
import java.awt._
import java.awt.event.{ActionEvent, ActionListener}
import javax.swing.ImageIcon

import se.gigurra.serviceutils.twitter.logging.Logging

case class TrayIcon(exitCallback: () => Unit) {

  val base = createImage("tray_icons/base.png", "base")
  val popup = new PopupMenu()
  val trayIcon = new awt.TrayIcon(base)
  val tray = SystemTray.getSystemTray
  val exitItem = new MenuItem("Exit")
  exitItem.addActionListener(new ActionListener { override def actionPerformed(e: ActionEvent): Unit = exitCallback() })

  trayIcon.setToolTip("DCS-Remote REST Proxy")
  popup.add(exitItem)
  trayIcon.setPopupMenu(popup)
  tray.add(trayIcon)

  def createImage(path: String, description: String): Image = {
    val imageURL = getClass.getClassLoader.getResource(path)
    if (imageURL == null) {
      throw new RuntimeException("Resource not found: " + path)
    } else {
      new ImageIcon(imageURL, description).getImage
    }
  }

}

object TrayIcon extends Logging{

  def setup(): Option[TrayIcon] = {
    SystemTray.isSupported match {
      case true =>
        logger.info("Tray icon supported! Setting up tray icon..")
        Some(TrayIcon(() => System.exit(0)))
      case false =>
        logger.info("Tray icon not supported!")
        None
    }
  }
} 
开发者ID:GiGurra,项目名称:dcs-remote2,代码行数:48,代码来源:TrayIcon.scala

示例2: ClustersDriver

//设置package包名称以及导入依赖的类
package sryza

import java.awt.Cursor
import java.awt.event.{ActionEvent, ActionListener}
import javax.swing._

object ClustersDriver {
  def main(args: Array[String]): Unit = {
    val splashIcon = new ImageIcon(getClass.getResource("/splash.png"))
    JOptionPane.showMessageDialog(null, "", "Clusters", JOptionPane.INFORMATION_MESSAGE, splashIcon)

    val cluster = new Cluster()
    val rootPanel = new RootPanel(cluster)

    val menuBar = new JMenuBar()
    val menu = new JMenu("Help")
    menuBar.add(menu)
    val menuItem = new JMenuItem("About")
    menuItem.addActionListener(new ActionListener {
      override def actionPerformed(e: ActionEvent): Unit = {
        JOptionPane.showMessageDialog(null,
          "Clusters is an artificial life computer program.  Gameplay focuses on raising alien\n" +
          "creatures known as Nodes.  Nodes mate, pass on their genes, get sick, execute\n" +
          "queries.")
      }
    })
    menu.add(menuItem)

    val timer = new Timer(50, new ActionListener() {
      override def actionPerformed(event: ActionEvent) = {
        cluster.gameStep()
        rootPanel.nodesPanel.repaint()
        rootPanel.statsPanel.updateStats(cluster)
        rootPanel.nodeStatsPanel.updateSelectedNode(rootPanel.nodesPanel.selectedNode)
        rootPanel.queryPanel.updateQuery()
      }
    })
    timer.start()

    val frame = new JFrame()
    frame.setJMenuBar(menuBar)
    frame.setTitle("Clusters")
    frame.setCursor(Cursor.HAND_CURSOR)
    frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE)
    frame.setContentPane(rootPanel)
    frame.pack()
    frame.setVisible(true)
  }
} 
开发者ID:sryza,项目名称:clusters,代码行数:50,代码来源:ClustersDriver.scala

示例3: occurred

//设置package包名称以及导入依赖的类
// Version 1: The event source is an Object

import scala.collection.mutable.ArrayBuffer
import java.awt.event.ActionEvent

trait Listener[E] {
  def occurred(e: E): Unit
}

trait Source[E, L <: Listener[E]] {
  private val listeners = new ArrayBuffer[L]
  def add(l: L) { listeners += l }
  def remove(l: L) { listeners -= l }
  def fire(e: E) {
    for (l <- listeners) l.occurred(e)
  }
}

trait ActionListener extends Listener[ActionEvent]

class Button extends Source[ActionEvent, ActionListener] {
  def click() {
    fire(new ActionEvent(this, ActionEvent.ACTION_PERFORMED, "click"))
  }
}

object Main extends App {
  val b = new Button
  b.add(new ActionListener {
    def occurred(e: ActionEvent) {
      println(e)
    }
  })
  b.click()
} 
开发者ID:yeahnoob,项目名称:scala-impatient-2e-code,代码行数:36,代码来源:Listeners1.scala

示例4: TrayAdapter

//设置package包名称以及导入依赖的类
package ch.thomsch.pause

import java.awt._
import java.awt.event.{ActionEvent, ActionListener}

import scalafx.stage.Stage


object TrayAdapter {
  val image : Image  = Toolkit.getDefaultToolkit.getImage(getClass.getResource("/icon-tray.png"))

  var trayMenu = new PopupMenu
  val trayIcon : TrayIcon  = new TrayIcon(image, "Pause", trayMenu)
  var stage : Stage = null
  val tray : SystemTray = SystemTray.getSystemTray

  def initialize(): Unit = {
    val exit: MenuItem = new MenuItem("Exit")
    val controls: MenuItem = new MenuItem("Settings...")
    controls.setFont(Font.decode(null).deriveFont(Font.BOLD))

    trayMenu.add(controls)
    trayMenu.addSeparator()
    trayMenu.add(exit)

    val listener : ActionListener= new ActionListener() {
      def actionPerformed(arg0 : ActionEvent ) {
        Actions.closeApplication()
      }
    }

    val settingsListener : ActionListener = new ActionListener {
      override def actionPerformed(e: ActionEvent) : Unit = {
        if(Pause.stage.isShowing) Pause.hide else Pause.show
      }
    }

    trayIcon.addActionListener(settingsListener)
    controls.addActionListener(settingsListener)
    exit.addActionListener(listener)

    tray.add(trayIcon)
  }

  def removeIcon(): Unit = {
    tray.remove(trayIcon)
  }

  def displayNotification(message : String): Unit = {
    trayIcon.displayMessage("", message, TrayIcon.MessageType.INFO)
  }

} 
开发者ID:Thomsch,项目名称:pause,代码行数:54,代码来源:TrayAdapter.scala

示例5: Editor

//设置package包名称以及导入依赖的类
package mur

import java.awt.event.{ActionEvent, ActionListener}
import akka.actor.ActorSystem
import com.typesafe.config.ConfigFactory
import scala.swing._
import scala.swing.event._

object Editor extends SimpleSwingApplication {
  val config = ConfigFactory.load
  val input = new TextArea(Main.text)
  val output = new TextArea("[0] No errors\n")
  val actorSystem = ActorSystem("mur-editor")
  val workers = actorSystem.actorOf(props = Worker.settings, name = "worker")

  def top = new MainFrame {
    title = "MuR Editor"
    preferredSize = new Dimension(
      config.getInt("gui.window-width"),
      config.getInt("gui.window-height")
    )
    contents = new BoxPanel(Orientation.Vertical) {
      contents += new ScrollPane(input)
      contents += new ScrollPane(output)
    }
    listenTo(input.keys)

    val timerListener = new ActionListener {
      override def actionPerformed(actionEvent: ActionEvent) = {
        workers ! NewInput(input.peer.getText)
      }
    }
    val timer = new javax.swing.Timer(config.getInt("gui.processing-delay"), timerListener)
    timer.setRepeats(false)
    reactions += {
      case _: KeyTyped => timer.restart()
    }
  }

  override def shutdown(): Unit = {
    actorSystem.stop(workers)
    actorSystem.terminate()
  }
} 
开发者ID:MaxGekk,项目名称:mur,代码行数:45,代码来源:Editor.scala

示例6: SAM

//设置package包名称以及导入依赖的类
import java.awt.event.{ActionEvent, ActionListener}
import javax.swing.{JButton, _}

object SAM {
  def main(args: Array[String]) {
    var data = 0
    val jFrame = new JFrame("SAM Testing")
    val jButton = new JButton("counter")
    jButton.addActionListener(new ActionListener {
      override def actionPerformed(e: ActionEvent): Unit ={
        data += 1
        println(data)
      }
    })

    implicit def convertedAction(action: (ActionEvent) => Unit) =
      new ActionListener {
        override def actionPerformed(e: ActionEvent){ action(e)}
      }

    //SAM simple abstract method??,?????????,??????????????
    jButton.addActionListener((event:ActionEvent) => {data += 1; println(data)})

    jFrame.setContentPane(jButton)
    jFrame.pack()
    jFrame.setVisible(true)

  }
} 
开发者ID:WeiLi1201,项目名称:ProgrammingNote,代码行数:30,代码来源:SAM.scala

示例7: OpenProfileDialog

//设置package包名称以及导入依赖的类
package aug.gui

import java.awt.event.{ActionEvent, ActionListener}
import java.awt.{Dialog, Dimension, FlowLayout}
import javax.swing._

import aug.profile.ConfigManager

class OpenProfileDialog(mainWindow: MainWindow) extends
  JDialog(mainWindow, "Open Profile", Dialog.ModalityType.DOCUMENT_MODAL) {

  setSize(300, 180)
  setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE)
  setLocationRelativeTo(mainWindow)

  setLayout(new BoxLayout(getContentPane, BoxLayout.Y_AXIS))

  private val profiles: Array[String] = ConfigManager.getUnactivedProfiles.toArray
  val comboBox = new JComboBox[String](profiles)
  val cancelButton = new JButton("cancel")
  val openButton = new JButton("open")

  val flowPanel = new JPanel()
  flowPanel.setLayout(new FlowLayout())
  flowPanel.add(cancelButton)
  flowPanel.add(openButton)

  if(profiles.isEmpty) openButton.setEnabled(false)

  getRootPane.setDefaultButton(openButton)
  getRootPane.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10))

  comboBox.setMaximumSize(comboBox.getPreferredSize)

  add(comboBox)
  add(Box.createRigidArea(new Dimension(0, 10)))
  add(flowPanel)

  pack()

  cancelButton.addActionListener(new ActionListener {
    override def actionPerformed(e: ActionEvent): Unit = setVisible(false)
  })

  openButton.addActionListener(new ActionListener {
    override def actionPerformed(e: ActionEvent): Unit = {
      ConfigManager.activateProfile(comboBox.getSelectedItem.toString, mainWindow)
      setVisible(false)
    }
  })

  setVisible(true)
} 
开发者ID:austinmiller,项目名称:augustmc,代码行数:54,代码来源:OpenProfileDialog.scala


注:本文中的java.awt.event.ActionEvent类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。