Question 2: The following program is supposed to display a button in a frame, but the button doesn't display. What is the problem? How would you fix that? 1: import javax.swing.*; 2: 3: public class Test extends JFrame { 4: public Test () { 5: add( new JButton( "OK") ); 6: } 7: 8: public static void main ( String ] args ) { 9: JFrame frame = new JFrame(); %3D 10: frame.setSize( 100, 200 ); 11: frame.setVisible( true ); 12: } 13:}
Q: Question 2: Implement the ShoppingCart and Product class with necessary properties so that the given…
A: code is here
Q: So, apparently when I asked this before, I instead of actually getting an answer, I just got my own…
A: The above Java code was throwing an error due to the use of an assignment operator (=) instead of a…
Q: What is printed by the code below? Note: There are two separate classes here. public class…
A: Answer : the given code is in java here I Provide a typed code as well as the output of the code…
Q: Write a program to accept the length of and width of a rectangle using scanner class and display its…
A: Java has built in Scanner class which enables to accept user input. Java also supports inheritance…
Q: Write a java program that shows a square frame filled with 10 buttons labeled 1 to 10, when one of…
A: import javax.swing.*; import java.awt.*;import java.awt.event.*; public class Main implements…
Q: Using java, solve the following problem with JavaFX: Write program (Call the class Smiley) that…
A: JavaFX smile face
Q: Please broadly explain what the code in the driver class does for both of them. What do you think…
A: Please broadly explain what the code in the driver class does for both of them. In 1st driver…
Q: Write a javaFx program to make your own draw pictures. (The following pictures are some examples: be…
A: In general, a 2D shape is a geometrical figure that can be drawn on the XY plane, these include…
Q: The Character class is provided in the Javalibrary. Provide your own implementation for this class.…
A: Program Plan: Include necessary header files create a class MyCharacter declare the variable ch as…
Q: Run this code in netbeans and screenshot the run results: source code: import java.awt.*;…
A: Given: import java.awt.*; import javax.swing.*; public class RectangleMonday extends JFrame{ public…
Q: APEX - Salesforce Write an Apex Class to Multiply two numbes and show in the Console and please add…
A: Given: Write an Apex Class to Multiply two numbes and show in the Console and please add proper…
Q: I really need help with this JAVA lab. I'm not calling the methods correctly and cant figure out how…
A: 1. Format the data using String . format function a. %-20s means take 20 space and print the…
Q: There are four states in a class Pen. These states are “color” of type String, “ink” of color…
A: Given there are 4 states of Pen class. The states are color, ink, manufacturer, inkThickness
Q: There is a problem with my program. I need the JOptionpane to pop up when I run the program and…
A: The ask is to debug the program and fix the JOptionPane issue.
Q: The given Java program is called the ColorDialog. When running, the ColorDialog has a menubar and 25…
A: 1)The given question has required for the solution to be provided with the help of an Java…
Q: Can you tell me where the graphic code portion and how can I alter to make it just ask about…
A: The graphics code portion is Highlighted in the below code import java.util.*; import…
Q: Write a Java program that shows a square frame filled with 10 buttons labeled 1 to 10. Nothing needs…
A: import javax.swing.*; import java.awt.*;public class Main { public static void main(String[] args)…
Q: Write a program that will use WheelsFX shapes to create a Car. With circles, Rectangle and Squares.…
A: Lets discuss the solution in the next steps
Q: public static JigsawPuzzle (1 method1() return new JigsawPuzzle [) { new JigsawPuzzle(new…
A: It is defined as a picture of the state of the computer's memory at a specific point in time. There…
Q: I have to use Netbeans for this program I need help because the main string is calling from test…
A: The problem is that the program is giving the jlang error because the main method is not found. To…
Q: • Write a complete Java program that uses "NullPointerException" Attach your code along with the…
A: In java a NullPointerException is a type of RuntimeException that occurs when a program tries to…
Q: Implement the ShoppingCart and Product class with necessary properties so that the given output is…
A: Program: Start Create a class ShoppingCart with attributes cart, cartName Implement setCartName()…
Q: PLEASE ENSURE TO USE THE FRAMEWORK PROVIDED IN THE IMAGES, AND THAT IT WORKS WITH THE TESTER CLASS.…
A: CODE TEXT SO YOU DON'T HAVE TO TYPE :) public class Circuit { private int firstSwitchState; // 0…
Q: can you please, write it in java.scanner.util and make it so i can copy and past it, thank you.…
A: import java.util.*;import java.lang.*;import java.io.*; interface ColoredShape{ enum ShapeColor{…
Q: Write a program to accept the length of and width of a rectangle using scanner class and display its…
A: Please find the answer below
Q: I am not able to get the ID, it jumps straight to GPA, where did i mess up? This is my code :…
A: While entering the record for the student, the buffer for the input needs to be cleared. It can be…
Q: In this task by using java language you should create the moving box example belwo, then you should…
A: Our task is to using java language, you should create the moving box example belwo, then you should…
Q: definition for a simple Ebook. Two instance variables and one parameterless constructor are…
A: Solution : - As the problem statement is given here, the required java code is as given below. Java…
Q: Answer the prompt with given main method: Code: import java.awt.*; public class TestRandomWalker…
A: Actually, program is a executable software that runs on a computer.
Q: n Java. Instead of drawing the objects, please print the output of the objects. Bus airport =…
A: Bus airport = new Bus(); Bus school = new Bus(); Bus downtown; airport.passengers = 25;…
Q: Write a simple java program in which you have to implement all the java stringbuffer method listed…
A: Sample Response: //Java program to implement all the java stringbuffer methods such as capacity(),…
Q: Which of the following statements are true for Java? (You can select as many answers as you want O…
A: Interface doesnt hold by itself instance variables of its own as by default inside interface…
Q: The given Java program is called the ColorDialog. When running, the ColorDialog has a menubar and 25…
A: Solution:-- 1)The given question has required for the solution to be provided with the help of an…
Q: What is displayed by the following code segment? public class Widget { private int v1, v2; public…
A: the complete solution is given below:-
Q: 3. A JavaBean has the following component: private boolean test; Which two pairs of method…
A: your question is about Javabean. let's solve the question
Q: Write a test program called TestSquare that: Creates two Square objects: one object with side’s…
A: Since the Programming language is not mentioned in the question, we will answer this question in…
Q: import java.util.Scanner; public class LabProgram { public static void main(String[] args) {…
A: Actually, Java is a high level programming language. And also object oriented .It Is a platform for…
Q: Please help me with my assignment for computer science as I had all the dialog box pop up for me…
A: Given that Please help me with my assignment for computer science as I had all the dialog box pop up…
Q: Convert the following Java code in Chapel and add methods which would turn a lamp on and off, and…
A: It is defined as a parallel programming language developed by Cray. Its syntax is fairly similar to…
Q: Consider the program below. Replace the tags_??1_, _??2_and_???3_respectively, by filling in the…
A: ??1: @Override ??2: A a=new A(); a.foo(); ??3: myClassA.x
Q: ????????: Python question Write the Game class with the required properties to give the following…
A: Input : Partial python code along with the output. Output : Complete python code that includes…
Q: In Java fix this problem so that it can run. The flawed pieces are highlighted -Also, use char…
A: Required: In Java fix this problem so that it can run. The flawed pieces are highlighted -Also,…
Q: Write a test program called TestSquare that: Creates two Square objects: one object with side’s…
A: Note: Here you didn't mention any programming language so we writing the program in C++ Programming…
Q: This question is related from my previous question, when I compile this code it gave me several…
A: In your program, there is one error and one exception. The error is “Cannot find the symbol Date”.…
Q: The following is a class definition for a simple Ebook. So i need to write a second constructor that…
A: public class Main{ public static void main(String[] args) { Ebook e=new Ebook(); //create…
Q: animated house. import java.awt.Color; import java.awt.Font; import java.awt.Graphics; import…
A: void drawEmptyBoard(Graphics g) { int x=x_offset, y=y_offset; Color old_col=g.getColor();…
Q: Write a test program called TestSquare that: Creates two Square objects: one object with side's…
A: In this question, we are asked to create a test class of the square object in JAVA Code is in the…
Trending now
This is a popular solution!
Step by step
Solved in 2 steps with 1 images
- The first one is answered as follows. Help with the second one. package test;import javax.swing.*;import java.awt.*;import java.awt.event.*; public class JavaApplication1 { public static void main(String[] arguments) { JFrame.setDefaultLookAndFeelDecorated(true);JFrame frame = new JFrame("print X and Y Coordinates");frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setLayout(new BorderLayout());frame.setSize(500,400); final JTextField output = new JTextField();;frame.add(output,BorderLayout.SOUTH); frame.addMouseListener(new MouseListener() {public void mousePressed(MouseEvent me) { }public void mouseReleased(MouseEvent me) { }public void mouseEntered(MouseEvent me) { }public void mouseExited(MouseEvent me) { }public void mouseClicked(MouseEvent me) {int x = me.getX();int y = me.getY();output.setText("Coordinate X:" + x + "|| Coordinate Y:" + y);}}); frame.setVisible(true);}}14 given the following code, how are the components displayed? Given the following code import java.awt.*; import javax.swing.*; public class Test { public static void main(String[] args) { JFrame frame = new JFrame("My Frame"); frame.add(new JButton("Cancel")); frame.add(new JButton("OK")); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setSize(200, 200); frame.setVisible(true)%3; Activate Windows Go to Settings to activate WPlease help me fix this java code which is supposed to be a Pac-Man game Java program is below import java.awt.*; import javax.swing.JFrame.*; public class ManyPacMans extends JFrame { public void paint(Graphics g) { g.drawghostShape(60,30,40); setBackground(Color.BLUE); g.fillghostShape(130, 30,100, 80); g.drawghostShape(60,30,40); setBackground(Color.PINK); g.fillghostShape(130, 30,100, 80); g.drawghostShape(60,30,40); setBackground(Color.RED); g.fillghostShape(130, 30,100, 80); g.drawOvalpacman(30,130,50, 60); setForeground(Color.yellow); g.fillOval(130,130,50, 60); } public Ghost(String imgPath, int x, int y, int speed, boolean ip) { super(imgPath, new int[] {0,0}, GHOST_WIDTH, GHOST_HEIGHT, GHOST_FRAMERATE, x, y); super.addFramesForAnimation("scatter", "ghost_scatter.png", 0, 0, 22,0); super.speed = speed; startX = x; startY = y; scoreValue = 200; } public ManyPacMans() { initUI(); } private void initUI() { add(new…
- Please do not give solution in image format thanku packagecom.abc.base; public class MyDataTypes { public static void main(String[] args) { int a=10; int b=20; System.out.println("a="+a); System.out.println("b="+b); } } //swap the value between a and b without creating any third varialbe.Please help me fix the errors in this java program. I can’t get the program to work. There are two classes AnimatedBall and BouncingBall Class: AnimatedBall Import java.swing.*; import java.awt.*; import java.awt.event.*; public class AnimatedBall extends JFrame implements ActionListener { private Button btnBounce; // declare a button to play private TextField txtSpeed; // declare a text field to enter number private Label lblDelay; private Panel controls; // generic panel for controls private BouncingBall display; // drawing panel for ball Container frame; public AnimatedBall () { // Set up the controls on the applet frame = getContentPane(); btnBounce = new Button ("Bounce Ball"); //create the objects txtSpeed = new TextField("10000", 10); lblDelay = new Label("Enter Delay"); display = new BouncingBall();//create the panel objects controls = new Panel(); setLayout(new BorderLayout()); // set the frame layout controls.add (btnBounce); // add controls to panel controls.add…Please help me fix the errors in the java program below. There are two class AnimatedBall and BouncingBall import javax.swing.*;import java.awt.*;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;public class AnimatedBall extends JFrame implements ActionListener{private Button btnBounce; // declare a button to playprivate TextField txtSpeed; // declare a text field to enterprivate Label lblDelay;private Panel controls; // generic panel for controlsprivate BouncingBall display; // drawing panel for ballContainer frame;public AnimatedBall (){// Set up the controls on the appletframe = getContentPane();btnBounce = new Button ("Bounce Ball");//create the objectstxtSpeed = new TextField("10000", 10);lblDelay = new Label("Enter Delay");display = new BouncingBall();//create the panel objectscontrols = new Panel();setLayout(new BorderLayout()); // set the frame layoutcontrols.add (btnBounce); // add controls to panelcontrols.add (lblDelay);controls.add…
- Write this code to get 7 inputs: import javax.swing.*;import java.awt.*;import java.awt.event.*; class WeeMadLib implements ActionListener { JFrame wmlGame = new JFrame("Wee Mad Lib");JPanel gameBoard = new JPanel(new GridLayout(3,3)); JLabel subjectLabel = new JLabel("Subject");JLabel verbLabel = new JLabel("Verb");JLabel objectLabel = new JLabel("Object"); JLabel subject = new JLabel("My friend ");JTextField verb = new JTextField(25);String[] objectOptions = { " a ball."," chickens."," a kazoo.", " an igloo." };JComboBox object = new JComboBox(objectOptions); JButton clear = new JButton("Clear");JTextArea sentence = new JTextArea("My friend ___ ___.");JButton exit = new JButton("Exit"); public WeeMadLib() { wmlGame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); wmlGame.setSize(300,300); subjectLabel.setOpaque(true); subjectLabel.setBackground(new Color(0,255,255)); subjectLabel.setHorizontalAlignment(JLabel.CENTER); sentence.setEditable(false); sentence.setOpaque(false);…Java ProgramEdit this program that when you press the clear button, it actually clears the textfield and data of the previous numbers pressed.import java.awt.BorderLayout;import java.awt.Container;import java.awt.Dimension;import java.awt.GridLayout;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import java.util.ArrayList;import javax.swing.*;public class Pincode extends JPanel implements ActionListener {JLabel display, displayExtra;JButton numButton;JButton clr;JButton etr;String displayContent = "";String[] numPadContent = {"1", "2", "3", "4", "5", "6", "7", "8", "9", "CLEAR", "0", "ENTER"};ArrayList<JButton> buttonList;String PASSWORD = "061904";JFrame f;Pincode(Container pane) {pane.setPreferredSize(new Dimension(320, 335));display = new JLabel(displayContent);displayExtra = new JLabel(displayContent);display.setPreferredSize(new Dimension(320, 25));display.setBorder(BorderFactory.createLoweredBevelBorder());pane.add(display,…import java.util.Scanner;class BloodData { private static String bloodType; private static String rhFactor; public BloodData() { bloodType="O"; rhFactor="+"; } public BloodData(String bt, String rh) { bloodType = bt; rhFactor = rh; } public void display() { System.out.println(bloodType+rhFactor+" is added to the blood bank."); //prints message }} public class Main { public static void main(String[] args) { Scanner sc=new Scanner(System.in); //create Scanner instance System.out.print("Enter blood type of patient: "); String input1=sc.nextLine(); //accept input from user System.out.print("Enter the Rhesus factor (+ or -): "); String input2=sc.nextLine(); //accept input from user BloodData bd; //create instance if("".equals(input1) || "".equals(input2)) //if any of inputs is blank bd=new BloodData(); //allocates memory using default constructor else //if valid inputs bd=new BloodData(input1,input2); //allocates memory using parameterized constructor…
- How can you use: JOptionsPane.showInputDialog to use switch for names as a string. Example below but it does not work: import javax.swing.JOptionPane; class JOptionsPane { String name = JOptionsPane.showInputDialog(null, "Enter name");Switch(name);Case"Jeramy";Case"James";break;Case"Carl";break;Look at the following applet code snippet: 1 import javax.swing.*; 2 import java.awt.*; 3 public class GraphicsTest extends JApplet 4 { 5 public void init() 6 { 7 getContentPane().setBackground(Color.WHITE); 8 } 9 public void paint(Graphics g) 10 { 11 int[] xCoords = {20, 20, 60, 100, 140, 140, 100, 60}; 12 int[] ycoords = {20, 100, 140, 140, 100, 60, 20, 20}; 13 super.paint(g); 14 g.setColor(Color.YELLOW); 15 g.fillPolygon(xCoords, yCoords, 8); 16 g.setColor(color.BLACK); 17 g.setFont(new Font("SansSerif", Font.BOLD, 35)); 18 g.drawString("SLOW", 35, 95); 19 } 20 } How many vertices does the polygon have? Justify your answer.import java.awt.*;public class TestRandomWalker {public static final int STEPS = 500;public static void main(String[] args) {RandomWalker walker = new RandomWalker(); // instantiate Walker objectDrawingPanel panel = new DrawingPanel(500, 500);Graphics g = panel.getGraphics();// advanced features -- center and zoom in the imagepanel.getGraphics().translate(250, 250);panel.getGraphics().scale(4, 4);// make the walker walk, and draw its movementint prevX = walker.getX(); // initialize Walker displayint prevY = walker.getY();for (int i = 1; i <= STEPS; i++) {g.setColor(Color.BLACK);g.drawLine(prevX, prevY, walker.getX(), walker.getY()); // update Walker display walker.move(); // move Walker 1 stepprevX = walker.getX(); // update x valueprevY = walker.getY(); // update y valueg.setColor(Color.RED); g.drawLine(prevX, prevY, walker.getX(), walker.getY()); // update Walker display int steps = walker.getSteps(); // record Walker stepsif (steps % 10 == 0) {System.out.println(steps + "…