C:\Users\notebook\Documents\NetBeansProjects\CS2\src\frames\KFrame9.java |
1
2
3
4 package frames;
5
6 import java.awt.BorderLayout;
7 import java.awt.Color;
8 import java.awt.Container;
9 import java.awt.FlowLayout;
10 import java.awt.event.ActionEvent;
11 import java.awt.event.ActionListener;
12 import javax.swing.JButton;
13 import javax.swing.JFrame;
14 import javax.swing.JPanel;
15 import javax.swing.JTextArea;
16 import javax.swing.JTextField;
17 import utilities.Random;
18
19
20
21 @author
22
23 public class KFrame9 extends JFrame implements ActionListener {
24
25 JTextArea displayer;
26 JButton termButton;
27 JButton quoteButton;
28 JButton personButton;
29 JButton languageButton;
30 JButton colorButton;
31 JButton clearButton;
32 JTextField input;
33
34 public KFrame9(String title) {
35 super(title);
36 setSize(700, 700);
37 setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
38 addComponents(getContentPane());
39 addListeners();
40 setVisible(true);
41 }
42
43 private void addComponents(Container contentPane) {
44
45 termButton = new JButton("Term");
46 quoteButton = new JButton("Quote");
47 personButton = new JButton("Person");
48 languageButton = new JButton("Language");
49 colorButton = new JButton("Color");
50 clearButton = new JButton("Clear");
51 JPanel controlPanel = new JPanel();
52 controlPanel.setLayout(new FlowLayout());
53 controlPanel.add(termButton);
54 controlPanel.add(quoteButton);
55 controlPanel.add(personButton);
56 controlPanel.add(languageButton);
57 controlPanel.add(colorButton);
58 controlPanel.add(clearButton);
59
60 displayer = new JTextArea();
61
62 input = new JTextField();
63
64 contentPane.setLayout(new BorderLayout());
65 contentPane.add(controlPanel, BorderLayout.NORTH);
66 contentPane.add(displayer, BorderLayout.CENTER);
67 contentPane.add(input, BorderLayout.SOUTH);
68
69 }
70
71 private void addListeners() {
72 termButton.addActionListener(this);
73 quoteButton.addActionListener(this);
74 personButton.addActionListener(this);
75 languageButton.addActionListener(this);
76 colorButton.addActionListener(this);
77 clearButton.addActionListener(this);
78 input.addActionListener(this);
79 }
80
81 public void actionPerformed(ActionEvent event) {
82 String command = event.getActionCommand();
83 displayer.setLineWrap(true);
84 displayer.setWrapStyleWord(true);
85 int random = (int) Math.round(Math.random() * 9);
86 if (event.getSource() instanceof JTextField) {
87 input.setText("");
88 }
89 if (command.equalsIgnoreCase("Term")) {
90 displayer.append(termsArray()[random] + "\n");
91 } else if (command.equalsIgnoreCase("Quote")) {
92 displayer.append(quotesArray()[random] + "\n");
93 } else if (command.equalsIgnoreCase("Person")) {
94 displayer.append(peopleArray()[random] + "\n");
95 } else if (command.equalsIgnoreCase("Language")) {
96 displayer.append(languagesArray()[random] + "\n");
97 } else if (command.equalsIgnoreCase("Color")) {
98 displayer.setBackground(Random.color());
99 } else if (command.equalsIgnoreCase("Clear")) {
100 displayer.setText(null);
101 }
102 }
103
104 private static String[] termsArray() {
105 String[] terms = new String[10];
106 terms[0] = "Bug: A programming error that causes unexpected glitches or problems for a program’s end user.";
107 terms[1] = "Debugging: The process of finding and removing errors from a program's source code.";
108 terms[2] = "Stepwise Refinement: A way of developing a computer program by first describing general functions, then breaking each function down into details which are refined in successive steps until the whole program is fully defined.";
109 terms[3] = "Application Programming Interface (API): The platform used by a program to access different services on the computer system.";
110 terms[4] = "Array: Similar data saved on a computer system in a sequential form.";
111 terms[5] = "Boolean: An expression, the value of which is either true or false.";
112 terms[6] = "Integrated Development Environment (IDE): A programming system that combines several tools of programming to provide an integrated platform for programming.";
113 terms[7] = "Variable: A portion of memory reserved to hold a single value.";
114 terms[8] = "Algorithm: A set of rules for solving a problem in a given number of steps.";
115 terms[9] = "Compiler: A program that translates human-readable programs into a form the computer understands.";
116 return terms;
117 }
118
119 private static String[] quotesArray() {
120 String[] quotes = new String[10];
121 quotes[0] = "Computing science is no more about computers than astronomy is about telescopes. - Edsger W. Dijkstra";
122 quotes[1] = "The purpose of computing is insight, not numbers. - Richard Hamming";
123 quotes[2] = "People think that computer science is the art of geniuses but the actual reality is the opposite, just many people doing things that build on each other, like a wall of mini stones. - Donald Knuth";
124 quotes[3] = "If a listener nods his head when you’re explaining your program, wake him up. - Alan J. Perlis";
125 quotes[4] = "We can only see a short distance ahead, but we can see plenty there that needs to be done. - Alan Turing";
126 quotes[5] = "A language that doesn’t have everything is actually easier to program in than some that do. - Dennis M. Ritchie";
127 quotes[6] = "Controlling complexity is the essence of computer programming. - Brian W. Kernighan";
128 quotes[7] = "Anyone who considers arithmetic methods of producing random digits is, of course, in a state of sin. - John Von Neumann";
129 quotes[8] = "There's an old story about the person who wished his computer were as easy to use as his telephone. That wish has come true, since I no longer know how to use my telephone. - Bjarne Stroustrup";
130 quotes[9] = "Code never lies, comments sometimes do. - Ron Jeffries";
131 return quotes;
132 }
133
134 private static String[] peopleArray() {
135 String[] people = new String[10];
136 people[0] = "Barbara Liskov: Helped develop and implement programming languages like CLU, the first programming language to support data abstraction.";
137 people[1] = "Larry Page: Co-founder of the trusty search engine Google (with Sergey Brin)";
138 people[2] = "Carl Sassenrath: Developed: 1) Amiga Computer, the first multimedia personal computer of its time; 2) REBOL, a specialized computer language technology.";
139 people[3] = "Ada Lovelace: Considered to be the first computer programmer. Theorized a method for the engine to repeat a series of instructions (looping).";
140 people[4] = "Edsger Dijkstra: Made advances in algorithms, pioneered and coined the term structured programming, invented the semaphore, and famously suggested that the GOTO statement should be considered harmful.";
141 people[5] = "Corrado Böhm: Theorized the concept of structured programming.";
142 people[6] = "George Boole: Formalized Boolean algebra, the basis for digital logic and computer science.";
143 people[7] = "Alonzo Church: Founded contributions to theoretical computer science, specifically for the development of the lambda calculus and the discovery of the undecidability problem within it.";
144 people[8] = "Herman Hollerith: Widely regarded as the father of modern machine data processing. His invention of the punched card tabulating machine marks the beginning of the era of semiautomatic data processing systems.";
145 people[9] = "Grace Hopper: Pioneered work on the necessity for high-level programming languages, which she termed automatic programming, and wrote the A-0 compiler, which heavily influenced the COBOL language.";
146 return people;
147 }
148
149 private static String[] languagesArray() {
150 String[] languages = new String[10];
151 languages[0] = "Hypertext Markup Language (HTML): A coding language used to write Internet-based documents, like websites. (Tim Berners-Lee, 1989)";
152 languages[1] = "Java: a general-purpose computer-programming language that is concurrent, class-based, object-oriented, and specifically designed to have as few implementation dependencies as possible. (James Gosling, 1995)";
153 languages[2] = "JavaScript (JS): A high-level, interpreted programming language that conforms to the ECMAScript specification. Enables interactice web pages. (Brendan Eich, 1995)";
154 languages[3] = "C++: A general-purpose programming language. It has imperative, object-oriented and generic programming features, while also providing facilities for low-level memory manipulation. (Bjarne Stroustrup, 1985)";
155 languages[4] = "C#: A general-purpose, multi-paradigm programming language encompassing strong typing, lexically scoped, imperative, declarative, functional, generic, object-oriented (class-based), and component-oriented programming disciplines. (Microsoft, 2000)";
156 languages[5] = "Python: An interpreted, high-level, general-purpose programming language. (Guido van Rossum, 1990)";
157 languages[6] = "PHP: Hypertext Preprocessor (or simply PHP): A general-purpose programming language originally designed for web development. (Rasmus Lerdorf, 1994)";
158 languages[7] = "Ruby: A dynamic, interpreted, reflective, object-oriented, general-purpose programming language. (Yukihiro Matsumoto, 1995)";
159 languages[8] = "Swift: A general-purpose, multi-paradigm, compiled programming language developed by Apple Inc. for iOS, macOS, watchOS, tvOS, Linux and z/OS. (Chris Lattner, Doug Gregor, John McCall, Ted Kremenek, Joe Groff, 2014)";
160 languages[9] = "Rust: A multi-paradigm systems programming language focused on safety, especially safe concurrency. Syntactically similar to C++, but is designed to provide better memory safety while maintaining high performance. (Garry Newman, 2010)";
161 return languages;
162 }
163
164 }
165