54 Pages

gui

Course: CS 101, Fall 2008
School: UVA
Rating:
 
 
 
 
 

Word Count: 1534

Document Preview

programming Graphical GUI user interfacebased programming Windchill Windchill There are several formulas for calculating the windchill temperature twc The one provided by U.S. National Weather Service and is applicable for a windspeed greater than four miles per hour twc = 0.081(t - 91.4)(3.71 v + 5.81 - 0.25v) + 91.4 Where Variable t is the Fahrenheit temperature Variable v is the windspeed in miles per...

Register Now

Unformatted Document Excerpt

Coursehero >> Virginia >> UVA >> CS 101

Course Hero has millions of student submitted documents similar to the one
below including study guides, practice problems, reference materials, practice exams, textbook help and tutor support.

Course Hero has millions of student submitted documents similar to the one below including study guides, practice problems, reference materials, practice exams, textbook help and tutor support.
programming Graphical GUI user interfacebased programming Windchill Windchill There are several formulas for calculating the windchill temperature twc The one provided by U.S. National Weather Service and is applicable for a windspeed greater than four miles per hour twc = 0.081(t - 91.4)(3.71 v + 5.81 - 0.25v) + 91.4 Where Variable t is the Fahrenheit temperature Variable v is the windspeed in miles per hour Consolebased programming Console program Method main() { statement1; statement2; ... statementm; } Console program s begin and end in m et hod m ain( ) In use Pr ogr am needs to r espond whenev er the r un button is click ed Ther e needs to be an ev ent loop that is look ing for user inteface ev ents GUIbased programming GUI program begins in m et hod m ain( ) . The m et hod creat es a new inst ance of t he GUI by invoking t he GUI const ruct or. On com plet ion, t he event dispat ching loop is begun GUI Program main() { GUI gui = new GUI(); } GUI Constructor() { constructor1; constructor2; ... constructorn; } Action Performer() { action1; action2; ... actionk; } Const ruct or configures t he com ponent s of t he GUI . I t also regist ers t he list ener perform er for user int eract ions Event-dispatching loop do if an event occurs then signal its action listeners until program ends The event dispat ching loop wat ches for user int eract ions wit h t he GUI . When an event occurs, it s list ener perform ers are not ified The act ion perform er im plem ent s t he t ask of t he GUI . Aft er it com plet es, t he event dispat ching loop is rest art ed Java support JFrame Represents a titled, bordered window JLabel Represents a display area suitable for one or both of a singleline text or image. JTextField Represents an editable singleline text entry component JButton Represents a push button JTextArea Represents an editable multiline text entry component Instance variables private JFrame window References the window containing the other components of the GUI Instance variables private JTextArea legendArea References the text display for the multiline program legend Instance variables private JLabel fahrTag References the label for the data entry area supplying the temperature Instance variables private JTextField fahrText References the data area supplying the temperature Instance variables private JLabel windTag References the label for the data entry area supplying the windspeed Instance variables private JTextField windText References the data area supplying the windspeed Instance variables private JLabel chillTag References the label for the data area giving the windchill Instance variables private JTextField chillText References the data area giving the windchill Class constants private static final String LEGEND = "This windchill calculator" + "is intended for velocities greater than 4 mph." Program legend text Class constants private static final int WINDOW_WIDTH = 350 Initial width of the GUI Class constants private static final int WINDOW_HEIGHT = 185 Initial height of the GUI Class constants private static final int AREA_WIDTH = 40 Width of the program legend in characters Class constants private static final int FIELD_WIDTH = 40 Number of characters per data entry area Class constants private static final FlowLayout LAYOUT_STYLE = new FlowLaout() References manager that lays out GUI components in a topto bottom, lefttoright manner Class constants private static FlowLayout LAYOUT_STYLE = new FlowLaout() References manager that lays out GUI components in a topto bottom, lefttoright manner Class constants private static FlowLayout LAYOUT_STYLE = new FlowLaout() References manager that lays out GUI components in a topto bottom, lefttoright manner Program Windchill.java import javax.swing.*; import java.awt.*; import java.awt.event.*; public class Windchill implements ActionListener { // class constants // instance variables with initialization // Windchill(): default constructor // actionPerformed(): run button action event handler // main(): application entry point } Program Windchill.java class constants private static final int WINDOW_WIDTH = 350; // pixels private static final int WINDOW_HEIGHT = 185; // pixels private static final int FIELD_WIDTH = 20; // characters private static final int AREA_WIDTH = 40; // characters private static final FlowLayout LAYOUT_STYLE = new FlowLayout(); private static final String LEGEND = "This windchill " + "calculator is intended for velocities greater than 4 mph."; Program Windchill.java instance variables // window for GUI private JFrame window = new JFrame("Windchill Calculator"); // legend private JTextArea legendArea = new JTextArea(LEGEND, 2, AREA_WIDTH); // user entry area for temperature private JLabel fahrTag = new JLabel("Fahrenheit temperature"); private JTextField fahrText = new JTextField(FIELD_WIDTH); Program Windchill.java instance variables // user entry area for windspeed private JLabel windTag = new JLabel(" Windspeed (mph)"); private JTextField windText = new JTextField(FIELD_WIDTH); // entry area for windchill result private JLabel chillTag = new JLabel(" Windchill temperature"); private JTextField chillText = new JTextField(FIELD_WIDTH); // run button private JButton runButton = new JButton("Run"); Program Windchill.java constructor public Windchill() { // configure GUI // register event listener // add components to container // display GUI } Program Windchill.java constructor public { Windchill() // configure GUI window.setSize(WINDOW_WIDTH, WINDOW_HEIGHT); window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); legendArea.setEditable(false); legendArea.setLineWrap(true); legendArea.setWrapStyleWord(true); legendArea.setBackground(window.getBackground()); chillText.setEditable(false); chillText.setBackground(Color.WHITE); Bad line wrapping It is important to make program legends uneditable Program Windchill.java constructor public Windchill() { // configure GUI window.setSize(WINDOW_WIDTH, WINDOW_HEIGHT); window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); legendArea.setEditable(false); legendArea.setLineWrap(true); legendArea.setWrapStyleWord(true); legendArea.setBackground(window.getBackground()); chillText.setEditable(false); chillText.setBackground(Color.WHITE); Dangers of an editable legend Line wrapping in the middle of a word Program Windchill.java constructor public Windchill() { // configure GUI window.setSize(WINDOW_WIDTH, WINDOW_HEIGHT); window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); legendArea.setEditable(false); legendArea.setLineWrap(true); legendArea.setWrapStyleWord(true); legendArea.setBackground(window.getBackground()); chillText.setEditable(false); chillText.setBackground(Color.WHITE); Bad line wrapping A JLabel is noneditable by the user By default the text field of a JTextField is editable by the user Program Windchill.java constructor public Windchill() { // configure GUI ... // register event listener runButton.addActionListener(this); Run button actionevent handling Act ion event s are sent t o regist ered act ion list eners An Act ionList ener has an act ionPerform er( ) m et hod t hat handles t he class specific act ivit y GUI : Action Listener actionPerformer() Method Action Event Get data entries from temperature and windspeed data areas Compute windchill according to the Weather Service formula Display result to windchill data area When t he run but t on is clicked, it dispat ches an act ion event Program Windchill.java constructor public Windchill() { // configure GUI ... // register event listener ... // add components to container Container c = window.getContentPane(); c.setLayout(LAYOUT_STYLE); c.add(legendArea); c.add(fahrTag); c.add(fahrText); c.add(windTag); c.add(windText); c.add(chillTag); c.add(chillText); c.add(runButton); Program Windchill.java constructor public Windchill() { // configure GUI ... // register event listener ... // add components to container ... // make GUI visible window.setVisible(true); Laying out the GUI components Top to bottom, left to right Program Windchill.java action performer public void actionPerformed(ActionEvent e) { // get user's responses // compute windchill } // display windchill Program Windchill.java action performer public void actionPerformed(ActionEvent e) { // get user's responses String response1 = fahrText.getText(); double t = Double.parseDouble(response1); String response2 = windText.getText(); double v = Double.parseDouble(response2); // compute windchill } // display windchill Program Windchill.java action performer Program Windchill.java action performer public void actionPerformed(ActionEvent e) { // get user's responses String response1 = fahrText.getText(); double t = Double.parseDouble(response1); String response2 = windText.getText(); double v = Double.parseDouble(response2); // compute windchill double windchillTemperature = 0.081 * (t 91.4) ...

Find millions of documents on Course Hero - Study Guides, Lecture Notes, Reference Materials, Practice Exams and more. Course Hero has millions of course specific materials providing students with the best way to expand their education.

Below is a small sample set of documents:

UVA - CS - 101
Fall 2004 - CS 101: Test 1Name _UVA Email ID _I. Computing and programming fundamentals1. (4 points) Give two examples of non-PC computing devices.Part I Part II Part III2. (4 points) What does Java program compilation do?Total3. (4 poin
UVA - CS - 101
Fall 2004 - CS 101: Test 3Name _UVA Email ID _Page 1 _ / 10 1. (Bonus 2 points) What is your section? 101 Page 4 _ / 17 101E Page 5 _ / 25 Page 6 _ / 20 Page 2 _ / 10 Page 3 _ / 18Total _ /100 2. (5 points) What is the output of the following c
UVA - CS - 101
CS 101 Exam 1 Spring 200Email Id _ Name _This exam is open text book and closed notes. Different questions have different points associated with them with later occurring questions having more worth than the beginning questions. Because your goal
UVA - CS - 101
CS 101 / CS 101-Ehttp:/www.cs.virginia.edu/~cs101M/W 2:00-3:15 CHM 402 / MEC 205Instructors: CS 101 Aaron Bloomfield http:/www.cs.virginia.edu/~asbCS 101-E James Cohoon http:/www.cs.virginia.edu/~cohoonOffice: Olsson Hall, room 228D Office: O
UVA - CS - 101
Take care with floating-point valuesConsider double a = 1; double b = 0.1 + 0.1 + 0.1 + 0.1 + 0.1 + 0.1 + 0.1 + 0.1 + 0.1 + 0.1 double c = .9999999999999999; Two true expressions! c = b b != a Two false expressions! a = b b != c Problem lies with th
UVA - CS - 101
Testing and ExceptionsException Abnormal event occurring during program execution Examples Manipulate nonexistent files File file = new File(s); Scanner fileIn = new Scanner(file); Improper array subscripting int[] a = new int[3]; a
UVA - CS - 101
BooleanvaluesGatewaytodecisionmakingBackground Ourproblemsolvingsolutionssofarhavethestraightlineproperty TheyexecutethesamestatementsforeveryrunoftheprogrampublicclassDisplayForecast /main():applicationentrypoint publicstaticvoidmain(String[]a
UVA - CS - 101
Cir cleKeeps on r ol l i ng Pr oblem design a cir cle r epr esent at ionSome possi bl e questi ons to ask What ki nd of ci r cl e? Why not use an exi sti ng ci r cl e r epr esentati on? What pl ans do you have for the ci r cl e? What
UVA - CS - 101
ClassesPreparation Scenesofarhasbeenbackgroundmaterialandexperience Computingsystemsandproblemsolving Variables Types Inputandoutput Expressions Assignments Objects StandardclassesandmethodsReady ExperiencewhatJavaisreallyabout Designa
UVA - CS - 101
Review for exam 1CS 101 Aaron Bloomfield1Todays lectureAn overview of the review sections of chapters 1-3 Stop me if you want me to go over something in more detail!2Material you may not be comfortable withConstructorsI know there is a
UVA - CS - 101
Iteration 1Java loopingOptions while dowhile for Allow programs to control how many times a statement list is executed 2AveragingProblem Extract a list of positive numbers from standard input and produce their average Number
UVA - CS - 101
Programming with methods and classes 1MethodsInstance (or member) method Operates on a object (i.e., and instance of the class)String s = new String("Help every cow reach its " + "potential!"); int n = s.length(); Instance method
UVA - CS - 101
Using ObjectsChapter 3 Spring 2005 CS 101 Aaron Bloomfield 1About the assignment statementAssign the value 5 to the variable x int x; x = 5; 5 = x; NOT VALID! This is not a mathematical equals It's a Java assignment The variable you wan
UVA - CS - 101
JavabasicsInclassquiz What aretherule for an ide s ntifie in Java? r In what m thod doe a programbe What is there e s gin? turn typeof that m thod? What e param te doe it re e r(s) s quire ? What is thee xpone ntiation ope rator in Java? How do w
UVA - CS - 101
CS 101Chapter 1: Background Spring 2005 Aaron Bloomfield1Let's beginGoalTeach you how to program effectivelySkills and information to be acquired Mental model of computer and network behavior Problem solving Object-oriented design Jav
UVA - CS - 101
StaplesareourstapleBuilding upon our solutionWhydidthisprogramworkpublicclassStaplerSimulation{ publicstaticvoidmain(String[]args){ StaplermyStapler=newStapler(); System.out.println(myStapler); myStapler.fill(); System.out.println(myStapler); my
UVA - CS - 101
Arrays 1BackgroundProgrammer often need the ability to represent a group of values as a list List may be onedimensional or multidimensional Java provides arrays and the collection classes The Vector class is an example of a collection cla
UVA - CS - 101
ArraysContinued 1Consideredint[] v = new int[10]; int i = 7; int j = 2; int k = 4; v[0] = 1; v[i] = 5; v[j] = v[i] + 3; v[j+1] = v[i] + v[0]; v[v[j] = 12; System.out.println(v[2]); v[k] = stdin.nextInt();v 1v[0]0v[1]8v[2]6v[3]3v
UVA - CS - 101
Decisions,decisions,decisionsChapter5 Spring2005 CS101 AaronBloomfield1BackgroundOurproblemsolvingsolutionssofarhavethestraightlineproperty TheyexecutethesamestatementsforeveryrunoftheprogrampublicclassDisplayForecast /main():applicatione
UVA - CS - 101
Page 2Question 2 No partial creditQuestion 3 No partial creditQuestion 4 No partial creditQuestion 5 No partial creditQuestion 6 -1 if float instead of doubleQuestion 7 -1 if the word 'swap' was mentioned -3 if there are no words
UVA - CS - 101
A B CD E FThis file has 38 characters.
UVA - CS - 101
ABCDEFThisfilehas30characters.
UVA - CS - 415
Fortran lectureFortran history Why do we care? o Was one of the most influential programming languages of all time o It's development mirrors PL evolution o Was the de facto programming languages for many years o Was the first high level language
UVA - CS - 101
Spring 2007 CS 101EMichele CoBoolean Expressions, Precedence, and If StatementsDescription: The following questions demonstrate key concepts related to evaluating Boolean expressions and evaluation precedence. Directions: Discuss your reasoning
UVA - CS - 101
CS 101 Spring 2006 Final ExamName: _Email ID: _This exam is open text book but closed-notes, closed-calculator, closed-neighbor, etc. Unlike the midterm exams, you have a full 3 hours to work on this exam. Please sign the honor pledge here:Pa
UVA - CS - 101
CS 101 Spring 2007 Midterm 1Name: _Email ID: _You only need to write your name and e-mail ID on the first page. This exam is CLOSED text book, closed-notes, closed-calculator, closed-neighbor, etc. Questions are worth different amounts, so be s
UVA - CS - 101
CS 101 Spring 2006 Midterm 3Name: _Email ID: _This exam is open text book but closed-notes, closed-calculator, closed-neighbor, etc. Questions are worth different amounts, so be sure to look over all the questions and plan your time accordingly
UVA - CS - 101
CS 101 Spring 2007 Midterm 2Name: _Email ID: _You only need to write your name and e-mail ID on the first page. This exam is CLOSED text book, closed-notes, closed-calculator, closed-neighbor, etc. Questions are worth different amounts, so be s
UVA - CS - 101
CS 101 Fall 2006 Midterm 3Name: _Email ID: _You only need to write your name and e-mail ID on the first page. This exam is CLOSED text book, closed-notes, closed-calculator, closed-neighbor, etc. Questions are worth different amounts, so be sur
UVA - CS - 101
CS 101 Fall 2006 Final ExamName: _Email ID: _You only need to write your name and e-mail ID on the first page. This exam is CLOSED text book, closed-notes, closed-calculator, closed-neighbor, etc. Questions are worth different amounts, so be su
UVA - CS - 101
CS 101 Fall 2006 Midterm 2Name: _Email ID: _You only need to write your name and e-mail ID on the first page. This exam is CLOSED text book, closed-notes, closed-calculator, closed-neighbor, etc. Questions are worth different amounts, so be sur
UVA - CS - 101
CS 101 & 101-ESpring 2007 http:/www.cs.virginia.edu/~cs101 CS 101: M/W/F 3:00-3:50 in CHM 402 CS 101-E: M/W 2:00-3:15 in MEC 205Instructors: CS 101 Aaron Bloomfield http:/www.cs.virginia.edu/~asbCS 101-E Michele Co http:/www.cs.virginia.edu/~mc2z
UVA - CS - 101
Inheritance and PolymorphismChapter 11 Spring 2007 CS 101 Aaron Bloomfield 1This section is not required material!A note about inheritance. It's not normally covered in 101 It will be gone over in more detail in CS 201 Ask questions if yo
UVA - CS - 101
MethodsChapter 5 Spring 2007 CS 101 Aaron Bloomfield 1PreparationScene so far has been background material and experience Computing systems and problem solving Variables Types Input and output Expressions Assignments Using objects
UVA - CS - 101
Review for Midterm 3CS 101 Spring 2007 1Topic CoverageLoops Chapter 4 Methods Chapter 5 Classes Chapter 6, Designing and creating classes Chapter 9, Static fields and methods, wrapper classes Arrays Chapter 8 2ClassesCircl
UVA - CS - 101
ReviewforExam1Spring2007 CS101/CS101ETodaysclassAnoverviewofchapters13 Stop me if you want me to go over something in moredetail!2Chapter13IntroComputersthinkinbits(1or0)00101001=81Eightbitsperbyte 1024bytes=1Kb 1024
UVA - CS - 101
Course SummaryCourse Summary Spring 2007 CS 101 Aaron Bloomfield 1Course Reflection2Course goalsObjectives: Students who complete the course will: Understand fundamentals of programming such as variables, conditional and iterati
UVA - CS - 101
CS 101Chapter 1: Introduction Aaron Bloomfield Spring 2007 Let's beginGoalTeach you how to program effectivelySkills and information to be acquired What the heck all this means Problem solving Objectoriented design Java 2So,
UVA - CS - 101
CS 101 Exam 2 Spring 2005Email Id _ Name _This exam is open text book and closed notes. Different questions have different points associated with them. Because your goal is to maximize your number of points, we recommend that you do not spend too
UVA - CS - 101
CS 101 Final Exam Fall 2004Email Id _Name _This exam is open book. Each question is worth 3 points.Page 1 Page 2 Page 3 Page 4 Page 5 Page 6 Page 7 Page 8 Total _ / 15 _ / 15 _ / 12 _ / 18 _ / 15 _ / 9 _ / 12 _ / 6 _ / 100 (maximum is 102)1. A
UVA - CS - 101
CS 101 Exam 1 Spring 200Email Id _ Name _This exam is open text book and closed notes. Different questions have different points associated with them with later occurring questions having more worth than the beginning questions. Because your goal
UVA - CS - 101
CS 101 (Fall 05) Exam 1 Grading Guidelines Question 1: 2 points All or nothing Question 2: 2 points 1 point for each column Questions 3-8: 3 points -2 for type error -1 for math error -2 for associativity error -1 for forgetting the .0 for a float/do
UVA - CS - 101
CS 101 Final Exam Grading GuidelinesQuestions 1 & 2: all or nothing Question 3 -1 for wrong modifiers (static, public, etc.) per variable to a max of -3 -4 for no head/tail variables -3 for missing a variable (head, tail, etc) if resulting class doe
UVA - CS - 101
CS 101 Exam Regrade Request FormName: UVa e-mail ID: Exam: Question(s) to be regraded: Action (To be filled in by TA/Grader): a. No Change b. Revised grade:Reasons for Regrade Request: a. Incorrect total. b. Problem (or part thereof) was overlooke
UVA - CS - 101
CS 101 Fall 2005 Midterm 3Name: _Email ID: _This exam is open text book but closed-notes, closed-calculator, closed-neighbor, etc. Questions are worth different amounts, so be sure to look over all the questions and plan your time accordingly.
UVA - CS - 101
CS 101 Fall 2005 Midterm 2Name: _Email ID: _This exam is open text book but closed-notes, closed-calculator, closed-neighbor, etc. Questions are worth different amounts (in particular, the final two questions are worth substantially more than a
UVA - CS - 101
CS 101 Midterm 3 Grading GuidelinesQuestions 1 & 2: All or nothing, as long as they entered a value Question 3 (top of page 2: there were two questions labeled as question 3): -2 for each missing i = 2 -2 for missing int[] c. Note that they don't ha
UVA - CS - 101
Course SummaryCourse Summary Fall 2005 CS 101 Aaron Bloomfield 1Course Reflection2Course goalsObjectives: Students who complete the course will: Understand fundamentals of programming such as variables, conditional and iterative
UVA - CS - 101
TheStackClassFinalReview Fall2005 CS101 AaronBloomfield1MotivationSameasforVectors Wewantaneasywaytostoreelementsinaobjectwithouthaving toworryaboutmanipulatingarrays2PropertiesofourStackclassItneedstohaveanarraytoholdthevalues T
UVA - CS - 101
Programmingwith methodsandclassesChapter7 Fall2005 CS101 AaronBloomfield1Static vs. non-static2MethodsInstance(ormember)method Operatesonaobject(i.e.,andinstanceoftheclass)Strings=newString("Helpeverycowreachits" +"potential!"); intn
UVA - CS - 101
CS 101Daily AnnouncementsMonday, 29 August 2005 Everybody should register for a lab section My first screw-up: The final exam is on a Tuesday, 13 Dec TAs and office hours are on the website First homework will be out later this week My offi
UVA - CS - 101
IterationChapter 6 Fall 2005 CS 101 Aaron Bloomfield 1Java loopingOptions while dowhile for Allow programs to control how many times a statement list is executed 2Averaging values3AveragingProblem Extract a list of positi
UVA - CS - 101
Java basicsChapter 2 Spring 2005 CS 101 Aaron Bloomfield 1DisplayForecast.java/ Authors: J. P. Cohoon and J. W. Davidson / Purpose: display a quotation in a console window public class DisplayForecast {Three comments / method main(): app
UVA - CS - 202
Growth of FunctionsCS 202 Epp, section ? Aaron Bloomfield1How does one measure algorithms We can time how long it takes a computer What if the computer is doing other things? And what happens if you get a faster computer? A 3 Ghz Windows mac
UVA - CS - 201
CS201: SW Development Methods Analysis of Algorithms Reading: Chapter 5 of MSD text Except Section 5.5 on recursion (next unit)Goals for this Unit Begin a focus on data structures and algorithms Understand the nature of the performance of al
UVA - CS - 201
Lecture 7: A Tale of Two Graphs (and a tree)CS201J: Engineering Software University of Virginia Computer ScienceDavid Evanshttp:/www.cs.virginia.edu/evansGraph ADTpublic class Graph { / OVERVIEW: / A Graph is a mutable type that
UVA - CS - 201
Lecture 7: A Tale of Two GraphsCS201j: Engineering Software University of Virginia Computer ScienceDavid Evanshttp:/www.cs.virginia.edu/~evansGraph ADTpublic class Graph { / OVERVIEW: / A Graph is a mutable type that / re
UVA - P - 211
Senior Citizens in Households Below the Poverty LevelBase FeaturesStudy NeighborhoodCity-County Boundary CityRailroadsSelected Major RoadsPercent of Senior Citizens in Households Below the Poverty Level by Block Groups0% - 3% 4% - 9% 10% -
UVA - P - 211
3899500.000000173179159177198 189A184 188187 191204 243 242 240196199 202 208 212213 221 215 216 224 225 220 232 233 228 234 251 2541 18623 4 190 2032001811823899250.000000239235B258 257 273 278281259 26726026
UVA - P - 211
Mapping of Residents Whose Travel to Work is 30 Minutes or Less by Way of Public Transportation in the West Main St. AreaPercentage of Residents Traveling to Work Within 30 Mins. Compared to All Other Means and Overall TimePercentage of Residents T
UVA - P - 211
Mapping for All Residents Whose Travel Time to Work is 30 Minutes or Less in the West Main St. AreaPercentage of Residents Whose Travel to Work Was Within 30 Minutes in Block GroupsCity-Wide ComparisonBase FeaturesStudy Neighborhood CityRailro