comp.lang.java.programmer
http://groups-beta.google.com/group/comp.lang.java.programmer
[EMAIL PROTECTED]

Today's topics:

* Function calls... - 11 messages, 4 authors
 
http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/fffeec3e18ff1713
* Getting A Greyscale Image To Display In Colour - Please Help! - 5 messages, 3 
authors
 
http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/2d8bb6f6f4ed5a2e
* [jsp]: getProperty - 5 messages, 3 authors
 
http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/6230ddcfe0818100
* Good JSP 2.0 Book? - 1 messages, 1 author
 
http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/23bfc11924c6feb3
* JMF Manager.createDataSource() and Resource URLs - 2 messages, 1 author
 
http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/f99d8613c3815c4
* Splitting a full-duplex socket - 1 messages, 1 author
 
http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/51615aee9a18c299

==============================================================================
TOPIC: Function calls...
http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/fffeec3e18ff1713
==============================================================================

== 1 of 11 ==
Date: Sun, Dec 26 2004 4:39 pm
From: Andrew McDonagh  

Chris Smith wrote:

snipped..

> 
> Except, of course, that you'd never want your database access code or 
> XML parsing code to be aware of Swing. 


snipped...

Absolutely, but coming up with a 'real world example' during the xmas 
holidays is hard for me, as I don't (thank god) have access to my work 
source code.  Even if I did, it would be a very domain explicit example 
which most people here wouldn't understand, as they wouldn't have worked 
in that domain.

So this leaves this 'real world' example of why Sun have choosen this 
particular idiom, albiet in a very simplified way.



== 2 of 11 ==
Date: Sun, Dec 26 2004 11:56 am
From: "Ryan Stewart"  

"Andrew McDonagh" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
> Absolutely, but coming up with a 'real world example' during the xmas 
> holidays is hard for me, as I don't (thank god) have access to my work 
> source code.  Even if I did, it would be a very domain explicit example 
> which most people here wouldn't understand, as they wouldn't have worked 
> in that domain.
>
> So this leaves this 'real world' example of why Sun have choosen this 
> particular idiom, albiet in a very simplified way.

I remain unconvinced. Interfaces and abstract classes are two different 
animals intended for two different purposes. Maybe in your work, interfaces 
predominant, but should java.lang.Number be an interface? What about 
java.util.AbstractCollection, java.io.OutputStream, or java.text.DateFormat? 
If your answer is yes, you are at the least promoting heavy-duty code 
duplication. 





== 3 of 11 ==
Date: Sun, Dec 26 2004 10:58 am
From: Chris Smith  

Andrew McDonagh <[EMAIL PROTECTED]> wrote:
> Absolutely, but coming up with a 'real world example' during the xmas 
> holidays is hard for me, as I don't (thank god) have access to my work 
> source code.

I think it's deeper than that.  In fact, I don't think that a "real 
world" example along the lines you're suggesting exists.  Almost by 
definition, it would introduce improper dependencies between modules.

Not that I disagree with using interfaces for this kind of thing.  An 
interface, in fact, is quite appropriate since it suggests something 
different at an abstract level; that there is a way of interacting with 
something that doesn't say anything about the implementation; versus an 
abstract class, which suggests a partial implementation that can be 
modified by overloading.  So interfaces are great.  Nevertheless, I 
don't think the practical multiple inheritance problem really exists 
with this kind of situation.

-- 
www.designacourse.com
The Easiest Way To Train Anyone... Anywhere.

Chris Smith - Lead Software Developer/Technical Trainer
MindIQ Corporation



== 4 of 11 ==
Date: Sun, Dec 26 2004 11:00 am
From: Chris Smith  

Andrew McDonagh <[EMAIL PROTECTED]> wrote:
> Sun, myself and others have no problem with adapter classes.

Sudsy was responding to Tony Morris, who said:

    "It is arguable that abstract classes should be used at all
     (inheritance from anything but an interface is pure evil, but
     that's another story for another camp fire)."

That cause Ryan Stewart to ask why, and hence this subthread.  Your 
position obviously isn't as extreme as Tony's, so Sudsy's response 
doesn't apply to you.

-- 
www.designacourse.com
The Easiest Way To Train Anyone... Anywhere.

Chris Smith - Lead Software Developer/Technical Trainer
MindIQ Corporation



== 5 of 11 ==
Date: Sun, Dec 26 2004 11:19 am
From: Chris Smith  

Chris Smith <[EMAIL PROTECTED]> wrote:
> something that doesn't say anything about the implementation; versus an 
> abstract class, which suggests a partial implementation that can be 
> modified by overloading.

Meant to say overriding.  Sorry for the confusion.

-- 
www.designacourse.com
The Easiest Way To Train Anyone... Anywhere.

Chris Smith - Lead Software Developer/Technical Trainer
MindIQ Corporation



== 6 of 11 ==
Date: Sun, Dec 26 2004 7:29 pm
From: Andrew McDonagh  


Ok, there seems to have been a mis-communication between us on this...


Ryan Stewart wrote:
> "Andrew McDonagh" <[EMAIL PROTECTED]> wrote in message 
> news:[EMAIL PROTECTED]
> 
>>Absolutely, but coming up with a 'real world example' during the xmas 
>>holidays is hard for me, as I don't (thank god) have access to my work 
>>source code.  Even if I did, it would be a very domain explicit example 
>>which most people here wouldn't understand, as they wouldn't have worked 
>>in that domain.
>>
>>So this leaves this 'real world' example of why Sun have choosen this 
>>particular idiom, albiet in a very simplified way.
> 
> 
> I remain unconvinced. Interfaces and abstract classes are two different 
> animals intended for two different purposes. 



I completely agree with you that Interfaces & Abstract classes are 
different and are used for different purposes.

> Maybe in your work, interfaces 
> predominant, but should java.lang.Number be an interface? What about 
> java.util.AbstractCollection, java.io.OutputStream, or java.text.DateFormat? 
> If your answer is yes, you are at the least promoting heavy-duty code 
> duplication. 

No you are completely right, it would be absurd at best.

So we agree.

Whilst a think Tony's stance is somewhat 'unique', I was trying to 
highlight the benefits of using Interfaces are the reference type rather 
than concrete or abstract classes, as this allows for a more flexible 
(i.e. loosely coupled) design.

Weirdly enough, in my work Interfaces only come into existence when I 
have a need to reference more than one version of the original concrete 
type. Until then, I simply use the single concrete class types as the 
reference.

As soon as I have a need for another version of the same type, then 
first I'll 'extract interface', and then create the second concrete 
class.  If the two concrete classes have duplicate code, then I will of 
course create an intermediate abstract class.

A very simple example....

Person ---uses--> Car

What about when they also need to drive a truck?

The code would be

Person ---uses --> vehicle

                         ^
                  ----------------
                  |
                 Car          truck

then i remove the duplication..


Person ---uses --> vehicle

                         ^
                         |
                  AbstractVehicle
                         ^
                         |
                  ----------------
                  |
                 Car          truck


But what about when the person uses a boat, would be 'weird' for boat to 
derive from AbstractVehicle as it doesn't have wheels. So by passing 
refs around via the interface we over come any problems when we need to 
change.

Ok...maybe that was too simplistic, but you get the idea...

We agree...



== 7 of 11 ==
Date: Sun, Dec 26 2004 7:32 pm
From: Andrew McDonagh  

Chris Smith wrote:
> Andrew McDonagh <[EMAIL PROTECTED]> wrote:
> 
>>Sun, myself and others have no problem with adapter classes.
> 
> 
> Sudsy was responding to Tony Morris, who said:
> 
>     "It is arguable that abstract classes should be used at all
>      (inheritance from anything but an interface is pure evil, but
>      that's another story for another camp fire)."
> 
> That cause Ryan Stewart to ask why, and hence this subthread.  Your 
> position obviously isn't as extreme as Tony's, so Sudsy's response 
> doesn't apply to you.
> 

oh yes, I see that now.  Yes I agree Tony's view is a little 'extreme', 
and in fact I agree with Ryan, but just used different words that did 
not convey my meaning very well.



== 8 of 11 ==
Date: Sun, Dec 26 2004 7:36 pm
From: Andrew McDonagh  

Chris Smith wrote:
> Andrew McDonagh <[EMAIL PROTECTED]> wrote:
> 
>>Absolutely, but coming up with a 'real world example' during the xmas 
>>holidays is hard for me, as I don't (thank god) have access to my work 
>>source code.
> 
> 
> I think it's deeper than that.  In fact, I don't think that a "real 
> world" example along the lines you're suggesting exists.  

Ok, lets forget trying to come up with a 'real world' example, as most 
peoples domain knowledge would produce an example which would probably 
only be confusing for others who haven't worked in that domain.


> Almost by 
> definition, it would introduce improper dependencies between modules.

I completely agree...

However, it was just simply an example of JTables usage of the 
TableModel interface.


snipped rest



== 9 of 11 ==
Date: Sun, Dec 26 2004 4:17 pm
From: "Ryan Stewart"  

"Andrew McDonagh" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
> Ok, there seems to have been a mis-communication between us on this...
[...]
> I completely agree with you that Interfaces & Abstract classes are 
> different and are used for different purposes.
>
Okay, I thought you were agreeing that abstract classes should never be 
used. That appears to be Tony's perspective.

[...]
> A very simple example....
>
> Person ---uses--> Car
>
> What about when they also need to drive a truck?
>
> The code would be
>
> Person ---uses --> vehicle
>
>                         ^
>                  ----------------
>                  |
>                 Car          truck
>
> then i remove the duplication..
>
>
> Person ---uses --> vehicle
>
>                         ^
>                         |
>                  AbstractVehicle
>                         ^
>                         |
>                  ----------------
>                  |
>                 Car          truck
>
>
> But what about when the person uses a boat, would be 'weird' for boat to 
> derive from AbstractVehicle as it doesn't have wheels. So by passing refs 
> around via the interface we over come any problems when we need to change.
>
> Ok...maybe that was too simplistic, but you get the idea...
>
> We agree...
Absolutely. And the "Person uses Vehicle" example is a perfect example of an 
interface. That's the whole point of interfaces: to provide an interface for 
interaction. To take it to a higher level of complexity, you might note 
first that not all vehicles have wheels (like your boat), so you might have 
an abstract Vehicle with an abstract Automobile subclass with concrete 
subclasses Car and Truck (or even more specialized as the need arises). Then 
Boat could be a concrete subclass of Vehicle:
                  ^
                  |
               Vehicle
                  ^
                  |
          -----------------
          |               |
      Automobile         Boat
          ^
          |
   ---------------
   |             |
  Car          Truck
(View fixed width for proper perspective.)

Or Boat might be abstract, and you might have subclasses Sailboat, Yacht, 
OilTanker...

Finally, note that an interface doesn't need to define an entire class. When 
a Person interacts with a Vehicle, what do they need to do with it? Let's 
narrow it down a bit. Suppose Person is an abstract class, and you have 
concrete classes Driver and Mechanic extending it. What do they do with a 
Vehicle? A driver drives and a mechanic services. Therefore, you might 
create interfaces Driveable and Serviceable which define methods drive and 
service (in a simple world), respectively. Then a Driver can drive 
*anything* that is Driveable, and a Mechanic can service *anything* that is 
Serviceable. You aren't tied to a Vehicle, Automobile, Car, or any other 
class.

(I'm not assuming you don't know all this, mainly writing it for others that 
may be watching.) 





== 10 of 11 ==
Date: Sun, Dec 26 2004 10:33 pm
From: Andrew McDonagh  

Ryan Stewart wrote:
> "Andrew McDonagh" <[EMAIL PROTECTED]> wrote in message 
> news:[EMAIL PROTECTED]
> 
>>Ok, there seems to have been a mis-communication between us on this...
> 
> [...]
> 
>>I completely agree with you that Interfaces & Abstract classes are 
>>different and are used for different purposes.
>>
> 
> Okay, I thought you were agreeing that abstract classes should never be 
> used. That appears to be Tony's perspective.

Nare, that would be daft!  Just talking about the references that are 
passed around, with the (my personal) norm of by sole class type or 
interface, very rarely by abstract class type.


> 
> Absolutely. And the "Person uses Vehicle" example is a perfect example of an 
> interface. 

Weird eh...we seem to be on the same page at last...

snipped

> 
> (I'm not assuming you don't know all this, mainly writing it for others that 
> may be watching.) 
> 

Thanks for clarifying.



== 11 of 11 ==
Date: Sun, Dec 26 2004 3:22 pm
From: "Tony Morris"  


"Ryan Stewart" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> "Tony Morris" <[EMAIL PROTECTED]> wrote in message
> news:[EMAIL PROTECTED]
> > Abstract classes should never be used as a pure virtual type (with only
> > abstract methods), or a concrete type (with no abstract methods).
> > It is arguable that abstract classes should be used at all (inheritance
> > from
> > anything but an interface is pure evil, but that's another story for
> > another
> > camp fire).
> >
> I'll bite. Why never use abstract classes?
>
>

I have two articles pending for IBM DeveloperWorks early next year.
Once they are published, I will make efforts to offer a full explanation by
way of another article.

-- 
Tony Morris
http://xdweb.net/~dibblego/






==============================================================================
TOPIC: Getting A Greyscale Image To Display In Colour - Please Help!
http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/2d8bb6f6f4ed5a2e
==============================================================================

== 1 of 5 ==
Date: Sun, Dec 26 2004 11:50 am
From: "stublair"  

Hi all,

I have a raster file landgrey.raster- essentially a 300 x 300 byte array
of pixel values where each value represents a different landuse type.  The
file looks something like this:


100 100 100 100…..
100 83    83   100….
100 83   83   100…
100 100 100 100…..

where the value 100 represents grass and the value 83 represents cars. The
full list of different landuse objects within the raster file are given
below:

133 =   Building
83 =    Cars
48 =    Roads
100 =   Grass
73 =    Trees


I have written a class -  OpenRasterListnr.java -  which opens up the
landgrey.raster  and displays the 300 x 300 file in greyscale, the code
for which is given below:

package Java;

import java.awt.*;
import java.awt.event.*;
import java.awt.image.*;
import java.io.*;

class OpenRasterListnr implements ActionListener {

        private ImagePanel panel = null;

        OpenRasterListnr (ImagePanel pn) {
        
                panel = pn;
        
        }

        public void actionPerformed (ActionEvent ae) {
                

        
                FileDialog openDialog = new FileDialog(new Frame(), "Open file",
FileDialog.LOAD); 
                openDialog.show();      
                File file = new File(openDialog.getDirectory() + 
openDialog.getFile());
                
                if ((openDialog.getDirectory() == null) || 
(openDialog.getFile() ==
null)) return;
                //-------------------
                //FileDialog saveDialog = new FileDialog(new Frame(), "Save 
file",
FileDialog.SAVE); 
                //saveDialog.show();    
                
                String fileName = openDialog.getDirectory() + 
openDialog.getFile();
                
                //File fileName = new File (saveDialog.getDirectory() +
saveDialog.getFile());
                
                //Image ourImage = panel.getDisplayImage();
                int width = 300;//ourImage.getWidth(panel);
                int height = 300;//ourImage.getHeight(panel);
                int x = 0;
                int y = 0;
                
                int[] pixels = new int[width * height];
                
                //try
                //{
                //---------------------
                        //FileWriter fw = new FileWriter(fileName);
                        
                File f = null;
                ReaderThing r = null;
                // Code to read integer arrays.
                f = new File("c:/Java/landgrey.raster");
                //f = new File(file);
                r = new ReaderThing(f, true);

                //int [][] d = r.getTwoDintArray(); 
                int [] a = r.getOneDintArray(); 
                //----------------------
                //sets yourpixelarray to same length as pixels
                //int[] a = new int[width * height];
                int [][] d = new int[width][height];
                for (int j = 0; j < height; j++) 
                {
                for (int i = 0; i < width; i++) 
                {
                        
                        // get compressed int out of pixels at (j * width) + i 
                        // make a new color object from that int
                        Color newColor = new Color (a[j * width + i]); //for 1D 
array
                        //Color newColor = new Color (d[j][i]);
                        //a[j * width + i] = d[j][i];
                        
                        int red = newColor.getRed();
                        int green = newColor.getGreen();
                        int blue = newColor.getBlue();
                
                        double temp = 0.56 * (double)green + 0.33 *(double) red 
+ 0.11
*(double) blue;
                        newColor = new Color((int)temp,(int)temp,(int)temp);
                        int compressedInt = newColor.getRGB();
                
                        String grey = String.valueOf(temp);
                                        
                        //fw.write(grey + " ");
                                
                        // put int back in pixels
                        a[j * width + i] = compressedInt;
                        d[j][i]=compressedInt;
                }
                }
        
                //fw.close();
                Image ourImage = panel.getToolkit().createImage(new
MemoryImageSource(width, height, a, 0, width));
                panel.setDisplayImage(ourImage); 
                panel.repaint(); 
        //}catch (IOException e){
                //e.printStackTrace();  
                //}
        
        }
}



For those interested ReaderThing.java is given below:


package Java;

import java.io.*;
import java.util.*;
import java.awt.Color;


/**
 * This Class takes in a file object in its constructor and turns it into
an 2D array.<P>
 * It also includes a method to get a 1D compressed int array for making
images and 1D String arrays.
 * @author Jonathan Gill (class of 2000, now working at GMap and still
coding, lucky man!) and Andy Evans.<P>
 * @version 1.2
**/
public class ReaderThing {


        private int [][] twoDintArray = null;
        private String [][] twoDStringArray = null;
        private int width, height = 0;


        public ReaderThing(File file, boolean convertToInts){

                FileReader filer = null;
                StringTokenizer st = null;

                String temp = null; 

                try {   

                        BufferedReader buff = new BufferedReader(new 
FileReader(file));
                        String line = buff.readLine();

                        // There seems to be a problem on some systems where 
                        // end of lines in text files are recognised by java as 
                        // a second, blank, line. We get rid of these by 
checking the 
                        // length of the line after calling trim(). Trim is a 
method 
                        // in every String class object, which removes the 
spaces 
                        // from its start and end. 

                        if (line != null) {

                                line.trim();

                                if (line.length() != 0){ 

                                        try {
                                
                                                st = new StringTokenizer(line, 
",");
                                                temp = st.nextToken();
                                                
                                                // Integer.parseInt() converts 
Strings to ints.

                                                width = Integer.parseInt(temp);
                                                temp = st.nextToken();
                                                height = Integer.parseInt(temp);
                                        
                                        } catch(NumberFormatException e){
                                        
                                                System.out.println("Invalid 
Format: " + 
                                                        "First line must be 
width,height");
                                                
                                        }
                                }
                        }
                
                        twoDintArray = new int[width][height];
                        twoDStringArray = new String[width][height];

                        line = buff.readLine();

                        // Get rid of any blank lines.

                        if (line != null) {

                                line.trim();
                                if (line.length() == 0) line = buff.readLine();
                
                        }

        
                        while (line != null){

                                for (int i = 0; i < height; i++) {
        
                                        st = new StringTokenizer(line, ", ");
                                        
                                        for (int j = 0; j < width; j++) {
                                        
                                                twoDStringArray[j][i] = 
st.nextToken();
                                                
                                                if (convertToInts == true)
{
                                                    
                                                    try {
                                                        int z =
Integer.parseInt(twoDStringArray[j][i]);
                                                        twoDintArray[j][i]
= z;
                                                    }
catch(NumberFormatException e) {
                                                        twoDintArray[j][i]
= 0;
                                                    }
                                                }
                                        }

                                        line = buff.readLine();
                                        
                                        if (line != null) {
                                                line.trim();
                                                if (line.length() == 0) line = 
buff.readLine();
                                        }

                                }

                        }

                        buff.close();

                } catch (IOException e) {

                        e.printStackTrace();

                }

        }


        
    

        public int getWidth() {
                return width;
        }





        public int getHeight() {
                return height;
        }





        public int[][] getTwoDintArray() {

                return twoDintArray;
        
        }




        
        public String[][] getTwoDStringArray() {

                return twoDStringArray;
        
        }





        public int[] getOneDintArray() {

                int [] oneDintArray  = new int [width * height];

                for (int a = 0; a < width; a++) {

                        for (int b = 0; b < height; b++) {

                                int temp = twoDintArray[a][b];
                                Color tempColor = new Color(temp,temp,temp);
                                oneDintArray [(b*width) + a] = 
tempColor.getRGB();
                        
                        }
                        
                }
                return oneDintArray;
        }





        public String[] getOneDStringArray() {

                String[] oneDStringArray  = new String [width * height];

                for (int a = 0; a < width; a++) {

                        for (int b = 0; b < height; b++) {

                                oneDStringArray [(b*width) + a] = 
twoDStringArray[a][b];                                                
                        
                        }
                        
                }
                return oneDStringArray;
        }



}

As part of the requirements of the programme I am making, the colours
associated with each land-use object have to be set via a point class
which uses get and set methods such as the one below (I realise that what
follows is not right – what I am basically trying to do is to set each of
the values in the landgrey.raster file to an object type – i.e  int
buildings = 133;     which can then be called in the OpenRasterListnr.java
file using a get/set method – whichever is appropriate – to display each of
the above landuses in the following colours

Buildings = red                 (255, 0, 0)
Cars = black                    (0, 0, 0)
Roads = grey                    (192, 192, 192)
Grass = green                   (0, 255, 0)
Trees = dark green              (0, 128, 0)

In a kind of garbled way I have attempted the code to do this though it is
obviously wrong. I know that I will need a new class – say MakeColour.java
– which will essentially be the same as OpenRaster.Listnr.java but will
have the additional code to display the image in colour instead of
greyscale. The code I have attempted to write so far is in lines 69 - 96
of the following code given below:


package Java;

import java.awt.*;
import java.awt.event.*;
import java.awt.image.*;
import java.io.*;

class MakeColour implements ActionListener {

        private ImagePanel panel = null;

        MakeColour (ImagePanel pn) {
        
                panel = pn;
        
        }

        public void actionPerformed (ActionEvent ae) {
                

        
                FileDialog openDialog = new FileDialog(new Frame(), "Open file",
FileDialog.LOAD); 
                openDialog.show();      
                File file = new File(openDialog.getDirectory() + 
openDialog.getFile());
                
                if ((openDialog.getDirectory() == null) || 
(openDialog.getFile() ==
null)) return;
                //-------------------
                //FileDialog saveDialog = new FileDialog(new Frame(), "Save 
file",
FileDialog.SAVE); 
                //saveDialog.show();    
                
                String fileName = openDialog.getDirectory() + 
openDialog.getFile();
                
                //File fileName = new File (saveDialog.getDirectory() +
saveDialog.getFile());
                
                //Image ourImage = panel.getDisplayImage();
                int width = 300;//ourImage.getWidth(panel);
                int height = 300;//ourImage.getHeight(panel);
                int x = 0;
                int y = 0;
                
                int[] pixels = new int[width * height];
                
                //try
                //{
                //---------------------
                        //FileWriter fw = new FileWriter(fileName);
                        
                File f = null;
                ReaderThing r = null;
                // Code to read integer arrays.
                f = new File("c:/Java/landgrey.raster");
                //f = new File(file);
                r = new ReaderThing(f, true);

                //int [][] d = r.getTwoDintArray(); 
                int [] a = r.getOneDintArray(); 
                //----------------------
                //sets yourpixelarray to same length as pixels
                //int[] a = new int[width * height];
                int [][] d = new int[width][height];
                
                
                for (int j = 0; j < height; j++) 
                {
                for (int i = 0; i < width; i++) 
                {
                        
                        
                Point secondColor = new Point (pixels[j * width + i]);
                                
                                int a = secondColor.setBuilding(Color.RED);     
        // make buildings red
                                int b = secondColor.setCars(Color.BLACK);       
        // make cars black
                                int c = secondColor.setRoads(Color.GRAY);       
        //make roads grey       
                                int d = secondColor.setGrass(Color.GREEN);      
        //make grass green
                                int e = secondColor.setTrees(Color.YELLOW);     
        //make trees yellow
                
                                double tempt = (double)a + (double)b + 
(double)c + (double)d +
(double)e;
                                secondColor = new 
Color((int)tempt,(int)tempt,(int)tempt, (int)tempt,
(int)tempt);
                                int compressedInt2 = secondColor.getRGB();
                                        
                                
                                String notgrey = String.valueOf(tempt);
                                        
                                fw.write(notgrey + " ");
                                
                                // put int back in pixels
                                pixels[j * width + i] = compressedInt2;
                        
                        
                        String grey = String.valueOf(temp);
                                        
                        //fw.write(grey + " ");
                                
                        // put int back in pixels
                        a[j * width + i] = compressedInt2;
                        d[j][i]=compressedInt2;
                }
                }
        
                //fw.close();
                Image ourImage = panel.getToolkit().createImage(new
MemoryImageSource(width, height, a, 0, width));
                panel.setDisplayImage(ourImage); 
                panel.repaint(); 
        //}catch (IOException e){
                //e.printStackTrace();  
                //}
        
        }
}


