JAVA_PRACTICAL13
JAVA_PRACTICAL13
JAVA_PRACTICAL13
import java.awt.*;
import java.awt.event.*;
Frame f;
WindowDemo()
f.addWindowListener(new WindowAdapter()
f.dispose();
});
f.setSize(400,400);
f.setVisible(true);
f.setLayout(null);
}
public static void main(String[] args)
new WindowDemo();
}
}
OutPut:-
Exercise:-
Q.1) write a program to demostrate the use of windowAdapter class.
import java.awt.*;
import java.awt.event.*;
public WindowAdapterDemo() {
setTitle("WindowAdapter Example");
setSize(400, 300);
addWindowListener(new WindowAdapter() {
System.out.println("Window is closing...");
dispose();
});
setLayout(new FlowLayout());
window.setVisible(true);
}
}
Output:-
import java.awt.*;
import java.awt.event.*;
public AnonymousInnerClassDemo() {
setSize(300, 200);
setLayout(new FlowLayout());
button.addActionListener(new ActionListener() {
@Override
});
add(button);
addWindowListener(new WindowAdapter() {
@Override
System.out.println("Window is closing...");
dispose();
});
demo.setVisible(true);
}
}
Output:-
Q.3)write a java program using MouseMotionAdapter class to implement only oe method
mouseDragged().
import java.awt.*;
import java.awt.event.*;
private int x = 0;
private int y = 0;
public MouseMotionAdapterDemo() {
setTitle("MouseMotionAdapter Example");
setSize(400, 400);
setBackground(Color.RED);
addMouseMotionListener(new MouseMotionAdapter() {
@Override
x = e.getX();
y = e.getY();
repaint();
});
addWindowListener(new WindowAdapter() {
@Override
dispose();
}
});
@Override
g.setColor(Color.RED);
window.setVisible(true);
}
}
Output:-