• Post Reply Bookmark Topic Watch Topic
  • New Topic

Moving comonents  RSS feed

 
Dave Donohoe
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Does anyone know if there is a way to allow the user of a Java Application to move components like buttons around the screen ?
 
swapnil dey
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi dave,
the basic requirement for moving the components is to set the LayoutManager of the container to 'null'.
Then the components can be moved within their container by using Component.setLocation(x, y); or Component.setLocation(Point p)
u will also need to set the size of the component by using Component.setSize(width, height)or Component.setSize(Dimension d)
the size needs to be set coz the location & the size are set to a default 0 if the LayoutManager is null
hope this solves ur problem
 
kishor patankar
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Dave Donohoe:
Does anyone know if there is a way to allow the user of a Java Application to move components like buttons around the screen ?

Dear Dave,
Here is a working code.
import java.applet.*;
import java.awt.*;
import java.awt.event.*;
public class MoveAhead extends Applet implements MouseMotionListener
{
Label lbl = new Label ("Hello World");
public void init()
{
add(lbl);
addMouseMotionListener(this);
}
public void mouseDragged(MouseEvent e)
{
lbl.setLocation(e.getX(), e.getY());
}
public void mouseMoved(MouseEvent e)
{
lbl.setLocation(e.getX(), e.getY());
}
}
 
kishor patankar
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dear Dave,
Here is a sample working code.
import java.applet.*;
import java.awt.*;
import java.awt.event.*;
public class MoveAhead extends Applet implements MouseMotionListener
{
Label lbl = new Label ("Hello World");
public void init()
{
add(lbl);
addMouseMotionListener(this);
}
public void mouseDragged(MouseEvent e)
{
lbl.setLocation(e.getX(), e.getY());
}
public void mouseMoved(MouseEvent e)
{
lbl.setLocation(e.getX(), e.getY());
}
}
 
kishor patankar
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
here is a code.
import java.applet.*;
import java.awt.*;
import java.awt.event.*;
public class MoveAhead extends Applet implements MouseMotionListener
{
Label lbl = new Label ("Hello World");
public void init()
{
add(lbl);
addMouseMotionListener(this);
}
public void mouseDragged(MouseEvent e)
{
lbl.setLocation(e.getX(), e.getY());
}
public void mouseMoved(MouseEvent e)
{
lbl.setLocation(e.getX(), e.getY());
}
}
 
Dave Donohoe
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Kishor, thats great............
Much Appriciated,
Dave
 
Dave Donohoe
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the reply Swapnil - that is exactly what I needed !
D
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!