Skip to content
Snippets Groups Projects
Commit a73b5ad9 authored by Nils Vreman's avatar Nils Vreman
Browse files

Added functionality to update tasklabels on events where focus is lost

parent 8e8456f6
No related branches found
No related tags found
No related merge requests found
......@@ -4,13 +4,16 @@ import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.awt.event.MouseListener;
import java.awt.event.MouseEvent;
import java.awt.event.FocusListener;
import java.awt.event.FocusEvent;
import java.awt.Color;
import javax.swing.JTextField;
import gui.UpdateListener;
public class TaskLabel extends JTextField implements MouseListener {
public class TaskLabel extends JTextField implements FocusListener, MouseListener {
private String previousText;
private UpdateListener updateListener;
private MarkListener markListener;
......@@ -24,6 +27,7 @@ public class TaskLabel extends JTextField implements MouseListener {
// Add Listener for when mouse does something with object
addMouseListener(this);
addFocusListener(this);
// Add Listener that does something with object when <Enter> is pressed
addActionListener(new ActionListener() {
......@@ -51,7 +55,10 @@ public class TaskLabel extends JTextField implements MouseListener {
this.markListener = markListener;
}
// MouseListener Functions.
/*
* MouseListener Functions.
*/
/*
* Invoked when the mouse button has been clicked (pressed and released) on a component.
*/
......@@ -78,4 +85,25 @@ public class TaskLabel extends JTextField implements MouseListener {
* Invoked when the mouse exits a component.
*/
public void mouseExited(MouseEvent e) {}
/*
* FocusListener Functions.
*/
/*
* Invoked when a component gains the keyboard focus.
*/
public void focusGained(FocusEvent e) {
previousText = getText();
}
/*
* Invoked when a component loses the keyboard focus.
*/
public void focusLost(FocusEvent e) {
if (!previousText.equals(getText()) && getText().matches("[0-9]+")) {
System.out.println(getText());
updateListener.update();
}
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment