Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class PostItNoteFrame extends JFrame implements ActionListener, MouseListener, MouseMotionListener{
- //create objects,strings,variables etc
- JPanel TArea;
- JTextArea postItNoteContent = new JTextArea();
- JScrollPane postItNoteScroll = new JScrollPane(postItNoteContent);
- private String Text;
- private static int PostItNoteCount = 1;
- private Font buttonFont = new Font("Arial", Font.BOLD, 30);
- private Color bodyColor = new Color(253, 253, 201);
- private Color titleColor = new Color(248, 247, 182);
- BorderLayout bl = new BorderLayout();
- /**
- * post it note frame
- * sets the post it notes basic settings
- * @param dim dimensions of post it note
- */
- public PostItNoteFrame (Point dim){
- // set Frame to visible, set dimensions, set title, set layout
- this.setSize(new Dimension(dim.x, dim.y));
- this.setTitle("Post-It Note");
- this.setLayout(bl);
- Point StartLoc = this.getLocation();
- StartLoc.x = StartLoc.x+this.getWidth();
- //Create the buttons and add to there respect areas
- this.add(createButtonArea(), BorderLayout.NORTH);
- this.add(createContent(), BorderLayout.CENTER);
- // closes process after exiting using close button
- this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- // set undercorated true
- this.setUndecorated(true);
- this.addMouseListener(this);
- // Set
- this.setVisible(true);
- }
- /**
- * create the content note area
- * @returns the content area of the post it note
- */
- private JScrollPane createContent(){
- // create text area And scroll Pane
- //set background colours set the scroll border to null
- postItNoteContent.setBackground(bodyColor);
- postItNoteScroll.setBackground(bodyColor);
- postItNoteScroll.setBorder(null);
- postItNoteContent.setMargin(new Insets(10,10,10,10));
- return postItNoteScroll;
- }
- /**
- * create button area method
- * setups the button areas
- * @return the newly formated jpanel
- */
- private JPanel createButtonArea(){
- //create button area
- JPanel buttonArea = new JPanel();
- JButton newPostItNote = new JButton ("+");
- JButton deletePostItNote = new JButton("x");
- //set background color
- buttonArea.setBackground(titleColor);
- // reset the Layout
- buttonArea.setLayout(new BorderLayout());
- // set settings for PostItNote
- newPostItNote.setFont(buttonFont);
- newPostItNote.setForeground(Color.GRAY);
- newPostItNote.setBackground(titleColor);
- newPostItNote.setOpaque(true);
- newPostItNote.setBorderPainted(false);
- // set settings for DeletePostItNote
- deletePostItNote.setFont(buttonFont);
- deletePostItNote.setForeground(Color.GRAY);
- deletePostItNote.setBackground(titleColor);
- deletePostItNote.setOpaque(true);
- deletePostItNote.setBorderPainted(false);
- // create buttons and then add them (Set their alignment)
- buttonArea.add(newPostItNote, BorderLayout.WEST);
- buttonArea.add(deletePostItNote, BorderLayout.EAST);
- // set action command and listeners
- newPostItNote.setActionCommand("CreateNewPostItNote");
- newPostItNote.addActionListener(this);
- deletePostItNote.setActionCommand("deletePostItNote");
- deletePostItNote.addActionListener(this);
- return buttonArea;
- }
- /**
- * method for events
- * create new post it note and delete note button events
- */
- public void actionPerformed(ActionEvent e) {
- // TODO Auto-generated method stub
- this.addMouseListener(this);
- if(e.getActionCommand().equals("CreateNewPostItNote")) {
- //Calculate the location for the new note to be placed
- Point startLoc = this.getLocation();
- //Move across by the width of the note
- startLoc.x = startLoc.x+this.getWidth();
- //Check we fit within the screen x size
- Dimension screen = Toolkit.getDefaultToolkit().getScreenSize();
- if (startLoc.x > screen.width - getWidth()){
- //If so move down y and reset x pos
- startLoc.x = 0;
- startLoc.y += this.getHeight();
- }
- PostItNoteFrame note = new PostItNoteFrame(startLoc, new Point(200,200));
- incPostItNoteCount();
- }
- else if(e.getActionCommand().equals("deletePostItNote")){
- this.dispose();
- decPostItNoteCount();
- if (getPostItNoteCount() < 1){
- System.out.println("Exiting Post-It note application.");
- System.exit(0);
- }
- }
- }
- *
- * @return the copied text
- */
- public String getCopiedText(){
- return Text;
- }
- /**
- *
- * @param Text to be copied
- */
- public void setCopiedText(String Text){
- this.Text = Text;
- }
- /**
- *
- * @param postItNoteContent to set
- */
- public void setPostItNoteContent(JTextArea postItNoteContent){
- this.postItNoteContent = postItNoteContent;
- }
- /**
- *
- * @return content of post it note content
- */
- public JTextArea getPostItNoteContent(){
- return postItNoteContent;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement