-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDataInputController.java
35 lines (30 loc) · 1019 Bytes
/
DataInputController.java
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
import javax.swing.*;
import java.awt.event.*;
import java.io.File;
public class DataInputController implements ActionListener
{
private Graph graph; //The Model used to describe the game
private JTextField dataInputted; //The textField linked to the controller
public DataInputController(Graph aGraph, JTextField aTextField)
{
this.graph = aGraph;
this.dataInputted = aTextField;
}
public void actionPerformed(ActionEvent e)
{
String text = dataInputted.getText();
if (text != null)
{
try
{
int temp = Integer.parseInt(text);
this.graph.addData(temp);
dataInputted.setText("");
}
catch (NumberFormatException ex)
{
this.dataInputted.selectAll();
}
}
}
}