Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Task 5. A Short Pause in Coding: Getting The Screen Size Switch roles. The driver should now navigate and the navigator should now drive. The

Task 5.

A Short Pause in Coding: Getting The Screen Size Switch roles. The driver should now navigate and the navigator should now drive. The driver should send their code to the navigator, either by saving the java file to their Google drive and sharing it, or by copying the code of the Java file to a shared Google doc. Then the new driver can launch DrJava and either load the shared file or copy in the shared code. Then change so the new driver is now sharing their screen. In last week's lab, you had to move a window to the edge of the screen. This was challenging because you probably did not know the screen size of your monitor. Java has pre-defined classes that can provide you with the screen size. You will use them in this lab to help you with your tasks. Toolkit is a pre-defined class that is used to manipulate the computer's desktop. One of the useful methods of Toolkit is getScreenSize which returns an object of type Dimension. Dimension represents a 2-dimensional coordinate. Before you code with these classes, you should practice using them. Type the following code into the Interactions pane (not in the editor). Of course, before you can use the classes, you have to import them! import java.awt.Dimension; import java.awt.Toolkit; Now you can use these classes: Toolkit kit = Toolkit.getDefaultToolkit(); Dimension d = kit.getScreenSize(); The first line calls a method of the Toolkit class that creates and returns a Toolkit object of the proper type for your system, and this object (or really its location in memory) is stored in the variable called kit. The second line calls the getScreenSize method of Toolkit on the Toolkit object and stores the reference to the returned Dimension in a variable called d. Now you can access the values of the Dimension through either its methods or its fields. Type the following into the interactions pane. Remember to omit the semicolons so that you can see the values of these expressions. d.getWidth() d.getHeight() d.width d.height So, you can use either the methods or the fields of Dimension to get the screen size. Note that the methods have a return type of double while the type of the fields is int. It does not matter which you use, but depending on what you decide you may need to use a typecast.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Sams Teach Yourself Beginning Databases In 24 Hours

Authors: Ryan Stephens, Ron Plew

1st Edition

067232492X, 978-0672324925

More Books

Students also viewed these Databases questions

Question

7. What is wrong with thinking in systems terms?

Answered: 1 week ago

Question

A variable of a primitive type can never be empty. true or false?

Answered: 1 week ago

Question

Tell the merits and demerits of Mendeleev's periodic table.

Answered: 1 week ago

Question

What are Decision Trees?

Answered: 1 week ago

Question

What is meant by the Term Glass Ceiling?

Answered: 1 week ago