• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Scala Point类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: OrderedPoint

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

import java.awt.Point

class OrderedPoint(a: Int, b: Int) extends Point(a,b) with scala.math.Ordered[Point] {
  override def compare(that: Point): Int = {
    if (this.x <= that.x && this.y < that.y) - 1
    else if (this.x == that.x && this.y == that.y) 0
    else 1
  }
}

object Test02 extends App {
  val x1 = new OrderedPoint(1, 1)
  val x2 = new OrderedPoint(1, 2)
  val x3 = new OrderedPoint(2, 1)
  val x4 = new OrderedPoint(2, 1)

  assert(x1 < x2)
  assert(x3 > x2)
  assert(x4 == x3)
} 
开发者ID:johnnyqian,项目名称:scala-for-the-impatient,代码行数:23,代码来源:02.scala


示例2: addPropertyChangeListener

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

import java.beans.{PropertyChangeEvent, PropertyChangeListener, PropertyChangeSupport => JavaPropertyChangeSupport}
import java.awt.Point

trait PropertyChangeSupport {
  val pcs =  new JavaPropertyChangeSupport(this)

  def addPropertyChangeListener(listener: PropertyChangeListener): Unit = {
    pcs.addPropertyChangeListener(listener)
  }

  def removePropertyChangeListener(listener:PropertyChangeListener) {
    pcs.removePropertyChangeListener(listener)
  }

  def firePropertyChange(propertyName: String, oldValue:Any, newValue:Any) {
    pcs.firePropertyChange(propertyName, oldValue, newValue)
  }
}

class PropertyChangeSupportedPoint(a: Int = 0, b: Int = 0) extends Point(a, b) with PropertyChangeSupport {
  override def move(x: Int, y: Int): Unit = {
    val oldX = this.x
    val oldY = this.y

    super.move(x, y)

    if(oldX != x)
      firePropertyChange("x", oldX ,x)
    if(oldY != y)
      firePropertyChange("y", oldY ,y)
  }
}

object Test05 extends App {
  val p = new PropertyChangeSupportedPoint(1,2)
  p.addPropertyChangeListener(new PropertyChangeListener {
    override def propertyChange(evt: PropertyChangeEvent): Unit = {
      printf("%s: %s => %s\n", evt.getPropertyName, evt.getOldValue, evt.getNewValue)
    }
  })

  p.move(2,2)
  p.move(3,3)
  p.move(3,4)
} 
开发者ID:johnnyqian,项目名称:scala-for-the-impatient,代码行数:48,代码来源:05.scala


示例3: MnistRawData

//设置package包名称以及导入依赖的类
package woshilaiceshide.nnadl.mnist

import woshilaiceshide.nnadl._
import woshilaiceshide.nnadl.math._
import woshilaiceshide.nnadl.util.Utility._
import woshilaiceshide.nnadl.util.ArrayUtility._

import java.io._

final case class MnistRawData(images: Array[Matrix], labels: Array[Int]) {
  private[nnadl] def split(howmany: Int) = {
    val (i0, i1) = images.cut_at_point(howmany)
    val (l0, l1) = labels.cut_at_point(howmany)
    (MnistRawData(i0, l0), MnistRawData(i1, l1))
  }
}
final case class MnistRawDataSet(training_data: MnistRawData, validation_data: MnistRawData, test_data: MnistRawData)

final case class MnistRecord(image: Matrix, label: Int) {
  def save() = {

    import java.awt.Point
    import java.awt.image._
    import javax.imageio.ImageIO
    val reshaped = image.reshape(28, 28)
    val pixels = reshaped.toArray()
    val (w, h) = reshaped.dim
    val raster = Raster.createWritableRaster(new PixelInterleavedSampleModel(0, w, h, 1, 1920, Array(0)), new Point(0, 0))

    for (i <- w.range; j <- h.range) { raster.setSample(i, j, 0, pixels(i)(j)) }
    val jimage = new BufferedImage(w, h, BufferedImage.TYPE_BYTE_GRAY);
    jimage.setData(raster)
    val output = new File(label + "." + System.currentTimeMillis() + ".jpg")
    ImageIO.write(jimage, "jpg", output)
  }
}

object MnistRecord {

  def apply(nrecord: NRecord) = {
    new MnistRecord(nrecord.x, nrecord.y.column(0).find(1))
  }

}

final case class MnistDataSet(training_data: Array[NRecord], validation_data: Array[NRecord], test_data: Array[NRecord]) 
开发者ID:woshilaiceshide,项目名称:s-nnadl,代码行数:47,代码来源:api.scala


