Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.awt.*;
- 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.*;
- /**
- * @author kosta
- */
- public class RightClickMenu extends JPopupMenu implements ActionListener {
- PostItNoteFrame Note;
- /**
- * the menu that has the layout for the right click menu
- * @param PostItNoteFrame the post it note frame for the right click menu
- */
- public RightClickMenu (Object PostItNoteFrame) {
- this.Note = Note;
- JMenuItem Cut = new JMenuItem("Cut");
- Cut.addActionListener(this);
- this.add(Cut);
- JMenuItem Copy = new JMenuItem("Copy");
- Copy.addActionListener(this);
- this.add(Copy);
- JMenuItem Paste = new JMenuItem("Paste");
- Paste.addActionListener(this);
- this.add(Paste);
- JMenuItem About = new JMenuItem("About");
- About.addActionListener(this);
- this.add(About);
- JMenuItem Exit = new JMenuItem("Exit");
- Exit.addActionListener(this);
- this.add(Exit);
- }
- /**
- * action performed menu that holds the functions for exit,copy,paste,about and cut functions
- */
- public void actionPerformed(ActionEvent e) {
- switch(e.getActionCommand()){
- case "Exit":
- System.out.println("Exiting Post-It note application.");
- System.exit(0);
- break;
- case "Copy":
- //note.getPostItNoteContent().copy();
- String copiedText = Note.getPostItNoteContent().getSelectedText();
- if (copiedText != null){
- Note.setCopiedText(copiedText);
- System.out.println(copiedText);
- }
- break;
- case "Paste":
- //Note.getPostItNoteContent().paste();
- if (Note.getCopiedText() != null){
- Note.getPostItNoteContent().insert(Note.getCopiedText(), Note.getPostItNoteContent().getCaretPosition());
- System.out.println(Note.getCopiedText());
- }
- break;
- case "About":
- //AboutPostItNote dialog = new AboutPostItNote(this.note);
- case "Cut":
- String cuttedText = Note.getPostItNoteContent().getSelectedText();
- if (cuttedText != null){
- Note.setCopiedText(Note.getPostItNoteContent().getSelectedText());
- Note.getPostItNoteContent().setText(Note.getPostItNoteContent().getText().replace(Note.getPostItNoteContent().getSelectedText(), ""));
- }
- break;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement