Talk About Network



Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > Java Help > Re: need simple...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 3 of 4 Topic 15987 of 16078
Post > Topic >>

Re: need simple help.....

by Knute Johnson <nospam@[EMAIL PROTECTED] > Apr 18, 2008 at 08:37 AM

RedGrittyBrick wrote:
> TheBigPJ wrote:
>> Im confused why this isnt working....
> 
> "isn't working" is a poor description. DId you get an error message when

> compiling, and error message when running, or di the output differ from 
> what you expected. If the latter, describe what you expected and what 
> you saw.
> 
> When I fix your code and run it it works OK for me (I had to create a 
> map.png). See below for probable error on your part.
> 
>>
>> Any ideas? What have I stupidly missed?
>>
>> Thanks,
>> Peter
>>
>> -----------------------------
>> import javax.swing.*;
>> import java.awt.*;
>> import java.util.*;
>>
>> public class CAS2_Interface extends JPanel{
>>
>>     CAS_Engine theCAS_Engine;
> 
> Unused.
>     // CAS_Engine theCAS_Engine;
> 
>>
>>     public static void main(String[] args)
>>     {
>>         JFrame mainWindow = new JFrame("CASAT - Connect a Square on a
>> Tesseract (Multiplayer)");
>>
>>         JPanel content = new JPanel();
>>         content.add(new CAS2_Interface(), BorderLayout.WEST);
>>
>>         mainWindow.setContentPane(content);
>>
>>         mainWindow.getContentPane().setBackground(new
>> Color(176,196,222));
>>         mainWindow.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
>>         mainWindow.setLocationRelativeTo(null);
>>         mainWindow.pack();
>>         mainWindow.setVisible(true);
>>     }
>>
>>     public void CAS2_Interface()
> 
> This method has a constructor name
>     public CAS2_Interface()
> 
>>     {
>>         setPreferredSize(new Dimension(600,471));
>>         setBackground(new Color(173,216,230));
>>     }
>>
>>     public void paintComponent(Graphics g)
>>     {
>>         super.paintComponent(g);
>>         drawScreen((Graphics2D) g);
>>     }
>>
>>     public void drawScreen(Graphics2D g)
>>     {
>>         //Uses the game board as defined in the program specification
>>         Image image = Toolkit.getDefaultToolkit().getImage("./
>> map.png");
> 
> You don't check whether the file exists or the getImage succeeds. This 
> is where your problem lies.
> 
> I'd create a new File("./map.png") and check file.exists();
> I'd check that image.getHeight(null) <> -1;
> 
>>         g.drawImage(image, 0,0,this);
>>     }
>> }
> 
> 
> 

He's already posted the same problem in a thread with the same title and 
doesn't want to provide any information more than this.  Actually this 
one has even less information.

Loading the image in the paintComponent() method is going to be
problematic!

He doesn't need to check whether the image is loaded or not because he 
is using the ImageObserver/Producer pattern.  It will load and draw (if 
it exists, as you point out) on its own.

-- 

Knute Johnson
email s/nospam/linux/

--
Posted via NewsDemon.com - Premium Uncensored Newsgroup Service
      ------->>>>>>http://www.NewsDem




 4 Posts in Topic:
need simple help.....
TheBigPJ <TheBigPJ@[EM  2008-04-17 10:03:49 
Re: need simple help.....
RedGrittyBrick <RedGri  2008-04-18 11:11:19 
Re: need simple help.....
Knute Johnson <nospam@  2008-04-18 08:37:41 
Re: need simple help.....
TheBigPJ <TheBigPJ@[EM  2008-04-18 16:09:15 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Sat May 17 2:45:44 CDT 2008.