Question

2. Find the error(s), correct it, and write output. Point 5 package javaapplication154 import javax.swing.* import java.awt.
0 0
Add a comment Improve this question Transcribed image text
Answer #1

package javaapplication154;

import javax.swing.*;
import java.awt.*;
import java.awt.Color; //no error but not needed to write since you have included java.awt.* which gets all classes and interfaces in awt package
public class JGraphicsPanel extends JPanel
{
public JGraphicsPanel(Color color)
{
this.setBackground(color);
}
public void paint(Graphics g) //g is reference to Graphics class
{
super.paint(g); //passing g as parameter to paint()
g.setColor(new Color(0,0,0)); //passing Color object as argument to setColor() method
//Calling the below methods of Graphics class using reference 'g'
g.fillOval(10,5,40,40);
g.fillOval(60,5,40,40);
}
}

package javaapplication154;

import java.awt.Color;
import javax.swing.JFrame;
public class JavaApplication154
{
public static void main(String[] args)
{
JFrame frame=new JFrame("Using colors");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JGraphicsPanel GraphicsPanel=new JGraphicsPanel(Color.RED);
frame.add(GraphicsPanel); //mandatory to add panel to frame
frame.setSize(400,180);
frame.setVisible(true); //sets frame visibility to true
}
}

Output

Using colors ion154.java Using colors on154

