Starting Out with Java: From Control Structures through Data Structures (3rd Edition)
3rd Edition
ISBN: 9780134038179
Author: Tony Gaddis, Godfrey Muganda
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Concept explainers
Textbook Question
Chapter 12, Problem 1MC
With Swing, you use this class to create a frame.
- a. Frame
- b. SwingFrame
- c. JFrame
- d. JavaFrame
Expert Solution & Answer
Program Description Answer
To create a frame with the use of “Swing”, the programmer should use the “JFrame” class for the application.
Hence, correct answer is option “C”.
Explanation of Solution
“JFrame” class:
- The basic window of the swing application is known as frame.
- To create a frame, the programmer should create an object for the “JFrame” class in a Swing application.
- The package of “import javax.swing.JFrame*” should import in the program before using the “JFrame” class.
Syntax:
JFrame object_name=new JFrame();
Here,
- “JFrame” is the class name.
- “object_name” is the object name of the frame.
The programmer can use the object name of “JFrame” class to insert components in the window.
Want to see more full solutions like this?
Subscribe now to access step-by-step solutions to millions of textbook problems written by subject matter experts!
Students have asked these similar questions
Using comments within the code itself, can you provide an line by line explanation of the below JavaScript file? The file itself deals with WebGl if that helps you.
Please and thank you
JavaScript file:
"use strict";
var canvas;
var gl;
var positions = [];
var colors = [];
var numTimesToSubdivide = 3;
window.onload = function init()
{
canvas = document.getElementById("gl-canvas");
gl = canvas.getContext('webgl2');
if (!gl) alert("WebGL 2.0 isn't available");
//
// Initialize our data for the Sierpinski Gasket
//
// First, initialize the vertices of our 3D gasket
// Four vertices on unit circle
// Intial tetrahedron with equal length sides
var vertices = [
vec3(0.0000, 0.0000, -1.0000),
vec3(0.0000, 0.9428, 0.3333),
vec3(-0.8165, -0.4714, 0.3333),
vec3(0.8165, -0.4714, 0.3333)
];
divideTetra(vertices[0], vertices[1], vertices[2], vertices[3],
numTimesToSubdivide);
//
// Configure WebGL
//
gl.viewport(0, 0, canvas.width, canvas.height);
gl.clearColor(1.0, 1.0, 1.0,…
Does this display two images? And if so in which folder shall I add the gif files?
package javafxapplication3;
import javafx.application.Application;import javafx.scene.Scene;import javafx.scene.image.Image;import javafx.scene.image.ImageView;import javafx.scene.layout.GridPane;import javafx.stage.Stage;
public class JavaFXApplication3 extends Application {@Overridepublic void start(Stage primaryStage)throws Exception {GridPane gridPane = new GridPane();int flagCount = 0;for (int i = 0; i<2; i++) {for (int j = 0; j<2; j++) { gridPane.add(new ImageView(new Image("image/flag"+flagCount+".gif")), i, j);flagCount++;}}Scene scene = new Scene(gridPane, 1000, 500);primaryStage.setTitle("Flags");primaryStage.setScene(scene);primaryStage.show();}public static void main(String[]args) {Application.launch(args);}}
Which objects are added to others, from left to right, as in: A is added (→) to B which is added (→) to C, etc.?
Button → Stage → Scene → Pane
Button → Scene → Stage → Pane
Button → Scene → Pane → Stage
Button → Pane → Scene → Stage
Chapter 12 Solutions
Starting Out with Java: From Control Structures through Data Structures (3rd Edition)
Ch. 12.2 - Prob. 12.1CPCh. 12.2 - Prob. 12.2CPCh. 12.2 - Prob. 12.3CPCh. 12.2 - Prob. 12.4CPCh. 12.2 - Prob. 12.5CPCh. 12.2 - Prob. 12.6CPCh. 12.2 - If you are writing an event listener class for a...Ch. 12.2 - Prob. 12.8CPCh. 12.2 - Prob. 12.9CPCh. 12.3 - Prob. 12.10CP
Ch. 12.3 - Prob. 12.11CPCh. 12.3 - Which layout manager arranges components in a row,...Ch. 12.3 - Prob. 12.13CPCh. 12.3 - Prob. 12.14CPCh. 12.3 - Prob. 12.15CPCh. 12.3 - Prob. 12.16CPCh. 12.3 - Prob. 12.17CPCh. 12.4 - Prob. 12.18CPCh. 12.4 - Prob. 12.19CPCh. 12.4 - Prob. 12.20CPCh. 12.4 - Prob. 12.21CPCh. 12.4 - Prob. 12.22CPCh. 12.4 - Prob. 12.23CPCh. 12.4 - Prob. 12.24CPCh. 12.4 - Prob. 12.25CPCh. 12.5 - Prob. 12.26CPCh. 12.5 - Prob. 12.27CPCh. 12 - With Swing, you use this class to create a frame....Ch. 12 - Prob. 2MCCh. 12 - Prob. 3MCCh. 12 - Prob. 4MCCh. 12 - Prob. 5MCCh. 12 - Prob. 6MCCh. 12 - Prob. 7MCCh. 12 - Prob. 8MCCh. 12 - Prob. 9MCCh. 12 - Prob. 10MCCh. 12 - Prob. 11MCCh. 12 - Prob. 12TFCh. 12 - Prob. 13TFCh. 12 - Prob. 14TFCh. 12 - Prob. 15TFCh. 12 - Prob. 16TFCh. 12 - Prob. 17TFCh. 12 - Prob. 18TFCh. 12 - Prob. 19TFCh. 12 - Prob. 20TFCh. 12 - The following statement is in a class that uses...Ch. 12 - Prob. 2FTECh. 12 - Prob. 3FTECh. 12 - Prob. 4FTECh. 12 - Prob. 5FTECh. 12 - Prob. 1AWCh. 12 - Prob. 2AWCh. 12 - The variable myWindow references a JFrame object....Ch. 12 - Prob. 4AWCh. 12 - Prob. 5AWCh. 12 - Prob. 6AWCh. 12 - Prob. 7AWCh. 12 - Prob. 8AWCh. 12 - Prob. 9AWCh. 12 - Prob. 1SACh. 12 - Prob. 2SACh. 12 - Prob. 3SACh. 12 - Prob. 4SACh. 12 - Retail Price Calculator Create a GUI application...Ch. 12 - Prob. 2PCCh. 12 - Prob. 3PCCh. 12 - Travel Expenses Create a GUI application that...Ch. 12 - Prob. 5PCCh. 12 - Joes Automotive Joes Automotive performs the...Ch. 12 - Prob. 8PC
Knowledge Booster
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.Similar questions
- Write a program that displays four images of your choice in a grid pane. Javafx code: what is wrong with this code: Where shall I add the images which folder package javafxapplication1; import java.awt.Graphics;import java.awt.Image;import java.awt.image.ImageObserver;import java.awt.image.ImageProducer;import javafx.application.Application;import javafx.event.ActionEvent;import javafx.event.EventHandler;import javafx.scene.Scene;import javafx.scene.control.Button;import javafx.scene.image.ImageView;import javafx.scene.layout.GridPane;import javafx.scene.layout.StackPane;import javafx.stage.Stage; public class JavaFXApplication1 extends Application { @Overridepublic void start(Stage primaryStage) {// Place nodes in the pane// Create a pane to hold the images views// Create a pane to hold the images viewsGridPane pane = new GridPane();// Place nodes in the panepane.add(new ImageView(new Image("image1.gif")), 0, 0);pane.add(new ImageView(new Image("image2.gif")), 1, 0);pane.add(new…arrow_forwardYou don't need to make whole frame. Just give code snippets of asked things.Java ProgrammingSuppose the program is modified and a ProductDetails frame (in JavaFX/Java Swing) is added to the same application. Assume all components are added to the frame (ProductDetails) and event registration on jc (JComboBox) and jb (JButon) has been done. You are required to write an inner class (ProductDetailsHandler) to handle the events on the JComboBox and JButton. Upon selecting the type of the products from jc (CountedProduct, WightedProduct, Both), the application reads the products details from the file using readProduct() method corresponding to the selected product type and displays the details of each to the console. In case if the CheckBox ‘cb’ is checked, it takes the product ID from the user in ‘jt’ (JTextField) and upon pressing the ‘jb’ JButton, the details related to the product are retrieved from the file if it is CountedProduct only and displays on the console otherwise it displays…arrow_forwardPlease fix this so when i press Addorder i am able to add the data and the when i press save the data works and is stored on a table to see on the gui import java.awt.*; import javax.swing.*; import java.awt.event.ActionListener; import java.awt.event.ActionEvent; public class OrderEntryScreen extends JFrame { private JTextField txttableNumber; private JTextField txtcapacity; private JTextField txtsubtotal; private JTextField txtID; private JTextField txtestimatedWaitTime; private JTextField txtDate; private JTextField txtTime; private JButton SaveCommand; private JButton commandCloser; private JButton ClearAll; // private JButton MakeOrder; // private JButton MakeReservation; private JCheckBox checkBox; // variable that was stated to be added for checkbox private Driver orderlist1; // Variable for PersonListing so we can create the instance // private Driver orderlist1; private JPanel pnlCommand; private JPanel…arrow_forward
- It is recommended that you begin by practicing the moveVertical and slowMoveVertical methods. Figure out how to move the circle to the left by 70 pixels by using the moveHorizontal command.arrow_forwardcan someone help me resize the picture in Java. This is my code: import java.awt.*;import java.awt.image.BufferedImage;import java.io.File;import java.io.IOException;import javax.imageio.ImageIO; class ImageDisplayGUI { public static void main(String[] args) { SwingUtilities.invokeLater(() -> { createAndShowGUI(); }); } private static void createAndShowGUI() { JFrame frame = new JFrame("Bears"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setSize(800, 600); frame.setLayout(new BorderLayout()); // Load and display the JPG image try { BufferedImage image = ImageIO.read(new File("two bears.png")); // Replace with your image path ImageIcon icon = new ImageIcon(image); JLabel imageLabel = new JLabel(icon); frame.add(imageLabel, BorderLayout.CENTER); } catch (IOException e) { // Handle image loading error…arrow_forwardYou are creating a programme for several platforms, which is the issue. As a result, the code is dotted with several #ifdef lines. In fact, there are so many that the code is difficult to comprehend and the design is unsightly.For instance:void send_cmd(void){ send_cmd_start();#ifdef FE_TEXTURE send_texture();#endif /* FE_TEXTURE */#ifdef FE_COLOR send_background(); if (foreground != TRANSPARENT) send_foreground();#endif /* FE_COLOR */#ifdef FE_SIZE if (size != 0) send_size();#endif /* FE_SIZE */#ifdef FE_REPLAY if (prev_cmd == '\0') { prev_cmd = cur_cmd; prev_param = cur_param; }#endif /* FE_REPLAY */ send_cmd_end();}arrow_forward
- The following java code has many errors fix them so that the gui will work and output a new window with a slider! private static void buildGui() { JFrame frame = new JFrame(); JTextArea textArea = new JTextArea(5, 20); // set default font size to 10 to match JSlider starting position textArea.setFont(new Font(textArea.getFont().getName(), textArea.getFont().getStyle(), 10)); frame.add(textArea, BorderLayout.CENTER); // set up slider JSlider slider = new JSlider(JSlider.HORIZONTAL, 10, 30, 10); slider.setMajorTickSpacing(5); slider.setMinorTickSpacing(1); slider.setPaintTicks(true); slider.setPaintLabels(true); frame.add(slider, BorderLayout.SOUTH); // create and add change listener slider.addChangeListener(new ChangeListener() { @Override public void stateChanged(ChangeEvent e) { int fontSize = slider.getValue(); Font currentFont = textArea.getFont(); // get the current font and set the modified…arrow_forwardAdd a JTextField and a JTextArea to the frame. Initialize the field to an empty string and the text area to “||”. Modify the program so that the contents of the field are appended to the area each time the user clicks the button. For example, if the user enters “xxx” in the field and clicks the button three times, the area contains “||xxx||xxx||xxx||”. Go off this code: import javax.swing.*;import java.awt.Color;import java.awt.event.*; public class MyCustomFrame extends JFrame{ // instance variables - replace the example below with your own private JButton button; private JLabel label; // add two more instance variables for JTextField and a JTextArea t // ... private static final int FRAME_WIDTH = 800; private static final int FRAME_HEIGHT = 800; public MyCustomFrame() { JPanel panel = new JPanel(); panel.setBackground(Color.RED); button = new JButton("Push Me"); // create a listener object and add it to the button //...…arrow_forwardJava Questions - (Has 2 Parts). Based on each code, which answer out of the choices "A, B, C, D, E" is correct. Each question has one correct answer. Thank you. Part 1 - Which method do you need to invoke to display a frame (or a "form")? A. displayWindow = true;B. setVisible = true;C. setVisible(true);D. setDisplay(true);E. setShowForm(true); Part 2 - Which sets the frame (or a "form") width to 100 pixels and the height to 200 pixels? A. setSize(100, 200);B. setSize(200, 100);C. setDims(100, 200);D. setDimensions(200, 100);E. setWidth(100); setHeight(100);arrow_forward
- Can you show me where and how to add an image folder (Create a pane to hold the images views) with gif images on this code, to hold image views. code is below import javafx.application.Application;import javafx.scene.Scene;import javafx.scene.image.Image;import javafx.scene.image.ImageView;import javafx.scene.layout.GridPane;import javafx.stage.Stage; public class ex1401 extends Application {@Override public void start(Stage primaryStage) { /** pane to hold four images */GridPane p= new GridPane();p.add(new ImageView(new Image("image/uk.gif")), 0, 0);p.add(new ImageView(new Image("image/ca.gif")), 1, 0);p.add(new ImageView(new Image("image/china.gif")), 0, 1);p.add(new ImageView(new Image("image/us.gif")), 1, 1); Scene s= new Scene(p);primaryStage.setTitle("Exercise_14_01");primaryStage.setScene(s);primaryStage.show(); } }arrow_forwardHi, this is my full code I removed the code of the frame so I can capture everything. Now, what I want to do is to use "Another? Y/N" (encircled on the second image) when I hit key "Y" or "y" it will prompt the user back to the main menu (first image), and when I hit "N" or "n" it will close the program. Any help will be greatly appreciated.arrow_forwardCreate a login page and signup page and link them together using JAVAFX and FXML. Please show the code in order, print and image, and show the output in the answerarrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- EBK JAVA PROGRAMMINGComputer ScienceISBN:9781337671385Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENTEBK JAVA PROGRAMMINGComputer ScienceISBN:9781305480537Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENT
EBK JAVA PROGRAMMING
Computer Science
ISBN:9781337671385
Author:FARRELL
Publisher:CENGAGE LEARNING - CONSIGNMENT
EBK JAVA PROGRAMMING
Computer Science
ISBN:9781305480537
Author:FARRELL
Publisher:CENGAGE LEARNING - CONSIGNMENT
Time Complexity Analysis - How To Calculate Running Time | InterviewBit; Author: InterviewBit;https://www.youtube.com/watch?v=--oxG4Q1PA0;License: Standard YouTube License, CC-BY