I need some help with xtend [message #997323] |
Sat, 05 January 2013 15:51  |
Eclipse User |
|
|
|
I tried posting this to the google+ group but it keeps deleting my post...
I cannot implement the abstract class KeyAdapter inside of another class like I can in Java...
class Something extends JFrame
{
class foo extends KeyAdapter
{
//this will not work, please help me understand why.
}
}
I got it rolling like this but I wonder if there was a more idiomatic well accepted way...
public class keything extends KeyAdapter
{
public static var x = 100
public static var y = 100
override void keyPressed(KeyEvent e)
{
val keyCode = e.keyCode
switch keyCode
{
case 87: y = y - 1
case 65: x = x - 1
case 83: y = y + 1
case 68: x = x + 1
}
}
}
public class Something extends JFrame
{
new()
{
addKeyListener(new keything)
setTitle("GAME")
setSize(500,500)
setResizable(false)
setVisible(true)
setDefaultCloseOperation(EXIT_ON_CLOSE)
}
override public void paint(Graphics g)
{
g.fillOval(keything::x,keything::y,15,15)
repaint
}
def static void main(String[] args)
{
new Something
}
}
|
|
|
|
Re: I need some help with xtend [message #999478 is a reply to message #997323] |
Sat, 12 January 2013 02:40  |
Eclipse User |
|
|
|
Please tet me know why coming the error in this code. this question for all?
Jacob Goodson wrote on Sat, 05 January 2013 15:51I tried posting this to the google+ group but it keeps deleting my post...
I cannot implement the abstract class KeyAdapter inside of another class like I can in Java...
class Something extends JFrame
{
class foo extends KeyAdapter
{
//this will not work, please help me understand why.
}
}
I got it rolling like this but I wonder if there was a more idiomatic well accepted way...
public class keything extends KeyAdapter
{
public static var x = 100
public static var y = 100
override void keyPressed(KeyEvent e)
{
val keyCode = e.keyCode
switch keyCode
{
case 87: y = y - 1
case 65: x = x - 1
case 83: y = y + 1
case 68: x = x + 1
}
}
}
public class Something extends JFrame
{
new()
{
addKeyListener(new keything)
setTitle("GAME")
setSize(500,500)
setResizable(false)
setVisible(true)
setDefaultCloseOperation(EXIT_ON_CLOSE)
}
override public void paint(Graphics g)
{
g.fillOval(keything::x,keything::y,15,15)
repaint
}
def static void main(String[] args)
{
new Something
}
}
|
|
|
Powered by
FUDForum. Page generated in 0.03108 seconds