Add a comment
Know the answer?
Add Answer to:
2. Find the error(s), correct it, and write output. Point 5 package javaapplication154 import javax.swing.* import...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • There 2 parts to complete: import javax.swing.*; import java.awt.event.*; import java.awt.*; public class Q4 extends JFrame...

    There 2 parts to complete: import javax.swing.*; import java.awt.event.*; import java.awt.*; public class Q4 extends JFrame { private int xPos, yPos; public Q4() { JPanel drawPanel = new JPanel() { @Override public void paintComponent(Graphics g) { super.paintComponent(g); // paint parent's background //complete this: } }; drawPanel.addMouseListener(new MouseAdapter() { public void mouseClicked(MouseEvent evt) { //complete this :- set the xPos, yPos }    }); setContentPane(drawPanel); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setTitle("Mouse-Click Demo"); setSize(400, 250); setVisible(true); } public static void main(String[] args) { SwingUtilities.invokeLater(new Runnable() {...

  • Ex: In relation to image painting in frame, the following code is the use of getImage()...

    Ex: In relation to image painting in frame, the following code is the use of getImage() in toolkit. Modify the image() through ImageIcon and imageIO.read() of javax into a converted form using imageIO.read(). import java.awt.*; import javax.swing.*; public class FrameImage extends JPanel{ public void paint(Graphics g) { Toolkit toolkit = Toolkit.getDefaultToolkit(); Image image = toolkit.getImage("image/grapes.gif"); g.drawImage(image, 60, 40, this); } public static void main(String[] args) { JFrame frame = new JFrame(); FrameImage pannell = new FrameImage(); frame.add(pannell); frame.setTitle("image paint"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);...

  • package timing; import java.awt.event.*; import javax.swing.*; public class Timing implements ActionListener{     JButton button1;     JLabel...

    package timing; import java.awt.event.*; import javax.swing.*; public class Timing implements ActionListener{     JButton button1;     JLabel label1;     public int minutes=3;//initial time     public int time=minutes*60;//total amount of time in seconds only     public int seconds=time%60;     public String defaulttimeset="0"+Integer.toString(minutes)+":0"+Integer.toString(seconds);     public static void main(String[] args) {         Timing move=new Timing();         move.go();     }     public void go(){         JFrame frame=new JFrame();         frame.setBounds(50,50,400,400);         JPanel panel2=new JPanel();         button1=new JButton("Start Time");         panel2.add(button1);                 button1.setBounds(30,50,150,170);         frame.getContentPane().add(button1);...

  • The program given here will draw the Olympic logo. Modify the program as the following: 1.Change...

    The program given here will draw the Olympic logo. Modify the program as the following: 1.Change the class name to Test1OlympicYourFirstNameYourLastName 2.Change the OlympicRingPanel class name to OlympicRingPanelYourfirstNameYourLastName 3.Modify the program so that the first ring will be filled with random color with a random alpha value. I have shown 3 sample output here for your references. 4.Modify the paintComponent so your name will be displayed under the Olympic rings.The color of your name should be random color as well....

  • What is wrong with this code please. I need to draw CIRCLES in JFrame JAVA.  recursively Draw...

    What is wrong with this code please. I need to draw CIRCLES in JFrame JAVA.  recursively Draw a circle centered near the top of the JPanel After drawing a circle, your program should draw two more circles half way to the left and right of the circle just drawn and located "one level" lower in the JPanel. Do this drawing as long as the drawing would not be below the bottom of the JPanel Each newly drawn circle then follows the...

  • I am getting this Error can you please fix my Java code. import java.awt.Dialog; import java.awt.Label;...

    I am getting this Error can you please fix my Java code. import java.awt.Dialog; import java.awt.Label; import java.awt.TextArea; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map.Entry; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JPanel; public class Fall_2017 {    public TextArea courseInput;    public Label textAreaLabel;    public JButton addData;    public Dialog confirmDialog;    HashMap<Integer, ArrayList<String>> students;    public Fall_2017(){    courseInput = new TextArea(20, 40);    textAreaLabel = new Label("Student's data:");    addData = new JButton("Add...

  • import java.awt.*; import javax.swing.*; import java.awt.event.*; import javax.swing.BorderFactory; import javax.swing.border.Border; public class Q1 extends JFrame {...

    import java.awt.*; import javax.swing.*; import java.awt.event.*; import javax.swing.BorderFactory; import javax.swing.border.Border; public class Q1 extends JFrame {    public static void createAndShowGUI() {        JFrame frame = new JFrame("Q1");        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);        Font courierFont = new Font("Courier", Font.BOLD, 40);        Font arialFont = new Font("Arial", Font.BOLD, 40);        Font sansFont = new Font("Sans-serif", Font.BOLD, 20);        JLabel label = new JLabel("Enter a word"); label.setFont(sansFont);        Font font1 = new Font("Sans-serif", Font.BOLD, 40);       ...

  • tart from the following code, and add Action Listener to make it functional to do the...

    tart from the following code, and add Action Listener to make it functional to do the temperature conversion in the direction of the arrow that is clicked. . (Need about 10 lines) Note: import javax.swing.*; import java.awt.GridLayout; import java.awt.event.*; import java.text.DecimalFormat; public class temperatureConverter extends JFrame { public static void main(String[] args) {     JFrame frame = new temperatureConverter();     frame.setTitle("Temp");     frame.setSize(200, 100);     frame.setLocationRelativeTo(null);     frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);     frame.setVisible(true); }    public temperatureConverter() {     JLabel lblC = new...

  • PLEASE HELP I'M GETTING A "cannot find symbol - variable CENTER" ERROR: import javax.swing.*; import java.awt.*;...

    PLEASE HELP I'M GETTING A "cannot find symbol - variable CENTER" ERROR: import javax.swing.*; import java.awt.*; /** * Write a description of class FlowLayout here. * * @author (your name) * @version (a version number or a date) */ public class FlowLayout { // instance variables - replace the example below with your own JButton button1,button2,button3; JFrame jFrame;    /** * Constructor for objects of class FlowLayout */ FlowLayout() { // initialise instance variables jFrame= new JFrame("FlowLayout Example"); jFrame.setLayout(new FlowLayout(FlowLayout.CENTER));...

  • I need to implement game logic for tic tac toe in this code. Can someone help...

    I need to implement game logic for tic tac toe in this code. Can someone help me. It just needs to be a a player vs player again and ask if you want to play again. import javax.swing.*; import java.awt.*; import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; import java.awt.event.MouseListener; public class TicTacToe { public static void main(String[] args) { JFrame frame = new JFrame(" TicTacToe"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setSize(290, 300); Board board = new Board(); frame.add(board); frame.setResizable(false); frame.setVisible(true); } } class Board extends JComponent {...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT