The Artima Developer Community
Sponsored Link

Programming in Scala Forum
How to get message from custom component?

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
Eric Fowler

Posts: 2
Nickname: wildsalmon
Registered: May, 2014

How to get message from custom component? Posted: Jun 14, 2014 10:41 PM
Reply to this message Reply
Advertisement
New to Swing here.

I can make a button and get button clicks:
val button = new Button{
text = "Click me!"
}

contents = new BoxPanel(Orientation.Vertical)
{
contents += button
border = Swing.EmptyBorder(30,30,10,30)
}

listenTo(button)

var nClicks = 0;
reactions += {
case ButtonClicked(b) =>
nClicks += 1
label.text = "Number of clicks: " + nClicks
}

OK, fine.

Now I make a new component:
var vc = new VertexComponent

Where (in another file):

import scala.swing.Component
import scala.swing._

class VertexComponent extends Component {

override def paint(g: Graphics2D):Unit = {

//... blah. This works.
}

}

I want to know how I trap a button click on the component.
Do I need to set up my own case class like ButtonClick? How do I tie that to the actual event?

Should be easy.

Topic: scala.Application?? Previous Topic   Next Topic Topic: Scala Tuples and Map+=

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use