Go Back   CodingForums.com > :: Server side development > Java and JSP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 01-23-2009, 09:51 PM   PM User | #1
DELOCH
Regular Coder

 
DELOCH's Avatar
 
Join Date: Apr 2006
Location: Canada
Posts: 537
Thanks: 4
Thanked 2 Times in 2 Posts
DELOCH is an unknown quantity at this point
Simple Image Problem

PHP Code:
import javax.swing.*;
import java.awt.*;

public class 
ImageDraw extends JFrame
{
    public 
ImageDraw()
    {
        
super("");
        
setSize(300300);
        
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        
setVisible(true);
    }
    public static 
void main(String[] args){new ImageDraw();}
}
class 
ImagePanel extends JPanel
{
    public 
void paintComponent(Graphics g)
    {
        
super.paintComponent(g);
        
Image im = new ImageIcon("image.jpg").getImage();
        
g.drawImage(im00null);
    }

the code above id a dumb code for placing an "image.jpg" onto the program...

somewhy it doesn't work...

I also tried using Toolkit.getDefaultToolkit().getImage() but it doesn't work(although when i checked it's getWidth, getHeight methods, they returned -1...<<error).

thanks ahead of time... images are a big part of making... anything
i know i can use bufferedimage but that's longer code...
DELOCH is offline   Reply With Quote
Old 01-26-2009, 01:31 PM   PM User | #2
icm9768
New Coder

 
Join Date: Jun 2005
Posts: 32
Thanks: 0
Thanked 2 Times in 2 Posts
icm9768 is an unknown quantity at this point
I don't see you actually instantiating an ImagePanel anywhere and putting it in the frame. Try adding something like:

super("");
setSize(300, 300);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
--> setContentPane( new ImagePanel() );
setVisible(true);
icm9768 is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 07:39 PM.


Advertisement
Log in to turn off these ads.