Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3998316
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T07:30:37+00:00 2026-05-20T07:30:37+00:00

I’m having two weird errors New error is when i tell java to draw

  • 0

I’m having two weird errors

New error is when i tell java to draw a string that displays the coordinateness of x and y, It doesn’t.

public void paint (Graphics g)
{
    super.paint (g);

   //System.out.println ("Boolean: " + this.closeDoors);


    g.drawString("("+x+","+y+")",x,y);
}

Link to my program if you to compile it.
http://hotfile.com/dl/107032853/c81d927/Pigment.java.html

This is my complete program

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.applet.Applet;
import java.awt.Graphics;

/**
 *
 * @author George Beazer
 */
public class Pigment extends JApplet 
{
    boolean closeDoors;
    private int x = 0;
    private int y = 0;


    public static void main(String [] args)
    {
            Pigment stuff = new Pigment();
    }
    public Pigment()

    {

        setBackground (Color.blue);
    }

    @Override
    public void init()
    {
         setLayout(new FlowLayout());
         addMouseListener(new MyMouseListener());
    }
    @Override
    public void paint (Graphics g)
    {
        super.paint (g);

       //System.out.println ("Boolean: " + this.closeDoors);


        g.drawString("("+x+","+y+")",x,y);
         if (x > 35)

            {
                            g.drawLine (35, 50, 570, 50);
                g.drawLine (35, 50, 250, 0);
                g.drawLine (250, 0, 570, 50);
                g.drawRect (50, 50, 500, 350);
                g.fillRect (100, 75, 80, 80);
                g.fillRect (400, 75, 80, 80);
                g.fillRect (240, 200, 125, 200);


            }

        else
            {        
            g.drawLine (35, 50, 570, 50);
            g.drawLine (35, 50, 250, 0);
            g.drawLine (250, 0, 570, 50);
            g.drawLine (180, 120, 100, 120);
            g.drawLine (400, 120, 480, 120);
            g.drawLine (140, 75, 140, 160);
            g.drawLine (450, 75, 450, 160);
            g.drawRect (50, 50, 500, 350);
            g.drawRect (100, 75, 80, 80);
            g.drawRect (400, 75, 80, 80);
            g.drawRect (240, 200, 125, 200);
            g.drawOval (330,280, 20, 20);
            }


    }
    private class MyMouseListener implements MouseListener
    {
        public void mouseClicked (MouseEvent e)
        {
            x = e.getX();
            y = e.getY();

        }

        public void mouseEntered (MouseEvent e)
        {


        }
        public void mouseExited(MouseEvent e){}
        public void mousePressed (MouseEvent e){

        }
        public void mouseReleased (MouseEvent e){}

    }

}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T07:30:38+00:00Added an answer on May 20, 2026 at 7:30 am

    With regards to your first question, the reason that you’re getting a compiler error here:

    if (x > 35)
    {
        g.drawLine (35, 50, 570, 50);
        g.drawLine (35, 50, 250, 0);
    
        repaint();
        break;  
    }
    

    Is that this break statement is not actually in a loop. In Java, you can break out of while, for, do...while, and switch statements, but not if statements. There’s not a particularly good reason for this – it’s mainly historical – but the compiler does indeed enforce it.

    Of the three aforementioned control structures, for, while, and do...while are referred to as loops because they execute code potentially many times. The break statement in this case is a way of saying “please abort execution of the current loop; I don’t want to run it any more.” Its opposite is continue, which means “please go to the next iteration of this loop.”

    The reason you can break out of a switch is because Java’s switch statement is based on the C programming language’s version of switch in which labels are “fall-through.” In this context, break means “I have finished executing all of the code I want to execute in this particular label; please get me out of this statement.” Interestingly, you can break out of a switch, but you can’t continue.

    However, you cannot break out of an if statement. There is no high-level reason for this, and in fact the language designers could just as easily have allowed this behavior to mean “stop executing this part of the if statement.” I think the reason they opted not to do this is that if statements have a sort of “implicit break” at the end of each handler. For example, if you write

    if (condition()) {
        // A
    } else {
        // B
    }
    // C
    

    Then after executing A, the control flow will immediately jump you to C, rather than falling through to the else handler.

    If you want to simulate a break out of of the middle of an if statement, you could do something like this:

    if (condition()) {
         // code
    
         if (someOtherCondition()) {
              // more code
         }
    }
    

    The idea here is that you run the if statement for some time, then decide using a second if statement whether or not to run the rest of the code in the loop.

    Hope this helps!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I've got a string that has curly quotes in it. I'd like to replace
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I'm trying to use string.replace('’','') to replace the dreaded weird single-quote character: ’ (aka
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I want to count how many characters a certain string has in PHP, but
I would like to count the length of a string with PHP. The string
For some reason, after submitting a string like this Jack’s Spindle from a text
Specifically, suppose I start with the string string =hello \'i am \' me And

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.