summaryrefslogtreecommitdiffstats
path: root/Master/Reference Architectures and Patterns/hjp5/examples/Listing3610.java
blob: ec07a0f6f5cbce785a8292dd299bd9a60cadaa27 (plain)
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
83
84
85
/* Listing3610.java */

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.border.*;

public class Listing3610
extends JFrame
implements MouseListener, ActionListener
{
  public Listing3610()
  {
    super("Kontextmen�s");
    addWindowListener(new WindowClosingAdapter(true));
    addMouseListener(this);
  }

  //MouseListener
  public void mouseClicked(MouseEvent event)
  {
    checkPopupMenu(event);
  }

  public void mouseEntered(MouseEvent event)
  {
  }

  public void mouseExited(MouseEvent event)
  {
  }

  public void mousePressed(MouseEvent event)
  {
    checkPopupMenu(event);
  }

  public void mouseReleased(MouseEvent event)
  {
    checkPopupMenu(event);
  }

  private void checkPopupMenu(MouseEvent event)
  {
    if (event.isPopupTrigger()) {
      JPopupMenu popup = new JPopupMenu();
      //R�ckg�ngig hinzuf�gen
      JMenuItem mi = new JMenuItem("Rueckgaengig");
      mi.addActionListener(this);
      popup.add(mi);
      //Separator hinzuf�gen
      popup.addSeparator();
      //Ausschneiden, Kopieren, Einf�gen hinzuf�gen
      mi = new JMenuItem("Ausschneiden");
      mi.addActionListener(this);
      popup.add(mi);
      mi = new JMenuItem("Kopieren");
      mi.addActionListener(this);
      popup.add(mi);
      mi = new JMenuItem("Einfuegen");
      mi.addActionListener(this);
      popup.add(mi);
      //Men� anzeigen
      popup.show(
        event.getComponent(),
        event.getX(),
        event.getY()
      );
    }
  }

  //ActionListener
  public void actionPerformed(ActionEvent event)
  {
    System.out.println(event.getActionCommand());
  }

  public static void main(String[] args)
  {
    Listing3610 frame = new Listing3610();
    frame.setLocation(100, 100);
    frame.setSize(300, 200);
    frame.setVisible(true);
  }
}