Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Placing an image object on canvas(urgent)

 
Sandy Abraham
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I will be running my program on my PocketPC using Jeode. I want to place an image object on top of a canvas. How do you do that? Please help.
Part of the canvas program is

class MyCanvas extends Canvas implements MouseMotionListener
{
int x;
int y;
int boxSize;
int halfBoxSize;
public void mouseDragged(MouseEvent ev)
{
mouseMoved(ev);
}
public void mouseMoved(MouseEvent ev)
{
x = ev.getX() - halfBoxSize;
y = ev.getY() - halfBoxSize;
repaint();
}
public void paint(Graphics g)
{
g.setColor(Color.red);
if(x >= 0 && y >= 0)
{
g.fillRect(x, y, boxSize, boxSize);
}
}
public MyCanvas()
{
x = -1;
y = -1;
boxSize = 10;
halfBoxSize = boxSize / 2;
setBackground(Color.gray);
setSize(600, 800);
setVisible(true);
addMouseMotionListener(this);
repaint();
}
}
void setupPanels()
{
Panel mainPanel = new Panel();
mainPanel.setLayout(new GridLayout(1, 1));
Panel panels[][] = new Panel[1][1];
for(int j = 0; j < 1; j++)
{
panels[j][0] = new Panel();
panels[j][0].setLayout(new FlowLayout(0));
}
panels[0][0].add(new MyCanvas());

for(int j = 0; j < 1; j++)
{
mainPanel.add(panels[j][0]);
}
add("Center", mainPanel);
}
Thank you!
 
Nathan Pruett
Bartender
Posts: 4121
IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Just add a g.drawImage() call in your paint() method... if you want the image to be on top of everything else, just make it the last call in the paint() method.
 
Sandy Abraham
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What's the statement to get the key pressed on the PocketPC if I choose not to use the pen thingy?
It's like this, I have one big image divided into 4 small parts, to fit the small PocketPC screen. And when i press the 'Right' arrow button on PocketPC, the screen which is displaying the first part of the big image which move left, displaying the second part of the image. How do I do this? Anyone can help?
 
Sandy Abraham
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm using Jeode
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic