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 78 79 80 81 82
| package client;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Rectangle;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseMotionListener;
import javax.swing.BorderFactory;
import javax.swing.JInternalFrame;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.plaf.basic.BasicInternalFrameUI;
public class ChildFrame extends JInternalFrame implements MouseMotionListener {
private JMenu menuFile = new JMenu();
private JMenuItem menuFileExit = new JMenuItem();
private JMenuBar menuBar = new JMenuBar();
public ChildFrame() {
try {
jbInit();
} catch (Exception e) {
e.printStackTrace();
}
}
// on cree la drag fonction
public void mouseDragged(MouseEvent argEvent) {
if (argEvent.getX() < 0 || argEvent.getY() < 0) {
Rectangle objBounds = this.getBounds();
this.setLocation(objBounds.x + argEvent.getX(),
objBounds.y + argEvent.getY());
} else {
Rectangle objBounds = this.getBounds();
if (objBounds.x <= objBounds.x + argEvent.getX() &&
objBounds.x + argEvent.getX() <=
objBounds.x + objBounds.width &&
objBounds.y <= objBounds.y + argEvent.getY() &&
objBounds.y + argEvent.getY() <=
objBounds.y + objBounds.height) {
this.setLocation(objBounds.x + argEvent.getX(),
objBounds.y + argEvent.getY());
} else {
this.setLocation(argEvent.getX(), argEvent.getY());
}
}
}
public void mouseMoved(MouseEvent argEvent) {
}
void fileExit_ActionPerformed(ActionEvent e) {
this.dispose();
}
private void jbInit() throws Exception {
BasicInternalFrameUI ui = (BasicInternalFrameUI)this.getUI();
ui.setNorthPane(null); // supprime la title bar
this.setOpaque(true);
this.setSize(new Dimension(908, 700));
menuBar.add(menuFile);
this.setJMenuBar(menuBar);
menuFile.setText("File");
menuFile.add(menuFileExit);
menuFileExit.setText("Close");
menuFileExit.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent ae) {
fileExit_ActionPerformed(ae);
}
});
this.getContentPane().setLayout(null);
menuBar.setBackground(new Color(165, 255, 165));
// ceci assigne la drag fonction au JmenuBar
menuBar.addMouseMotionListener(this);
getContentPane().setLayout(null);
this.setBorder(BorderFactory.createLineBorder(Color.black, 1));
}
} |
Partager