-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWords_Frame.java
More file actions
66 lines (51 loc) · 1.51 KB
/
Words_Frame.java
File metadata and controls
66 lines (51 loc) · 1.51 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
package wordframe;
import javax.swing.*;
import java.awt.*;
public class Words_Frame extends JFrame{
public static void main(String[] args) {
Words_Frame app = new Words_Frame();
app.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE );
}
public Words_Frame() {
super( "Words_Frame" );
setSize(850,800);
setVisible(true);
Container container = getContentPane();
container.setLayout( new FlowLayout() );
Dictionary webster = new Dictionary();
String s = "Number of pages: " + webster.getPages() + "\n";
s += "Number of definitions: " + webster.getDefinitions() + "\n";
s += "Definitions per page: " + webster.computeRatio() + "\n";
JTextArea t1 = new JTextArea( s, 5, 20);
container.add( new JScrollPane( t1 ) );
t1.setEditable(false);
}
}
class Book {
protected int pages = 1500;
public void setPages(int numPages) {
pages = numPages;
}
public int getPages() {
return pages;
}
}
class Dictionary {
private Book bk;
private int definitions = 52500;
public Dictionary() {
bk = new Book();
}
public double computeRatio() {
return (double) definitions/bk.getPages();
}
public void setDefinitions(int numDefinitions) {
definitions = numDefinitions;
}
public int getDefinitions() {
return definitions;
}
public int getPages() {
return bk.getPages();
}
}