any help on this one would be greatly greatly appreciated - if anyone
wants the rest of the code to see how bits are working email me!

stu
x




== 2 of 5 ==
Date: Sun, Dec 26 2004 6:22 pm
From: ByteCoder  

stublair wrote:
> Hi all,
> 
> I have a raster file landgrey.raster- essentially a 300 x 300 byte array
> of pixel values where each value represents a different landuse type.  The
> file looks something like this:
> 
> 
> 100 100 100 100…..
> 100 83          83   100….
> 100 83   83   100…
> 100 100 100 100…..
[...]

I am not completely sure what you mean, but since you can already 
display a image of grey-values, I suppose that isn't the problem.

If you got problems with the Colors, you could use a switch-case 
statement when you walk through the (2D) array. If the case is 133, set 
it to the color for the building. If it is 48, set it to the road color.
You could make the default statement the color of grass, because that 
might be used the most. Also if someone changes an int in a file to an 
incorrect value it will stay grass in your image.

-- 
-------------
- ByteCoder -           ...I see stupid people
-------------
                    Curiosity *Skilled* the cat



== 3 of 5 ==
Date: Sun, Dec 26 2004 5:36 pm
From: Andrew McDonagh  

ByteCoder wrote:
> stublair wrote:
> 
>> Hi all,
>>
>> I have a raster file landgrey.raster- essentially a 300 x 300 byte array
>> of pixel values where each value represents a different landuse type.  
>> The
>> file looks something like this:
>>
>>
>> 100 100 100 100…..
>> 100 83      83   100….
>> 100 83   83   100…
>> 100 100 100 100…..
> 
> [...]
> 
> I am not completely sure what you mean, but since you can already 
> display a image of grey-values, I suppose that isn't the problem.
> 
> If you got problems with the Colors, you could use a switch-case 
> statement when you walk through the (2D) array. If the case is 133, set 
> it to the color for the building. If it is 48, set it to the road color.
> You could make the default statement the color of grass, because that 
> might be used the most. Also if someone changes an int in a file to an 
> incorrect value it will stay grass in your image.
> 

you can use the built in RGBImageFilter or a derived one like...

http://www.cafeaulait.org/course/week9/35.html



== 4 of 5 ==
Date: Sun, Dec 26 2004 1:03 pm
From: "stublair"  

hi cheers for the reply, i have written some code for a switch statment but
the project requires that i use  a point class such as the one below and
then use the get/set method to reference objects such as buildings into
the array - any further ideas would be mucho appreciated!

stu
x

package Java;

public class Point {

        int buildings = 133;
        int cars = 83;
        int roads = 48;
        int grass = 100;
        int trees = 73;
        
        

//----------------------------------------
        
        
        void setBuilding (int buildingsIn) {
                buildings = buildingsIn;
        
        }

        int getBuildings () {
                        return buildings;
        
        }       
                        
                        
                        
//----------------------------------------
        void setCars (int carsIn) {
                cars = carsIn;
        
        }



        int getCars () {
                        return cars;
        
        }
//----------------------------------------

        void setRoads (int roadsIn) {
                roads = roadsIn;
        
        }

        
        int getRoads () {
                        return roads;
                        
        }               



//----------------------------------------

        void setGrass (int grassIn) {
                grass = grassIn;
        
        }

        
        int getGrass () {
                        return grass;
        }

        
//------------------------------------- 
        
        
        void setTrees (int treesIn) {
                trees = treesIn;
        
        }
        
        
        int getTrees () {
                        return trees;
        
        }
        
        
//-------------------------------------- end point class        
}




== 5 of 5 ==
Date: Sun, Dec 26 2004 7:37 pm
From: ByteCoder  

stublair wrote:
> hi cheers for the reply, i have written some code for a switch statment but
> the project requires that i use  a point class such as the one below and
> then use the get/set method to reference objects such as buildings into
> the array - any further ideas would be mucho appreciated!
> 
> stu
> x
> 
[snip code]

There already is a Class java.awt.Point, which extends Point2D. Perhaps 
you could extend Point for this exercise? It might be an idea to 
overwrite the getLocation() and setLocation() methods to not only 
return/pass a Point, but also the type of Point, such as Building, Car etc.

If you make Classes of Grass, Building, Car etc. you could put the 
colour info in the object of the material.

You could make static calls to the material Classes to prevent 
unnessecary object creation.

-- 
-------------
- ByteCoder -           ...I see stupid people
-------------
                    Curiosity *Skilled* the cat




==============================================================================
TOPIC: [jsp]: getProperty
http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/6230ddcfe0818100
==============================================================================

== 1 of 5 ==
Date: Sun, Dec 26 2004 11:40 am
From: "Ryan Stewart"  

"Marcus Reiter" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
[...]
> <jsp:setProperty name="BeanName" property="vectorName" value="10"/>

[...]
> org.apache.jasper.JasperException: Can't find a method to write property
> vectorNameof type 'java.util.Vector' in a bean of type
> 'packageName.BeanName'

[...]
>    private Vector vectorName= new Vector();

[...]
"vectorName" is a Vector. The value "10" can't be converted to a Vector. 
Consider a minor or major redesign. Name things appropriately, and don't 
make a setter for a Vector property that takes an int (which is what's 
screwing you up). 





== 2 of 5 ==
Date: Sun, Dec 26 2004 7:14 pm
From: "Marcus Reiter"  

10 should not get converted to a Vector.

The thing is the vector I want first of all needs to get builded -
and the method that builds that vector needs an integer value.

look, that's the method it should connect to:

public void setVectorName(int attribute) {
        this.vectorName= dbConnection .getBeanList(attribute);
    }

so it should take that int value, send it to a method in another class and
this method
should return a vector, that then gets saved in my bean.

I guess that might not be the best idea, yet it's the only idea I had so
far...

Marcus





== 3 of 5 ==
Date: Sun, Dec 26 2004 12:28 pm
From: "Ryan Stewart"  

"Marcus Reiter" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
> 10 should not get converted to a Vector.
>
Obviously, but that's what you've told it to do because the variable 
"vectorName" is of type Vector.

> The thing is the vector I want first of all needs to get builded -
> and the method that builds that vector needs an integer value.
>
> look, that's the method it should connect to:
>
> public void setVectorName(int attribute) {
>        this.vectorName= dbConnection .getBeanList(attribute);
>    }
>
> so it should take that int value, send it to a method in another class and
> this method
> should return a vector, that then gets saved in my bean.
>
The name of the method declares that it's a setter for property vectorName. 
You've used it as something else.

