Advertisement
FlyChsCake

Jaba 11 - 16

Nov 22nd, 2019
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.77 KB | None | 0 0
  1. package lab2;
  2.  
  3. import java.awt.Color;
  4. import java.awt.Dimension;
  5. import java.awt.event.KeyEvent;
  6. import java.awt.event.MouseEvent;
  7. import java.awt.event.MouseListener;
  8. import java.awt.event.KeyListener;
  9. import javax.swing.JFrame;
  10.  
  11. public class lab11 extends JFrame {
  12.     public lab11 () {
  13.         Dimension d = new Dimension(300, 300);
  14.         setSize(d);
  15.         setTitle("ЛТЕУ");
  16.         setLocation(150, 350);
  17.         addMouseListener(new InternalClass(this));
  18.         getContentPane().setBackground(Color.GREEN);
  19.         addKeyListener(new InternalClass(this));
  20.     }
  21.  
  22.     public static void main(String[] args) {
  23.         lab11 w = new lab11();
  24.         w.setVisible(true);
  25.     }
  26.    
  27.     private class InternalClass implements MouseListener, KeyListener {
  28.             JFrame window;
  29.  
  30.             public InternalClass(JFrame window) {
  31.                 this.window = window;
  32.             }
  33.  
  34.             private void eventToDo() {
  35.                 window.setLocation(window.getLocationOnScreen().x, window.getLocationOnScreen().y - 10);
  36.             }
  37.  
  38.             public void mouseEntered(MouseEvent event) {}
  39.             public void mouseExited(MouseEvent event) {}
  40.             public void mousePressed(MouseEvent event) {}
  41.             public void mouseClicked(MouseEvent event) {}
  42.             public void mouseReleased(MouseEvent event) {
  43.                 if (event.getButton() == MouseEvent.BUTTON3) {
  44.                     eventToDo();
  45.                 }
  46.             }
  47.  
  48.             public void keyTyped(KeyEvent e) {}
  49.             public void keyReleased(KeyEvent e) {}
  50.             public void keyPressed(KeyEvent e) {
  51.                 if (((e.getModifiersEx() & KeyEvent.CTRL_DOWN_MASK) != 0) && ((e.getModifiersEx() & KeyEvent.SHIFT_DOWN_MASK) != 0)) {
  52.                     eventToDo();
  53.                 }
  54.             }
  55.         }
  56.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement