All Matches
Solution Library
Expert Answer
Textbooks
Search Textbook questions, tutors and Books
Oops, something went wrong!
Change your search query and then try again
Toggle navigation
FREE Trial
S
Books
FREE
Tutors
Study Help
Expert Questions
Accounting
General Management
Mathematics
Finance
Organizational Behaviour
Law
Physics
Operating System
Management Leadership
Sociology
Programming
Marketing
Database
Computer Network
Economics
Textbooks Solutions
Accounting
Managerial Accounting
Management Leadership
Cost Accounting
Statistics
Business Law
Corporate Finance
Finance
Economics
Auditing
Hire a Tutor
AI Tutor
New
Search
Search
Sign In
Register
study help
computer science
java concepts late objects
Questions and Answers of
Java Concepts Late Objects
In Worked Example 9.2, make the process method a default method of the Sequence interface.Data from Example 9.2,n this Worked Example, we investigate properties of number sequences. A number sequence
Write a method that takes an array of integers and a NumberFormatter object (from Exercise P9.22) and prints each number on a separate line, formatted with the given formatter. The numbers should be
What is the difference between a frame and a panel?
Write a program that shows a square frame filled with 100 buttons labeled 1 to 100. Nothing needs to happen when you press any of the buttons.
Write a program to plot the following face. Provide a class FaceViewer and a class FaceComponent.
From a programmer’s perspective, what is the most important difference between the user interface of a console application and a graphical application?
Draw a “bull’s eye”—a set of concentric rings in alternating black and white colors. Hint: Fill a black circle, then fill a smaller white circle on top, and so on. Your program should be
Why are separate viewer and frame classes used for graphical programs?
Enhance the ButtonViewer1 program in Section 10.2.1 so that it has two buttons, each of which prints a message “I was clicked n times!” whenever the button is clicked. Each button should have a
Write a program that draws a picture of a house. It could be as simple as the accompanying figure, or if you like, make it more elaborate (3-D, skyscraper, marble columns in the entryway, whatever).
What happens if you add a button and a label directly to a JFrame without using a JPanel? What happens if you add the label first? Try it out, by modifying the program in Section 10.1.2, and report
Extend Exercise P10.3 by supplying a drawHouse method in which you can specify the position and size. Then populate your frame with a few houses of different sizes.Data from Exercise P10.3Write a
What is an event object? An event source? An event listener?
Implement a ButtonViewer1 program as in Exercise E10.3 using only a single listener class. Hint: Pass the button label to the constructor of the listener.Data from Exercise E10.3Enhance the
Extend Exercise P10.4 so that you can make the houses appear in different colors. The color should be passed as an argument to the drawHouse method. Populate your frame with houses of different
Who calls the actionPerformed method of an event listener? When does the call to the actionPerformed method occur?
Enhance the ButtonViewer1 program so that it prints the date and time at which the button was clicked. System.out.println(new java.util.Date()) prints the current date and time.
Improve the output quality of the investment application in Section 10.3.2. Format the numbers with two decimal digits, using the String.format method. Set the font of the text area to a fixed width
You can exit a graphical program by calling System.exit(0). Describe how to provide an Exit button that functions in the same way as closing the window. Should you still call setDefaultCloseOperation
Write a program that draws a 3D view of a cylinder.
Write a program to plot the string “HELLO”, using only lines and circles. Do not call drawString, and do not use System.out. Make classes LetterH, LetterE, LetterL, and LetterO.
Write a graphical application simulating a bank account. Supply text fields and buttons for depositing and withdrawing money, and for displaying the current balance in a label.
Modify the drawItalianFlag method in How To 10.1 to draw any flag with three horizontal colored stripes. Write a program that displays the German and Hungarian flags.
Write a program that displays the Olympic rings. Color the rings in the Olympic colors. Provide a method drawRing that draws a ring of a given position and color.
Why are we using inner classes for event listeners? If Java did not have inner classes, could we still implement event listeners? How?
Write a graphical application for computing statistics of a data set. Supply a text field and button for adding floating-point values, and display the current minimum, maximum, and average in a label.
Write a program that prompts the user to enter an integer in a text field. When a Draw button is clicked, draw as many rectangles at random positions in a component as the user requested.
Write an application with three labeled text fields, one each for the initial amount of a savings account, the annual interest rate, and the number of years. Add a button “Calculate” and a
Write a program that asks the user to enter an integer n into a text field. When a Draw button is clicked, draw an n-by-n grid in a component.
What is the difference between a label, a text field, and a text area?
Write a program that has a Draw button and a component in which a random mixture of rectangles, ellipses, and lines, with random positions, is displayed each time the Draw button is clicked.
Name a method that is declared in JTextArea, a method that JTextArea inherits from JTextComponent, and a method that JTextArea inherits from JComponent.
Write a graphics program that draws your name in red, contained inside a blue rectangle. Provide a class NameViewer and a class NameComponent.
Make a bar chart to plot the following data set. Label each bar. Provide a class BarChartViewer and a class BarChartComponent. Bridge Name Longest Span (ft) Golden Gate 4,200 Brooklyn 1,595 Delaware
Write a program that fills the window with a large ellipse, with a black outline and filled with your favorite color. The ellipse should touch the window boundaries, even if the window is resized.
Implement a graphical application that simulates a cash register. Provide a text field for the item price and two buttons for adding the item to the sale, one for taxable items and one for nontaxable
How would you modify the chart component in Section 10.4.3 to draw a vertical bar chart? (Careful: The y-values grow downward.)
Write a graphical application to implement a currency converter between euros and U.S. dollars, and vice versa. Provide two text fields for the euro and dollar amounts. Between them, place two
How do you specify a text color?
How would you modify the drawItalianFlag method in How To 10.1 to draw any flag with a white vertical stripe in the middle and two arbitrary colors to the left and right?
Can you use a flow layout for the components in a frame? If yes, how?
Write an application with three buttons labeled “Red”, “Green”, and “Blue” that changes the background color of a panel in the center of the frame to red, green, or blue.
Enhance the font viewer program to allow the user to select different font faces. Research the API documentation to find out how to find the available fonts on the user’s system.
What is the advantage of a layout manager over telling the container “place this component at position (x, y)”?
Write a graphical application that produces a restaurant bill. Provide buttons for ten popular dishes or drink items. (You decide on the items and their prices.) Provide text fields for entering less
What is the difference between the paintComponent and repaint methods?
Explain why the call to the getWidth method in the ChartComponent class has no explicit parameter.
Write a program that lets users design charts such as the following:Use appropriate components to ask for the x- and y-positions of the points, and to redraw the chart when the user adds an item.
What happens when you place a single button into the CENTER area of a container that uses a border layout? Try it out by writing a small sample program if you aren’t sure of the answer.
Write an application with three radio buttons labeled “Red”, “Green”, and “Blue” that changes the background color of a panel in the center of the frame to red, green, or blue.
Write a program that animates a car so that it moves across a frame.
What happens if you place multiple buttons directly into the SOUTH area, without using a panel? Try it out by writing a small sample program if you aren’t sure of the answer.
Write an application with three check boxes labeled “Red”, “Green”, and “Blue” that adds a red, green, or blue component to the background color of a panel in the center of the frame.
Write a program that animates two cars moving across a frame in opposite directions (but at different heights so that they don’t collide.)
What happens when you add a button to a container that uses a border layout and omit the position? Try it out and explain.
Write an application with a combo box containing three items labeled “Red”, “Green”, and “Blue” that change the background color of a panel in the center of the frame to red, green, or
Write a program that displays a scrolling message in a panel. Use a timer for the scrolling effect. In the timer’s action listener, move the starting position of the message and repaint. When the
What happens when you try to add a button to another button? Try it out and explain.
Write an application with a Color menu and menu items labeled “Red”, “Green”, and “Blue” that change the background color of a panel in the center of the frame to red, green, or blue.
Write a program that displays a number of rectangles at random positions. Supply menu items “Fewer” and “More” that generate fewer or more random rectangles. Each time the user selects
Write a program that prompts the user to enter the x- and y‑positions of a center point and a radius, using text fields.When the user clicks a “Draw” button, draw a circle with that center and
What is the difference between the grid layout and the grid bag layout?
Modify the program of Exercise E11.7 to replace the buttons with a slider to generate more or fewer random rectangles.Data from Exercise E11.7Write a program that displays a number of rectangles at
Write a program that allows the user to specify a circle by typing the radius in a text field and then clicking on the center. Note that you don’t need a “Draw” button.
Can you add icons to check boxes, radio buttons, and combo boxes? Browse the Java documentation to find out. Then write a small test program to verify your findings.
Write a program that allows the user to specify a circle with two mouse presses, the first one on the center and the second on a point on the periphery. Hint: In the mouse press handler, you must
What is the difference between radio buttons and check boxes?
Write a program that uses a timer to print the current time once a second. The following code prints the current time: Date now = new Date();System.out.println(now);The Date class is in the
Write a program that allows the user to specify a triangle with three mouse presses. After the first mouse press, draw a small dot. After the second mouse press, draw a line joining the first two
Why do you need a button group for radio buttons but not for check boxes?
Implement a program that allows two players to play tic-tac-toe. Draw the game grid and an indication of whose turn it is (X or O). Upon the next click, check that the mouse click falls into an empty
What is the difference between a menu bar, a menu, and a menu item?
Write a program that lets users design line charts with a mouse. When the user clicks above or below an existing point, the point is moved. (Allow for a few pixels of tolerance.) When the user clicks
When browsing through the Java documentation for more information about sliders, we ignored the JSlider constructor with no arguments. Why? Would it have worked in our sample program?
Write a program with a graphical interface that allows the user to convert an amount of money between U.S. dollars (USD), euros (EUR), and British pounds (GBP). The user interface should have the
How do you construct a vertical slider? Consult the Swing documentation for an answer.
Write a program with a graphical interface that implements a login window with text fields for the user name and password. When the login is successful, hide the login window and open a new window
Why doesn’t a JComboBox send out change events?
What component would you use to show a set of choices, as in a combo box, but so that several items are visible at the same time? Run the Swing demo application or look at a book with Swing example
How many Swing user-interface components are there? Look at the Java documentation to get an approximate answer.
How many methods does the JProgressBar component have? Be sure to count inherited methods. Look at the Java documentation.
What is the difference between an ActionEvent and a MouseEvent?
What information does an action event object carry? What additional information does a mouse event object carry?
Why does the ActionListener interface have only one method, whereas the MouseListener has five methods?
Enhance the invoice-printing program by providing for two kinds of line items: One kind describes products that are purchased in certain numerical quantities (such as “3 toasters”), another
Write a program that simulates a vending machine. Products can be purchased by inserting coins with a value at least equal to the cost of the product. A user selects a product from a list of
List the steps in the process of object-oriented design that this chapter recommends for student use.
The invoice-printing program is somewhat unrealistic because the formatting of the LineItem objects won’t lead to good visual results when the prices and quantities have varying numbers of digits.
Write a program to design an appointment calendar. An appointment includes the date, starting time, ending time, and a description; for example, Dentist 2017/10/2 17:30 18:30CS1 class 2017/10/3
Give a rule of thumb for how to find classes when designing a program.
The invoice-printing program has an unfortunate flaw—it mixes “application logic” (the computation of total charges) and “presentation” (the visual appearance of the invoice). To appreciate
Write a program that administers and grades quizzes. A quiz consists of questions. There are four types of questions: text questions, number questions, choice questions with a single answer, and
Give a rule of thumb for how to find methods when designing a program.
Write a program that teaches arithmetic to a young child. The program tests addition and subtraction. In level 1, it tests only addition of numbers less than ten whose sum is less than ten. In level
Produce a requirements document for a program that allows a company to send out personalized mailings, either by e-mail or through the postal service. Template files contain the message text,
After discovering a method, why is it important to identify the object that is responsible for carrying out the action?
Implement a simple e-mail messaging system. A message has a recipient, a sender, and a message text. A mailbox can store messages. Supply a number of mailboxes for different users and a user
Write a tic-tac-toe game that allows a human player to play against the computer. Your program will play many turns against a human opponent, and it will learn. When it is the computer’s turn, the
What relationship is appropriate between the following classes: aggregation, inheritance, or neither?a. University—Studentb. Student—TeachingAssistantc. Student—Freshmand. Student—Professore.
Modify the implementation of the classes in the ATM simulation in Worked so that the bank manages a collection of bank accounts and a separate collection of customers. Allow joint accounts in which
Showing 300 - 400
of 835
1
2
3
4
5
6
7
8
9