-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathCustomWindow_JavaTutorial.java
More file actions
77 lines (69 loc) · 2.57 KB
/
Copy pathCustomWindow_JavaTutorial.java
File metadata and controls
77 lines (69 loc) · 2.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
import java.awt.BorderLayout;
import java.awt.FlowLayout;
import java.awt.LayoutManager;
import java.awt.Point;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.event.MouseMotionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;
/**
*
*@author Vincent
*/
public class CustomWindow_JavaTutorial {
static Point compCoords;
public static void main(String[] args) throws ClassNotFoundException, InstantiationException, IllegalAccessException, UnsupportedLookAndFeelException {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
JFrame window = new JFrame("Draggable Component: Java Tutorial");
final JPanel topPanel = new JPanel((LayoutManager) new FlowLayout(FlowLayout.RIGHT));
final JButton minimize = new JButton("-");
final JButton exit = new JButton("X");
exit.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
System.exit(0);
}
});
minimize.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
window.setState(JFrame.ICONIFIED);
}
});
compCoords = null;
topPanel.addMouseListener(new MouseListener() {
public void mouseReleased(MouseEvent e) {
compCoords = null;
}
public void mousePressed(MouseEvent e) {
compCoords = e.getPoint();
}
public void mouseExited(MouseEvent e) {
}
public void mouseEntered(MouseEvent e) {
}
public void mouseClicked(MouseEvent e) {
}
});
topPanel.addMouseMotionListener(new MouseMotionListener() {
public void mouseMoved(MouseEvent e) {
}
public void mouseDragged(MouseEvent e) {
Point currCoords = e.getLocationOnScreen();
window.setLocation(currCoords.x - compCoords.x, currCoords.y - compCoords.y);
}
});
topPanel.add(minimize);
topPanel.add(exit);
window.add(BorderLayout.NORTH, topPanel);
window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
window.setSize(500, 500);
window.setLocationRelativeTo(null);
window.setUndecorated(true);
window.setVisible(true);
}
}