As you read the enhancements to the latest release of the J2SE platform, you will immediately notice that Sun finally listens to our suggestions. I'm not suggesting that they didn't listen to us at all, but they seem to be focusing more on adding large APIs rather than patching up APIs that have been in use for years. For example, the AWT Frame class. Although Sun added the ability to programmatically icon a frame in version 1.2, you still cannot hide the Title bar or maximize the frame. Although you can use Windows to avoid the Title bar, some tasks require a top-level Frame instead of a window. There is basically no luck.
Now, with the 1.4 release, you can programmatically hide platform-specific window adornments, such as Title Bar, and maximize the Frame. Both of these functions were first proposed as early as 1997. The absence of modified Frame support was due to the fact that in the spring of 1997, Sun's error database recorded related errors, and the error identification number for 4038769,frame scaling support was presented in August 1997, with the error identification number 4071554. I'll show you how to use both of these features in this article.
Non-decorated Frame
The simplest way to use these two features is to support unmodified Frame. To hide the Title bar on a frame, you need to set the Undecorated property of the specified frame to true. By default, this value is false and you cannot change this setting when the Frame is displayed (the system throws a Illegalcomponentstateexception exception if you try to change it).
Listing 1. Create a no-decorated Frame
Frame frame = new Frame();
frame.setUndecorated(true);
Because Title Bar and other window decorations are now hidden, you cannot rely on the underlying window management system to provide support for the drag Frame. You must add this support yourself with a pair of mouse listeners.
Listing 2. Add drag Support
// Avoid creating a point with each mousePressed() call
Point origin = new Point();
frame.addMouseListener(new MouseAdapter() {
public void mousePressed(MouseEvent e) {
origin.x = e.getX();
origin.y = e.getY();
}
});
frame.addMouseMotionListener(new MouseMotionAdapter() {
public void mouseDragged(MouseEvent e) {
Point p = frame.getLocation();
frame.setLocation(
p.x + e.getX() - origin.x,
p.y + e.getY() - origin.y);
}
});