Can anyone help in resizing the JLabel object

Hi,
can anyone help me in resizing the JLabel object after being dropped onto the DropContainer. I'm providing the code below
import javax.swing.*;
import java.awt.*;
import java.awt.datatransfer.DataFlavor;
import java.awt.datatransfer.Transferable;
import java.awt.datatransfer.UnsupportedFlavorException;
import java.awt.dnd.*;
import java.io.File;
import java.io.Serializable;
import java.awt.event.*;
import java.awt.Insets;
import java.awt.Dimension;
public class project2 extends JApplet implements Runnable{
private DragContainer dragcontainer;
private DropContainer dropcontainer;
private DefaultListModel listModel,listModel1;
public void start() {
Thread kicker = new Thread(this);
kicker.start();
public void run() {
project2 dndapplet = new project2();
dndapplet.init();
public void init() {
try {
getContentPane().setLayout(new BorderLayout());
listModel = new DefaultListModel();
dragcontainer = new DragContainer(listModel);
getContentPane().add(BorderLayout.WEST, new JScrollPane(dragcontainer));
listModel1=new DefaultListModel();
dropcontainer = new DropContainer(listModel1);
getContentPane().add(BorderLayout.CENTER,new JScrollPane(dropcontainer));
catch (Exception e) {
System.out.println("error");
fillUpList("images");
setSize(700, 300);
public static void main(String[] args) {
Frame f = new Frame("dndframe");
project2 dndapplet = new project2();
//Point pos=new Point();
f.add(dndapplet);
dndapplet.init();
dndapplet.start();
f.show();
private void fillUpList(String directory) {
File dir = new File(directory);
File[] files = dir.listFiles();
for (int i = 0; i < 11; i++) {
listModel.addElement(new ImageIcon(directory + "\\" + files.getName()));
class Cursor extends Object implements Serializable
public static final int SE_RESIZE_CURSOR=0;
int cursor;
public Cursor(int SE_RESIZE_CURSOR)
cursor=SE_RESIZE_CURSOR;
class ImageTransferable implements Transferable, Serializable
ImageIcon imageIcon;
public static final DataFlavor IMAGE_FLAVOR = DataFlavor.imageFlavor;
public DataFlavor[] getTransferDataFlavors()
return new DataFlavor[] {IMAGE_FLAVOR};
public ImageTransferable(ImageIcon imageIcon)
this.imageIcon = imageIcon;
public Object getTransferData(DataFlavor f) throws UnsupportedFlavorException
if (!isDataFlavorSupported(f))
throw new UnsupportedFlavorException(f);
return imageIcon;
public boolean isDataFlavorSupported(DataFlavor aFlavor)
return IMAGE_FLAVOR.equals(aFlavor);
class DragContainer extends JList implements DragGestureListener, DragSourceListener
private DragSource iDragSource = null;
public DragContainer(ListModel lm)
super(lm);
iDragSource = new DragSource();
iDragSource.createDefaultDragGestureRecognizer(this,DnDConstants.ACTION_COPY_OR_MOVE, this);
public void dragGestureRecognized(DragGestureEvent aEvt)
ImageIcon imageSelected = (ImageIcon) getSelectedValue();
ImageTransferable imsel = new ImageTransferable(imageSelected);
if (imageSelected != null)
System.out.println("startdrag...");
iDragSource.startDrag(aEvt, DragSource.DefaultCopyNoDrop, imsel, this);
else
System.out.println("Nothing Selected");
public void dropActionChanged(DropTargetDragEvent event)
public void dropActionChanged(DragSourceDragEvent event)
public void dragDropEnd(DragSourceDropEvent event)
public void dragEnter(DragSourceDragEvent event)
public void dragExit(DragSourceEvent event)
public void dragOver(DragSourceDragEvent event)
DragSourceContext context = event.getDragSourceContext();
context.setCursor(null);
context.setCursor(DragSource.DefaultCopyDrop);
class DropContainer extends JList implements DropTargetListener,MouseListener
private DropTarget iDropTarget = null;
private int acceptableActions = DnDConstants.ACTION_COPY_OR_MOVE;
JLabel imgLabel=null;
public int dropX;
public int dropY;
public int x;
public int y;
public DropContainer(ListModel lm1)
super(lm1);
iDropTarget = new DropTarget(this, this);
setBackground(Color.white);
public void drop(DropTargetDropEvent aEvt)
Point location=null;
ImageIcon icon=null;
Transferable transferable=null;
//int dropX=0;
//int dropY=0;
try
transferable = aEvt.getTransferable();
location=new Point();
if(transferable.isDataFlavorSupported(ImageTransferable.IMAGE_FLAVOR))
aEvt.acceptDrop(acceptableActions);
icon = (ImageIcon)
transferable.getTransferData(ImageTransferable.IMAGE_FLAVOR);
setLayout(null);
imgLabel=new JLabel();
imgLabel.setIcon(icon);
imgLabel.addMouseListener(this);
location=aEvt.getLocation();
dropX=location.x;
dropY=location.y;
imgLabel.setBounds(dropX,dropY,icon.getIconWidth(),icon.getIconHeight());
this.add(imgLabel);
SwingUtilities.updateComponentTreeUI(this.getRootPane());
aEvt.getDropTargetContext().dropComplete(true);
else
System.out.println("rejecting drop");
aEvt.rejectDrop();
aEvt.getDropTargetContext().dropComplete(false);
catch (Exception exc)
exc.printStackTrace();
aEvt.rejectDrop();
aEvt.getDropTargetContext().dropComplete(false);
finally
location=null;
transferable=null;
icon=null;
imgLabel=null;
public void mousePressed(MouseEvent e)
x=e.getX();
y=e.getY();
public void mouseReleased(MouseEvent e)
int temp1,temp2;
temp1=y;
temp2=x;
imgLabel.setSize(temp1,temp2);
public void mouseEntered(MouseEvent e) {}
public void mouseExited(MouseEvent e) {}
public void mouseClicked(MouseEvent e) {}
public void dragEnter(DropTargetDragEvent event)
System.out.println("dragenter");
event.acceptDrag(acceptableActions);
public void dragExit(DropTargetEvent event)
System.out.println("dragexit");
public void dragOver(DropTargetDragEvent event)
System.out.println("dragover");
event.acceptDrag(acceptableActions);
public void dropActionChanged(DropTargetDragEvent event)
System.out.println("dropactionchanged");
event.acceptDrag(acceptableActions);
}//class DropContainer

Hi all,
I have two classes, say 1st and 2nd.
I have created an object of the second class in the first class and also i have invoked a method of the second class using it's object from the first class.
but when i compile the first class i'm getting an error that "cannot access the second class".
can anyone help me in fixing this problem
thanks in advance
murali

Similar Messages

Maybe you are looking for

  • How can i import contacts from my regular sim to iphone 5 (nano sim)

    how can i import contacts from my regular sim to iphone 5 (nano sim)

  • User id while  creating a purchase order

    Hello all, I would like to know whether there is any option to enter the user id or user name while creating a purchase order. If so could anyone post on how to do that. Thanks, Maxx

  • Compatability between Windows 8 and my HP Officejet J3680

    I just got a new laptop with Windows 8.  That is hard enough to get used to.  Now my printer does not communicate with my laptop.  I have downloaded drivers and updates.  Changed portsand used HP Doctor whatever.  Nothing seems to work.  Help. This q

  • Data File Parsing in CVI

    Hi guys, I'm new in LabWindows. I have a simple project, which has to parse a .txt file. Only some data inside the txt-File is interesting (the middle part, segment # 1-3 -> see example). The upper and lower part differs in size and is not important.

  • Why can't I sign into messages on OSX Mountain Lion?

    I just upgraded to Mountain Lion on OSX and I cannot sign into Messages or FaceTime. I'm getting this message every time: "The server encountered an error processing registration. Please try again later." Any advice or anyone else experiencing this?