AWT
does anybody use it?
if you do, please help a newbie student figure out:
How do I add an image to a frame or panel
Do i use add(Image image) or something like that
Or is there a simpler way.
thanx.
btw, if you do not use AWT, any help would be appreciated anyway
only subclasses of Component can be added to the AWTs passive rendering system.
If you arn't using Swing, then you will have to extend 1 of the existing AWT Components (I would recommend java.awt.Panel), and override the paint method so it draws the desired image.
Its a straight forward bit of code :P
hey, well heres a good question:where can i get some of the api souce code, for example the panel code, so that i could extend it effectively?
You dont need the source of the core classes, only the javadoc.
The javadoc is available for viewing here :-
http://java.sun.com/j2se/1.4.1/docs/api/
and for download, here :-
http://java.sun.com/j2se/1.4.1/download.html
(scrolldown to the section entitled 'J2SE v 1.4.1 Documentation')
blee... i already answered in the other thread :/u dont need to start new threads over and over again if u didnt get the answer instantly.
oNyxa at 2007-7-12 2:18:18 >

how do you create an image object in an application? if the image is in the same directory, what would i do? Image i = new Image(name)? or some odd thing like in applets?
there are many ways.
in applets, you've got
Applet.getImage(URL);
for applets and applications, you've got
Toolkit.getImage();
and
Toolkit.createImage();
alternatively, you've got (new to java1.4)
ImageIO.read().
You should read up on the various methods, and their application.
i am trying to use Toolkit.getImage() and i am getting an error: nonstatic method cannot be referanced from a static contextwhat does this mean?
you're getting that error because your code is like this:
public class Example {
public static void main(String[] args) {
Toolkit.getImage(...);
// ...
}
}
since main is a static method, it can't use non-static methods. An easy way around this would be to do it this way:
public class Example {
public Example() {
Toolkit.getImage(...);
// ...
}
public static void main(String[] args) {
new Example();
}
}
no, but im using it in a constructor for PokerFrame, which extends Frame. this is not static, as far as i know, but it still does not allow it.
oh I'm not thinking! You're using Toolkit.getImage, getImage is not a static method! Use getToolkit().getImage
as in Image i = getToolkit().getImage(name);?
just instantiate a toolkitToolkit tk = Toolkit.getDefaultToolkit();then,tk.getImage("fileName");
hehe, the confusion I sow is amazing :D
sorry for that :P
when I said, Toolkit.getImage(), I simply meant the getImage method of the Toolkit class.
I didn't expect you to take it so literally - it wasn't code! :)
BTW, is there a standard for describing such things?
elsewhere, i've seen the format 'ClassName::methodName()' used when describing methods of an instance of a particular class.
Is this how your s'posed to 'say' it? :S
that's how you 'say' it for C/C++, I've never seen it 'said' like that in Java
hey, lets start a trend and use your way!
anyways, another sutpid question from a person new to graphical programming and programming in general for that matter:
What is this doublebuffering that i have been seeing. I tried searching arround and could not get a good explanation. Anybody?
>What is this doublebuffering [?]
doublebuffering means that u use two buffers for your graphics (wow :))
well u have one buffer wich is used for your drawing action... and another wich is currently shown on the screen. this way u avoid the flickering wich usually occurs since the user doesnt see the drawing itself anymore. only the frames wich are finished.
there are two ways to do that.
one way is blitting (or BLT). there u have a backbuffer and a frontbuffer. u draw all stuff in your backbuffer and when u r done with that u copy (blit) the whole thingy into the frontbuffer wich is displayed all the time.
the other way is page flipping ("page" is the buffer). this one is better. u have (at least) two buffers. one is displayed and the other is used for drawing. sounds familiar doesnt it? well the difference is, when u r done with drawing u dont copy it to the frontbuffer - instead u display that buffer and draw then into the buffer wich was the frontbuffer before. the pages get simply fipped - therefore flipping :)
u might ask why there are two ways to do that since flipping is better. well the answer is simple if u r not in fullscreen mode u cant flip the pages cuz your programm only knows how to draw onto itself and doesnt even have a clue what else is goin on onto the screen. therefore u have to use blitting in windowed applications (or applets).
well if u use bufferstrategy u dont have to worry bout that. in fullscreen bufferstrategy will use flipping and windowed it will use blitting - therefore it's quite easy to implement fullscreen, windowed or even an option to switch between 'em later ;)
oNyxa at 2007-7-18 20:33:30 >

a question a bit more to the point of this thread:
I extended the Button class and made an image that is clickable. the only problem is that it only shows a small protion of the top left corner of the image. I am using FlowLayout. when i extended the button class i used setSize to set the size of the button. Is this not enough? should i set some other dimentional variables?
narrow it down a little: is there a way to set the prefered size?or should i just put it in a container with Border Layout in the center position and then use that contaiener as the card button? did that make cense?