> I guess that might not be the best idea, yet it's the only idea I had so
> far...
>
What about a different method like setType or setAttribute, where type or 
attribute or whatever you want to call it is an int? 





== 4 of 5 ==
Date: Sun, Dec 26 2004 7:43 pm
From: "Marcus Reiter"  

Sounds good -

But how would I do that?

So far I only know the setProperty and getProperty tag...

Marcus





== 5 of 5 ==
Date: Sun, Dec 26 2004 3:00 pm
From: Sudsy  

Marcus Reiter wrote:
> Sounds good -
> 
> But how would I do that?
> 
> So far I only know the setProperty and getProperty tag...
> 

Marcus,
    What Ryan is trying to explain is that you have an impedance
mis-match here. Look at these two methods:

     public Vector getVectorName() {
       ...

     public void setVectorName(int attribute) {
       ...

So the accessor is returning a java.util.Vector but the mutator
is expecting an int. The argument type for the mutator is supposed
to be the same as the return type from the accessor, i.e.:

     public Vector getVectorName() {
       ...

     public void setVectorName( Vector name ) {
       ...

What Ryan is (I think) suggesting is that you add another attribute,
something like this:

     public Vector getVectorName() {
       ...

     public void setVectorNameIndex( int nameIndex ) {
       ...

     public int getVectorNameIndex() {
       ...

The rest should be fairly obvious by now...




==============================================================================
TOPIC: Good JSP 2.0 Book?
http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/23bfc11924c6feb3
==============================================================================

== 1 of 1 ==
Date: Sun, Dec 26 2004 1:44 pm
From: Larry Hannay <"LarryStupidTuesday  

I think that "JavaServer Pages" by Hans Bergsten (O'Reilly publisher) is 
definitely worth checking out.


[EMAIL PROTECTED] wrote:

>I am a fairly experienced programmer. I've predominantly written web
>apps using Microsoft technologies and am looking to learn Java Server
>Pages 2.0.
>
>Can anyone recommend a good book? Looking for a book which assumes that
>the reader has a web development background - don't need a tutorial on
>how/why pages need to be generated dynamically. Need a "how to build
>web apps using JSP" type of book..
>
>thanks,
>
>Bijoy
>
>  
>




==============================================================================
TOPIC: JMF Manager.createDataSource() and Resource URLs
http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/f99d8613c3815c4
==============================================================================

== 1 of 2 ==
Date: Sun, Dec 26 2004 12:33 pm
From: "Dan Weber"  

Currently I am getting a URL from Class.getResource() for a wav file in
the same directory.

So here is what happens:

If I feed Manager.createDataSource from JMF the Resource URL it fails
and says unable to locate Data Source

If I feed Manager.createDataSource a url to a webserver with the same
file it works fine.

How can I work around this?

Dan




== 2 of 2 ==
Date: Sun, Dec 26 2004 12:35 pm
From: "Dan Weber"  

Here is the documentation for the Manager class --

http://java.sun.com/products/java-media/jmf/2.1.1/apidocs/javax/media/Manager.html
Dan





==============================================================================
TOPIC: Splitting a full-duplex socket
http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/51615aee9a18c299
==============================================================================

== 1 of 1 ==
Date: Sun, Dec 26 2004 2:02 pm
From: "cyberco"  

Thanks, Filip. I'm specifically talking about J2ME (MIDP2.0) devices,
which DO support sockets (at least the majority of them), so there's no
need to revert to HttpConnection. The problem is not on the client side
but on the proxy side...

Cheers,
cyberco




==============================================================================

You received this message because you are subscribed to the Google
Groups "comp.lang.java.programmer" group.

To post to this group, send email to [EMAIL PROTECTED] or
visit http://groups-beta.google.com/group/comp.lang.java.programmer

To unsubscribe from this group, send email to
[EMAIL PROTECTED]

To change the way you get mail from this group, visit:
http://groups-beta.google.com/group/comp.lang.java.programmer/subscribe

To report abuse, send email explaining the problem to [EMAIL PROTECTED]

==============================================================================
Google Groups: http://groups-beta.google.com 

Reply via email to