-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathScoreTextArea.java
More file actions
124 lines (113 loc) · 2.57 KB
/
Copy pathScoreTextArea.java
File metadata and controls
124 lines (113 loc) · 2.57 KB
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
/* File : ScoreTextArea.java
* Project: T Score Calculation
* Purpose: Raw score input in JTextArea and then
* converse them to number.
* Author : Wachara R.
* First Released: Sun 9 March 2008
* Last Updated : Tue 7 November 2009
*/
package tscore;
import javax.swing.*;
import java.awt.*;
import static tscore.TScoreConstants.*;
public class ScoreTextArea extends JTextArea
{
Font textFont = new Font("Dialog", Font.PLAIN, 12);
int NumberOfScore;
private double [ ] Score = new double[MAXIMUM_NUMBER_OF_DATA+1];
public ScoreTextArea ()
{
setFont(textFont);
setBackground(Color.white);
setSelectionColor(Color.pink);
setLineWrap(false); // Wrap the line at the container end.
}
public int readScore( )
{
String score = super.getText();
char[] ch = score.toCharArray();
String temp="";
boolean IN_COMMENT=false;
boolean IN_DIGIT = false;
int point = 0;
int line = 0;
int n = 0;
for(int i =0; i < ch.length ; i++)
{
switch (ch[i])
{
case '*' :
IN_COMMENT = true;
break;
case '0':
case '1':
case '2':
case '3':
case '4':
case '5':
case '6':
case '7':
case '8':
case '9':
case '.':
if (!IN_COMMENT)
{
IN_DIGIT =true;
if (ch[i] == '.') point +=1;
temp = temp + ch[i];
if (point > 1) {
displayError ("Some score not (a) numbers at line"+(line+1), "Error");
return -1;
}
}
break;
case ' ':
case '\n':
if (ch[i] == '\n')
{
line = line +1;
IN_COMMENT = false;
}
if (!(IN_COMMENT ) && IN_DIGIT)
{
point = 0;
// if (temp != "")
if (temp != "" && temp != " ") {
Score[n] = Double.parseDouble(temp);
temp = "";
n=n+1;
if ( n > (MAXIMUM_NUMBER_OF_DATA)) {
displayError ("Sorry! Your data exceed "+(MAXIMUM_NUMBER_OF_DATA)+"\nPlease truncate your data","Error" );
return -1;
} // if (n >=.....
}
IN_DIGIT = false;
}
break;
default :
if (!IN_COMMENT)
{
displayError("Error at line"+(line+1), "Error");
return -1;
}
break;
} //switch
if ( i == (ch.length-1) && ch[i] != '\n' && ch[i] != ' ') { // does'nt work --> && ch[i] !=null
Score[n] = Double.parseDouble(temp);
n=n+1;
if ( n > (MAXIMUM_NUMBER_OF_DATA)) {
displayError ("Sorry! Your data exceed "+(MAXIMUM_NUMBER_OF_DATA)+"\nPlease truncate your data","Error" );
return -1;
} // if (n >=.....
}
}// for loop
return n;
}
public double [ ] getScore()
{
return Score;
}
void displayError( String msgErr, String msgTitle) {
JOptionPane.showMessageDialog(null, msgErr, msgTitle,JOptionPane.ERROR_MESSAGE);
}
}