954,536 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

When I run my Java program my screen is blank.

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.*;
import java.applet.Applet;
import java.awt.Graphics;


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);
				}
	    	}
}
kingofdrew
Newbie Poster
4 posts since Feb 2011
Reputation Points: 10
Solved Threads: 0
 

if(x>330 && x<280 && y>20 && y<20)

x cannot be both >300 and <280 at the same time
similarly, y cannot be greater than and less than 20 at the same time

so this will always evaluate to false, for all possible values of x and y

JamesCherrill
Posting Genius
Moderator
6,373 posts since Apr 2008
Reputation Points: 2,130
Solved Threads: 1,073
 

I think you need y == 20?

mangopearapples
Posting Whiz in Training
242 posts since Oct 2010
Reputation Points: 26
Solved Threads: 3
 
I think you need y == 20?


Unlikely.
@kingofdrew needs to have another look at how && works.
Also
public void paint ( Graphics g, boolean closeDoors)
is probably a mistake. It looks like a failed attempt to override the inherited
public void paint ( Graphics g)
but because of the additional parameter this is just an ordinary method, not an override, and it doesn't get called anywhere.

JamesCherrill
Posting Genius
Moderator
6,373 posts since Apr 2008
Reputation Points: 2,130
Solved Threads: 1,073
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: