Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please can someone help on this code. I keep getting error on this constructor on MApp code: public void Circle() { g.fillOval(0, 0, s,

Please can someone help on this code. I keep getting error on this constructor on MApp code:

"

public void Circle()

{

g.fillOval(0, 0, s, s);

}

Here is the complete code include the main.

import java.awt.GridBagLayout;

import java.io.PrintWriter;

import java.util.Scanner;

import javax.swing.JFrame;

import javax.swing.JPanel;

public class Shpaes {

public static JFrame window = new JFrame("Shapes");

public static JPanel panel = new JPanel(new GridBagLayout());

public static void main(String[] args) {

window.setBounds(0,0,300,300);

window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

window.add(panel);

MApp m = new MApp();

m.setBounds(100,100,100,100);

window.add(m);

Draw d = new Draw(panel);

d.setBounds(0,0,window.getWidth(),90);

window.add(d);

window.setVisible(true);

}

}

import java.awt.Color;

import java.awt.Graphics;

import javax.swing.JFrame;

import javax.swing.JPanel;

import java.awt.*;

import java.awt.event.*;

import javax.swing.*;

public class MApp extends JPanel implements MouseListener {

private static final String O = null;

private static final String s = null;

private boolean clicked;

private Rectangle r;

public MApp() {

clicked = false;

r = new Rectangle(15, 15, 50, 50);

addMouseListener(this);

}

public void paintComponent(Graphics g) {

if(clicked) {

g.setColor(Color.BLUE);

}

else

{

g.setColor(Color.RED);

}

g.fillRect((int)r.getX(), (int)r.getY(),

(int)r.getWidth(), (int)r.getHeight());

}

public void mouseClicked (MouseEvent e) {

Point p = new Point(e.getX(), e.getY());

if(r.contains(p))

{

clicked =!clicked;

}

repaint();

}

public void Circle()

{

g.fillOval(O, O, s, s);

}

public void mousePressed (MouseEvent event) {}

public void mouseReleased (MouseEvent event) {}

public void mouseEntered (MouseEvent event) {}

public void mouseExited (MouseEvent event) {}

}

import java.awt.Color;

import java.awt.FlowLayout;

import java.awt.GridBagConstraints;

import java.awt.GridBagLayout;

import java.awt.Panel;

import java.awt.event.ActionEvent;

import java.awt.event.ActionListener;

import javax.swing.ButtonGroup;

import javax.swing.GroupLayout;

import javax.swing.JButton;

import javax.swing.JCheckBox;

import javax.swing.JLabel;

import javax.swing.JPanel;

import javax.swing.JRadioButton;

import javax.swing.JTextField;

public class Draw extends JPanel implements ActionListener {

JTextField tfInfo;

JLabel lblColor, lblShapes;

JCheckBox cbRed, cbBlue;

ButtonGroup shapes;

JRadioButton rbCircle, rbSquare;

JButton btnSubmit;

public Draw(JPanel panel) {

GridBagConstraints c = new GridBagConstraints();

tfInfo = new JTextField("Color", 15);

tfInfo = new JTextField("Shapes", 50);

lblColor = new JLabel("Colors");

cbRed = new JCheckBox("Red");

cbBlue = new JCheckBox("Blue");

lblShapes = new JLabel("Shapes");

shapes = new ButtonGroup();

rbCircle = new JRadioButton("Circle");

rbSquare = new JRadioButton("Square");

btnSubmit = new JButton("Draw");

btnSubmit.addActionListener(this);

this.setBackground(Color.WHITE);

add(lblColor);

add(cbRed);

add(cbBlue);

add(lblShapes);

add(rbCircle);

add(rbSquare);

add(btnSubmit);

shapes.add(rbCircle);

shapes.add(rbSquare);

}

public void actionPerformed(ActionEvent a)

{

if(a.getSource() == btnSubmit)

{

if(cbRed.isSelected()&&cbBlue.isSelected())

{

if(rbCircle.isSelected())

{

}

else if (rbSquare.isSelected())

{

}

}

else if(cbRed.isSelected())

{

if(rbCircle.isSelected())

{

}

else if(rbSquare.isSelected())

{

}

}

else if(cbBlue.isSelected())

{

if(rbCircle.isSelected())

{

}

}

else if(rbSquare.isSelected())

{

}

}

repaint();

}

}

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

Step: 3

blur-text-image

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

Modern Dental Assisting

Authors: Doni Bird, Debbie Robinson

13th Edition

978-0323624855, 0323624855

Students also viewed these Programming questions