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 3977890
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T04:58:40+00:00 2026-05-20T04:58:40+00:00

I don’t know why but nothing is appearing? I suppose to have a applet

  • 0

I don’t know why but nothing is appearing?

I suppose to have a applet of a house.

import javax.swing.*;
import java.awt.*;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.*;


public class color extends JApplet
{
    public void init()
    {
        addMouseListener(new MyMouseListener());
        getContentPane().setBackground(Color.white);
    }
    public class MyMouseListener implements MouseListener
    {
    public void mouseClicked(MouseEvent e) 
    {
           int x = e.getX();
           int y = e.getY();
           boolean closeDoors = true;

           if(x>330 && x<280 && y>20 && y<20)
           {
               closeDoors = false;
               repaint();

           }

    }
    public void mouseEntered(MouseEvent e) { }
    public void mouseExited(MouseEvent e) { }
    public void mousePressed(MouseEvent e) { }
    public void mouseReleased(MouseEvent e) { }
    }
    public void paint ( Graphics g, boolean closeDoors)
           {
                super.paint (g);

                do
                {
               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);
                }
                 while (closeDoors = true);

                 if (closeDoors = false);
                {
                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);
                }
            }
}
  • 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-20T04:58:41+00:00Added an answer on May 20, 2026 at 4:58 am

    I’ll try to help get you on the right track 🙂

    You may already know this, but if your not using an IDE, I recommend using appletviewer to develop your applets instead of with a browser. Just food for thought 🙂

    First of all, Toader Mihai Claudiu‘s suggestion is correct. Change

                do
                {
               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);
                }
                 while (closeDoors = true);
    
                 if (closeDoors = false);
                {
    

    into

                if (closeDoors)
                {
               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
                {
    

    Otherwise, you’re going to be painting as long as closeDoors is true. You just need to paint once. Java will ask you to paint again when it has to (for instance, when you call repaint()).

    Also, set closeDoors as a member variable. In other words, have:

    public class color extends JApplet
    {
      public boolean closeDoors = false;
    

    And when you switch the value of closeDoors in the click listener, you can simplify it as:

           int x = e.getX();
           int y = e.getY();
    
           if(x>330 && x<280 && y>20 && y<20)
           {
               closeDoors = !closeDoors;
               repaint();
    
           }
    

    That will, when you click in your specific area, invert the value of closeDoors. In other words, if closeDoors is true, it will be set to false, and vice versa.

    Note, your code if(x>330 && x<280 && y>20 && y<20) probably won’t work at all, since y cannot be greater than 20 and less than 20 at the same time, ever. I’ll let you play with that to figure out what works :-).

    Hope this helps.


    Just a minor detail, but you should probably call your class Color instead of color to follow Java’s standard naming convention, or call it something else if you don’t want to clash with java.awt.Color.

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

Sidebar

Related Questions

Don't know whats exactly going on, but it's definitely killing my time for nothing.
Don't know why but I can't find a solution to this. I have 3
don't know better title for this, but here's my code. I have class user
don't know if the title describes anything about what I'm trying to say but
Don't ask me how but I'm in a situation where I have DCPs published
Don't really know how to formulate the title, but it should be pretty obvious
Don't know how to google for such, but is there a way to query
Don't know why but font is not displaying.Please help. CSS(in css folder): style.css: @font-face
I don't know why, but this code worked for me a month ago... maybe
Don't ask why but I have the requirement to draw a border around certain

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.