示例4: PositionalComparator

//设置package包名称以及导入依赖的类
package org.pdfextractor.algorithm.candidate.posorder

import java.awt.Point
import java.io.IOException

import org.pdfextractor.algorithm.candidate.Candidate
import org.pdfextractor.db.domain.dictionary.PaymentFieldType

import scala.collection._

object PositionalComparator extends Ordering[Candidate] {

  type field2Points = mutable.HashMap[PaymentFieldType, Seq[Point]]

  val nodes: mutable.HashMap[PaymentFieldType, Node] = mutable.HashMap.empty

  try {
    val map: field2Points = mutable.HashMap.empty // TODO!! IOHelper.getMapFromFile("locations.json");

    map.keySet.foreach((key: PaymentFieldType) => {
      map.get(key) match {
        case Some(locations: TraversableOnce[Point]) => {
          val node: Node = new Node(Horizontal, 0, A4WidthPx, 0, A4HeightPx)
          node.addLocations(locations)
          nodes.put(key, node)
        }
        case _ =>
      }
    })
  } catch {
    case ioe: IOException =>
      throw new RuntimeException("Unable to load location data", ioe)
  }

  def compare(o1: Candidate, o2: Candidate): Int = {
    require(o1.paymentFieldType == o2.paymentFieldType)
    nodes.get(o1.paymentFieldType) match {
      case Some(node) =>
        val minDepth = Math.min(node.getMaxDepthForLocation(o1),
          node.getMaxDepthForLocation(o2))
        node.getDataPointsAtLevelForLocation(o2, minDepth) - node
          .getDataPointsAtLevelForLocation(o1, minDepth)
      case None => 0
    }
  }

} 
开发者ID:kveskimae,项目名称:pdfalg,代码行数:48,代码来源:PositionalComparator.scala


示例5: IOHelperTest

//设置package包名称以及导入依赖的类
package org.pdfextractor.algorithm.io

import java.awt.Point

import org.pdfextractor.db.domain.dictionary.PaymentFieldType
import org.pdfextractor.db.domain.dictionary.PaymentFieldType._
import org.scalatest._

class IOHelperTest  extends FlatSpec with Matchers {

  "An IOHelper" should "find " in {
    val locationsMap: scala.collection.Map[PaymentFieldType, Seq[Point]] = getMapFromFile("locations.json");
    assert(Option(locationsMap).isDefined)
    assert(locationsMap.size > 0)
    assert(locationsMap.get(TOTAL).nonEmpty)
    assert(locationsMap(TOTAL).size > 0)
    assert(locationsMap.get(REFERENCE_NUMBER).nonEmpty)
    assert(locationsMap(REFERENCE_NUMBER).size > 0)
  }

} 
开发者ID:kveskimae,项目名称:pdfalg,代码行数:22,代码来源:IOHelperTest.scala


示例6: Chap6

//设置package包名称以及导入依赖的类
package com.eugene.impatience_scala

import java.awt.Point


object Chap6 extends App{

    println("***"+args.reverse.mkString(" "))
    println(Poker.Spade.toString)
    for( c <- RGB.values ) println("0x%06x: %s".format(c.id, c))

    object Conversions{
        def inchesToCentimeters(value:Double) = value*2.54
        def gallonsToLiters(value:Double) = value*3.78541178
        def milesToKilometers(value:Double) = value*1.609344
    }
    class UnitConversion(val factor:Double){
        def convert(value:Double) = factor*value
    }
    object InchesToCentimeters extends UnitConversion(2.54)
    object GallonsToLiters extends UnitConversion(3.78541178)
    object MilesToKilometers extends UnitConversion(1.609344)
//        object Origin extends Point{
//            override def getLocation:Point = super.getLocation
//        }
    class Point(x:Double, y:Double)
    object Point{
        def apply(x:Double, y:Double) = new Point(x, y)
    }
    object Poker extends Enumeration{
        type Poker = Value
        val Spade = Value("?")
        val Club = Value("?")
        val Heart = Value("?")
        val Diamond = Value("?")
        override def toString = Poker.values.mkString(" ")
        def isRed(card:Poker) = card==Heart || card==Diamond
    }
    object RGB extends Enumeration{
        val black = Value(0x000000, "Black")
        val red = Value(0xff0000, "Red")
        val green = Value(0x00ff00, "Green")
        val blue = Value(0x0000ff, "Blue")
        val yellow = Value(0xffff00, "Yellow")
        val magenta = Value(0xff00ff, "Magenta")
        val cyan = Value(0x00ffff, "Cyan")
        val white = Value(0xffffff, "White")
    }

} 
开发者ID:Ernestyj,项目名称:ScalaProj,代码行数:51,代码来源:Chap6.scala


