Advertisement
xlrnxnlx

none

Sep 4th, 2014
227
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.41 KB | None | 0 0
  1. package uf.views.controll;
  2.  
  3. import java.awt.Point;
  4. import java.awt.event.*;
  5. import javax.swing.JFrame;
  6. import uf.views.MainView;
  7.  
  8. public class MainControll implements ActionListener {
  9.  
  10.     private MainView view;
  11.  
  12.     public MainControll() {}
  13.  
  14.     // construt.
  15.     public MainControll(MainView view) {
  16.         this.view = view;
  17.         // listeners.
  18.         view.getViewButtons().stream().forEach((b) -> {
  19.             b.addActionListener(this);
  20.         });
  21.         // controle da janela undecorated.
  22.         Point point = new Point();
  23.         view.addMouseListener(new MouseAdapter(){
  24.             @Override
  25.             public void mousePressed(MouseEvent e) {
  26.                 point.x = e.getX();
  27.                 point.y = e.getY();
  28.             }
  29.         });
  30.         // controle da janela undecorated.
  31.         view.addMouseMotionListener(new MouseMotionAdapter(){
  32.             @Override
  33.             public void mouseDragged(MouseEvent e) {
  34.                 Point p = view.getFrame().getLocation();
  35.                 view.getFrame().setLocation(p.x + e.getX() - point.x, p.y + e.getY() - point.y);
  36.             }
  37.         });
  38.         view.setVisible(true);
  39.     }
  40.  
  41.     @Override
  42.     public void actionPerformed(ActionEvent e) {
  43.         switch(e.getActionCommand()){
  44.             case "close": System.exit(0); break;
  45.             case "min": view.setExtendedState(JFrame.ICONIFIED); break;
  46.         }
  47.     }
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement