aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes Placing an image object on canvas(urgent) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Placing an image object on canvas(urgent)" Watch "Placing an image object on canvas(urgent)" New topic
Author

Placing an image object on canvas(urgent)

Sandy Abraham
Greenhorn

Joined: Aug 27, 2003
Posts: 9
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

Joined: Oct 18, 2000
Posts: 4121

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.


-Nate
Write once, run anywhere, because there's nowhere to hide! - /. A.C.
Sandy Abraham
Greenhorn

Joined: Aug 27, 2003
Posts: 9
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

Joined: Aug 27, 2003
Posts: 9
I'm using Jeode
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: Placing an image object on canvas(urgent)