示例7: Temp

//设置package包名称以及导入依赖的类
class Temp {
  import java.io.PrintWriter

  import scala.collection.immutable.TreeMap

  val simap = Map("A"->1,"B"->2)
  simap+("C"->3)
  import sys.process._
  import io.Source
  val name = "/program/test.txt"
  def revFile(name:String):Unit = {
    val linesRev = Source.fromFile(name).getLines().toArray.reverse
    val out = new PrintWriter(name)
    for (line <- linesRev){
      out.println(line)
    }
    out.close()

  }

  revFile(name)
  Source.fromFile(name).mkString.split("\\s+").filter(_.length>2).foreach(println _)
  import math.Ordered
  import java.awt.Point
  class OrderedPoint extends Point with Ordered[Point]{
    override def compare(that: Point): Int = {
      if (x == that.x){
        y - that.y
      }else{
        x - that.x
      }
    }
  }

  1+2 -> 10
} 
开发者ID:starqiu,项目名称:LearningScala,代码行数:37,代码来源:Temp.scala


示例8: Reading

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

import java.awt.{Rectangle, Dimension, Point}

import scala.io.StdIn.readLine

object Reading
{
  def readPassage =
  {
    println("Enter passage:")
    readLine()
  }

  def readPageNumber =
  {
    println("Enter page number:")
    readLine()
  }

  def bibleReadingTitleAnchor = new Rectangle(new Point(51, 129), new Dimension(921, 260))

  def bibleReadingTextAnchor = new Rectangle(new Point(51, 396), new Dimension(921, 320))
} 
开发者ID:ldeck,项目名称:churchscreen,代码行数:25,代码来源:Reading.scala


示例9: Exercise02

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

import java.awt.Point


object Exercise02 extends App {
  println("Chapter 10 Exercise 02")

  val points = Seq(new OrderedPoint(8, 1), new OrderedPoint(2, 9), new OrderedPoint(5, 1), new OrderedPoint(2, 4))
  println(points)
  println(points.sortBy(a => (a.getX, a.getY)))
  println(points(1) + " > " + points(3) + ": " + (points(1) > points(3)))
  println(points(0) + " < " + points(2) + ": " + (points(0) < points(2)))

  class OrderedPoint(x: Int, y: Int) extends Point(x: Int, y: Int) with Ordered[Point] {
    override def compare(that: Point): Int = {
      if (x < that.x && y < that.y) -1
      else if (x == that.x) {if (y < that.y) -1 else if (y == that.y) 0 else 1 }
      else 1
    }

    override def toString: String = "Point[" + x + "x" + y + "]"
  }
} 
开发者ID:Kiryna,项目名称:Scala-for-the-Impatient,代码行数:25,代码来源:Exercise02.scala


示例10: Exercise05

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

import java.awt.Point
import java.beans.{PropertyChangeEvent, PropertyChangeListener}


object Exercise05 extends App {
  println("Chapter 10 Exercise 05")

  val point = new Point with PropertyChangeSupport {
    override def move(x: Int, y: Int): Unit = {
      val oldX = getX
      val oldY = getY
      super.move(x, y)
      pcs.firePropertyChange("x", oldX, getX)
      pcs.firePropertyChange("y", oldY, getY)
    }
  }

  private val listener: PointChangeListener = new PointChangeListener
  point.addPropertyChangeListener(listener)
  point.move(2, 4)

  point.removePropertyChangeListener(listener)
  point.move(1, 3)

  class PointChangeListener extends PropertyChangeListener {
    override def propertyChange(evt: PropertyChangeEvent): Unit =
      println(evt.getPropertyName + ": " + evt.getOldValue + " to " + evt.getNewValue)
  }

  trait PropertyChangeSupport {
    val pcs = new java.beans.PropertyChangeSupport

    def addPropertyChangeListener(listener: PropertyChangeListener): Unit = pcs.addPropertyChangeListener(listener)
    def removePropertyChangeListener(listener: PropertyChangeListener): Unit = pcs.removePropertyChangeListener(listener)
  }
} 
开发者ID:Kiryna,项目名称:Scala-for-the-Impatient,代码行数:39,代码来源:Exercise05.scala



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Scala TileService类代码示例发布时间:2022-05-23
下一篇:
Scala SerializerWithStringManifest类代码示例发布时间:2022-05-23
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap