i need a GUI based java program where size of the frame increases whenever mouse is clicked over the frame.Plz help me

Comments
Asking for assignment

Are you allowed to use a JButton? The simplest way to do this would be to add a JButton that covers the whole frame, and resize the frame however you want when the button is clicked.

Otherwise, you'll have to set up a mouse listener on the frame.

take a look at mouse listeners. There are two wasys to do it, make a MouseListener class, or make your JFrame implement mouse listener:

class MyJFrame extends JFrame implements MouseListener
{
	//this is your own extension of a JFrame, you can make it just like any other JFrame with
	//MyJFrame frame = new MyJFrame();
	
	public void mouseClicked(MouseEvent arg0) {
		//do you resizing here
		this.resize(x, y);
	}

	//these methods have to be here because they are part of the interface, but are not used
	public void mouseEntered(MouseEvent arg0) {
		
	}

	public void mouseExited(MouseEvent arg0) {
		
	}

	public void mousePressed(MouseEvent arg0) {
		
	}

	public void mouseReleased(MouseEvent arg0) {
		
	}
}

or

class MyMouseListener  implements MouseListener
{
	//this is your custom mouse listener, you can add this to your frame like this:
	//frame.addMouseListener(new MyMouseListener());
	
	//this class is more versatile, in the future you might want to increase a JButton 
	//or any other component, you can re-use this class on those
	
	
	public void mouseClicked(MouseEvent e) {
		Component component = (Component)e.getSource();
		component.resize(x, y);
	}

	//these methods have to be here because they are part of the interface, but are not used
	public void mouseEntered(MouseEvent arg0) {
		
	}

	public void mouseExited(MouseEvent arg0) {
		
	}

	public void mousePressed(MouseEvent arg0) {
		
	}

	public void mouseReleased(MouseEvent arg0) {
		
	}
}
This article has been dead for over six months. Start a new discussion instead.