URGENT! : how to draw images?

new to swing, wanna create an app using jframes but how do i draw my images? added 2 jpanels to my jframe to split the window into 2, 1 side for text, the other is for my images. but how do i draw them on the jpanel? read the java tutorial but it only shows me class xxx extends jpanel. must i do this? if i must, where shld my jframe be? really need some help right away cos i'm doing it for a project n deadline's coming soon...

i attached the source code as following:(made by jbuilder)
package untitled3;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class Frame1 extends JFrame {
private JPanel contentPane;
private BorderLayout borderLayout1 = new BorderLayout();
private JSplitPane jSplitPane1 = new JSplitPane();
private JTextArea jTextArea1 = new JTextArea();
private JPanel jPanel1 = new JPanel();
//Construct the frame
public Frame1() {
enableEvents(AWTEvent.WINDOW_EVENT_MASK);
try {
jbInit();
catch(Exception e) {
e.printStackTrace();
//Component initialization
private void jbInit() throws Exception {
//setIconImage(Toolkit.getDefaultToolkit().createImage(Frame1.class.getResource("[Your Icon]")));
contentPane = (JPanel) this.getContentPane();
contentPane.setLayout(borderLayout1);
this.setSize(new Dimension(400, 300));
this.setTitle("Frame Title");
jTextArea1.setText("jTextArea1");
contentPane.add(jSplitPane1, BorderLayout.CENTER);
jSplitPane1.add(jTextArea1, JSplitPane.LEFT);
jSplitPane1.add(jPanel1, JSplitPane.RIGHT);
//Overridden so we can exit when window is closed
protected void processWindowEvent(WindowEvent e) {
super.processWindowEvent(e);
if (e.getID() == WindowEvent.WINDOW_CLOSING) {
System.exit(0);
package untitled3;
import javax.swing.UIManager;
import java.awt.*;
public class Application1 {
private boolean packFrame = false;
//Construct the application
public Application1() {
Frame1 frame = new Frame1();
//Validate frames that have preset sizes
//Pack frames that have useful preferred size info, e.g. from their layout
if (packFrame) {
frame.pack();
else {
frame.validate();
//Center the window
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
Dimension frameSize = frame.getSize();
if (frameSize.height > screenSize.height) {
frameSize.height = screenSize.height;
if (frameSize.width > screenSize.width) {
frameSize.width = screenSize.width;
frame.setLocation((screenSize.width - frameSize.width) / 2, (screenSize.height - frameSize.height) / 2);
frame.setVisible(true);
//Main method
public static void main(String[] args) {
try {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
catch(Exception e) {
e.printStackTrace();
new Application1();
}

Similar Messages

  • How to draw image in different dpi?

    I wonder is there any approach can be used to draw a image in different dpi, such as 144dpi, in a JPanel?
    'cause my image processed from other tools is not good, if I can draw image in a high dpi, then the image will looks much better, though the image becomes smaller.
    Note: no SCALE!

    I have a image which is 152dpi, then, how does the Widows draws this image? It looks much better than scale the 72dpi image to the same size.
    Really puzzled-_-                                                                                                                                                                                                                                                                                                                               

  • How to draw images at a particular spot in a subview

    When you load an image into a UIImageView:
    {CODE}
    UIImageView* page1 = [[UIImageView alloc] initWithImage: [UIImage imageNamed:@"page1.jpg"]];
    [myparentview addSubView:page1];
    {CODE}
    That works fine, and you get an UIImageView object with the picture at (0,0).
    If you add another UIImageView to the parent UIView object, then when that UIView is drawn you get the picture at 0,0 again, and it overwrites the first picture. I want to draw a series of sub-picutures into a giant view. When you add a subview is there any coordinate translation that happens, I tried zapping the frame() or bounds() variables of the subview to make it draw differently but that doesn't seem to change anything.

    Do this:
    UIImageView *page1 = [[UImageView alloc] initWithImage:[UIImage imageNamed:@"page1.jpg"]];
    CGRect frame = page1.frame;
    frame.origin.x = newX;
    frame.origin.y = newY;
    page1.frame = frame;
    [myParentView addSubView:page1];
    And use {code}, not {CODE}

  • How can I draw image in a vbean?

    How can I draw image in a vbean?
    this is my code :
    import java.awt.BorderLayout;
    import java.awt.Image;
    import java.awt.Graphics;
    import java.net.MalformedURLException;
    import java.net.URL;
    import com.sun.jimi.core.Jimi;
    import oracle.forms.handler.IHandler;
    import oracle.forms.properties.ID;
    import oracle.forms.ui.VBean;
    public class PrintEmailLogo extends VBean {
         URL url;
         Image img;
         boolean ImageLoaded = false;
         public void paint(Graphics g) {
              if (ImageLoaded) {
                   System.out.println("yes~~~");
                   g.drawImage(img, 0, 0, null);
              } else
                   System.out.println("no~~~");
         public boolean imageUpdate(Image img, int infoflags, int x, int y, int w,
                   int h) {
              if (infoflags == ALLBITS) {
                   System.out.println("yes");
                   ImageLoaded = true;
                   repaint();
                   return false;
              } else
                   return true;
         public void init(IHandler arg0) {
              super.init(arg0);
              try {
                   url = new URL("file:print/77G.gif");
                   img = Jimi.getImage(url);
                   Image offScreenImage = createImage(size().width, size().height);
                   Graphics offScreenGC = offScreenImage.getGraphics();
                   System.out.println(offScreenGC.drawImage(img, 0, 0, this));
              } catch (MalformedURLException e) {
                   // TODO Auto-generated catch block
                   e.printStackTrace();
    but when I run it in forms
    when it run Graphics offScreenGC = offScreenImage.getGraphics();
    It throw a exception:
    java.lang.NullPointerException     at com.avicit.aepcs.calendar.PrintEmailLogo.init(PrintEmailLogo.java:72)     at oracle.forms.handler.UICommon.instantiate(Unknown Source)     at oracle.forms.handler.UICommon.onCreate(Unknown Source)     at oracle.forms.handler.JavaContainer.onCreate(Unknown Source)     at oracle.forms.engine.Runform.onCreateHandler(Unknown Source)     at oracle.forms.engine.Runform.processMessage(Unknown Source)     at oracle.forms.engine.Runform.processSet(Unknown Source)     at oracle.forms.engine.Runform.onMessageReal(Unknown Source)     at oracle.forms.engine.Runform.onMessage(Unknown Source)     at oracle.forms.engine.Runform.processEventEnd(Unknown Source)     at oracle.ewt.lwAWT.LWComponent.redispatchEvent(Unknown Source)     at oracle.ewt.lwAWT.LWComponent.processEvent(Unknown Source)     at java.awt.Component.dispatchEventImpl(Unknown Source)     at java.awt.Container.dispatchEventImpl(Unknown Source)     at java.awt.Component.dispatchEvent(Unknown Source)     at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)     at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)     at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)     at java.awt.Container.dispatchEventImpl(Unknown Source)     at java.awt.Component.dispatchEvent(Unknown Source)     at java.awt.EventQueue.dispatchEvent(Unknown Source)     at java.awt.EventDispatchThread.pumpOneEventForHierarchy(Unknown Source)     at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)     at java.awt.EventDispatchThread.pumpEvents(Unknown Source)     at java.awt.EventDispatchThread.run(Unknown Source)
    I change it to:
    import java.awt.BorderLayout;
    import java.awt.Image;
    import java.awt.Graphics;
    import java.net.MalformedURLException;
    import java.net.URL;
    import javax.swing.JFrame;
    import com.sun.jimi.core.Jimi;
    import oracle.forms.handler.IHandler;
    import oracle.forms.properties.ID;
    import oracle.forms.ui.VBean;
    public class PrintEmailLogo extends VBean {
         URL url;
         Image img;
         public void paint(Graphics g) {
              try {
                   url = new URL("file:print/77G.gif");
                   img = Jimi.getImage(url);
                   g.drawImage(img, 0, 0, this));
              } catch (MalformedURLException e) {
                   // TODO Auto-generated catch block
                   e.printStackTrace();
         public void init(IHandler arg0) {
              super.init(arg0);
    But it display nothing.
    It isn't paint continuous.
    what's wrong in my vbean?
    please help me.

    The following code works fine for me:
    package oracle.forms.fd;
    import java.awt.*;
    import java.awt.event.*;
    import java.net.*;
    import java.util.*;
    import javax.swing.*;
    import javax.swing.event.*;
    import oracle.forms.handler.IHandler;
    import oracle.forms.properties.ID;
    import oracle.forms.ui.CustomEvent;
    import oracle.forms.ui.VBean;
    public class test extends VBean {
      private URL url;
      private URL m_codeBase; 
      private Image img;
    public void paint(Graphics g) {
      // draw the image
      g.drawImage(img, 0, 0, this);
    public void init(IHandler arg0) {
       super.init(arg0);
       // load image file
       img = loadImage("file:///c:/coyote.jpg");   
    public test()
        super();
       *  Load an image from JAR file, Client machine or Internet URL  *
      private Image loadImage(String imageName)
        URL imageURL = null;
        boolean loadSuccess = false;
        Image img = null ;
        //JAR
        imageURL = getClass().getResource(imageName);
        if (imageURL != null)
          try
            img = Toolkit.getDefaultToolkit().getImage(imageURL);
            loadSuccess = true;
            return img ;
          catch (Exception ilex)
            System.out.println("Error loading image from JAR: " + ilex.toString());
        else
          System.out.println("Unable to find " + imageName + " in JAR");
        //DOCBASE
        if (loadSuccess == false)
          System.out.println("Searching docbase for " + imageName);
          try
            if (imageName.toLowerCase().startsWith("http://")||imageName.toLowerCase().startsWith("https://"))
              imageURL = new URL(imageName);
            else if(imageName.toLowerCase().startsWith("file:"))
              imageURL = new URL(imageName);
            else
              imageURL = new URL(m_codeBase.getProtocol() + "://" + m_codeBase.getHost() + ":" + m_codeBase.getPort() + imageName);
            System.out.println("Constructed URL: " + imageURL.toString());
            try
              img = createImage((java.awt.image.ImageProducer) imageURL.getContent());
              loadSuccess = true;
              System.out.println("Image found: " + imageURL.toString());
              return img ;
            catch (Exception ilex)
              System.out.println("Error reading image - " + ilex.toString());
          catch (java.net.MalformedURLException urlex)
            System.out.println("Error creating URL - " + urlex.toString());
        //CODEBASE
        if (loadSuccess == false)
          System.out.println("Searching codebase for " + imageName);
          try
            imageURL = new URL(m_codeBase, imageName);
            System.out.println("Constructed URL: " + imageURL.toString());
            try
              img = createImage((java.awt.image.ImageProducer) imageURL.getContent());
              loadSuccess = true;
              System.out.println("Image found: " + imageURL.toString());
              return img ;
            catch (Exception ilex)
                    System.out.println("Error reading image - " + ilex.toString());
          catch (java.net.MalformedURLException urlex)
            System.out.println("Error creating URL - " + urlex.toString());
        if (loadSuccess == false)
          System.out.println("Error image " + imageName + " could not be located");
        return img ;
    }Francois

  • How to draw 2D shapes on the image generated by JMF MediaPlayer?

    Hello all:
    IS there any way that we can draw 2D shapes on the image generated by JMF
    MediaPlayer?
    I am currently working on a project which should draw 2D shapes(rectangle, circle etc) to
    mark the interesting part of image generated by JMF MediaPlayer.
    The software is supposed to work as follows:
    1> first use will open a mpg file and use JMF MediaPlayer to play this video
    2> if the user finds some interesting image on the video, he will pause the video
    and draw a circle to mark the interesting part on that image.
    I know how to draw a 2D shapes on JPanel, however, I have no idea how I can
    draw them on the Mediaplayer Screen.
    What technique I should learn to implement this software?
    any comments are welcome.
    thank you
    -Daniel

    If anyone can help?!
    thank you
    -Daniel

  • How draw image into frame in applet

    How draw image into frame in applet.Please give my simple example code.

    http://search.java.sun.com/search/java/index.jsp?qt=%2Bdraw+%2Bimage+%2Bpanel+%2Bhow&nh=10&qp=&rf=1&since=&country=&language=&charset=&variant=&col=javaforums

  • How to draw transparent image?

    i'm developing a java game, i wonder how to draw a transparent image, i'm using Image class, and Graphics class.

    http://search.java.sun.com/search/java/index.jsp?qp=forum%3A20&nh=10&qt=%2Btransparent+%2Bimage&col=javaforums

  • Drawing image Urgent!

    hai Guys!
    is it possible to draw image in xor mode using drawregion or drawimage if yes then how it can be done!

    hi frens..
    Is there way of drawing an image on Frame
    without erasing previous image. Each time the
    repaint() is called for drawing new image on frame
    using Graphics object, repaint() just clears the
    previous images , but i want previous image to be
    sustained .
    ImageIcon WhiteIcon = new ImageIcon("White.GIF");
    JL = new JLabel(null ,WhiteIcon, 0 );
    f.add(JL);Hope this will do.

  • Blast from the past: How do I draw image maps in Dreamweaver CC 2014?

    Need to update some old stuff, and can´t find where to draw image-maps on images.

    First, you need to be in Design View to get the image map tools to appear.
    Once there, the image map icons should show when you select an image. If they don't, you may have your Properties panel collapsed. In the bottom right corner of the Properties panel, there's a tiny triangle, click that to expand the panel to include the image map tools.

  • Can one add more than one photo layer to a draw image?

    I cannot seem to find a way to add more than one photo or photo layer to a Draw image, but the Draw page on Adobe seems to imply multiple photos can be added. How might I accomplish this? Thanks for your time.

    Unfortunately, Draw is currently limited to one photo layer, and only one photo within that layer.
    Hope that helps,
    Frank
    Draw Engineering

  • How to draw horizontal line in smartform after end of the all line items

    Hi Friends,
    I am working on the smartform. I have created TABLE node in Main window.
    i want to draw a horizontal line after end of the main window table node. i mean after printing all the line items of the table, I need to print one horizontal line.
    Could you please help me how to resolve this issue.
    FYI: I tried with the below two options. But no use.
    1. desinged footer area in the table node of the main window.
    2. tried with uline and system symbols.
    please correct me if i am wrong. please explain in detail how to draw horizontal line after end of the main window table.
    this is very urgent.
    Thanks in advance
    Regards
    Raghu

    Hello Valter Oliveira,
    Thanks for your answer. But I need some more detail about blank line text. i.e thrid point.
    Could you please tell me how to insert blank line text.
    1 - in your table, create a line type with only one column, with the same width of the table
    2 - in table painter, create a line under the line type
    3 - insert a blank line text in the footer section with the line type you have created.

  • How to display images at runtime in a web appplication

    i use C#. and also, how do i get an image to be downloaded from mysql database at runtime upon request. here is a bit of my declaration code and conditional construct code
     byte [] f = (byte[])(read["Passport"]); // this reads d byte data from the column passport in the database and assigns it to byte f.
    if (f == null)
           admin1pass.ImageUrl = null;
     else
           MemoryStream ms = new MemoryStream(f); // this holds the image gotten from the database
           admin1pass.ImageUrl = System.Drawing.Image.FromStream(ms);
    'now thats where i'm stuck. i hv used the
    using System.Drawing;
    using System.Data;
    namespaces but none contains the class Image which is oftren what i use in windows form apps.

    They'll help you over here.
    Microsoft C# ASP.Net forum
    Regards, Dave Patrick ....
    Microsoft Certified Professional
    Microsoft MVP [Windows]
    Disclaimer: This posting is provided "AS IS" with no warranties or guarantees , and confers no rights.

  • How to Draw 3-D scatter plot in J2ME?

    HI all
    I am new in J2ME And I need to draw a three dimensional scatter plot in J2ME application. Can any body help me how to do so? It's urgent and I am eagerly waiting for your response. Even if you can tell me how to draw a 3-D point like (x,y,z)=(3,5,8) in J2ME?

    I've removed the thread you started in the Java3D forum.
    db

  • Draw images in different Panels

    Hi,
    I have a JFrame with three JPanels.
    How can I draw three different Buffered images to those three JPanels?
    Code is appreciated.

    devboris wrote:
    Hi,
    I have a JFrame with three JPanels.
    How can I draw three different Buffered images to those three JPanels?Do you know how to draw one BufferedImage in one JPanel? If not, start there.
    Code is appreciated.An [SSCCE |http://sscce.org] is appreciated.

  • How to make image out of panel?

    hi,
    i have a JPanel object and i drawn something on this panel. it also contains somemore components. can anyone say how to create image (like .jpg) from what is getting displayed in my panel.
    thankx in advance.

    Found this in the newgroups
    If you are using Java 2D, you can create a JPEG image by using the
    com.sun.image.codec.jpeg package. The code below creates a JPEG image and
    saves it to a file.
    public void save(BufferedImage destImage, String filename) {
    try {
    ByteArrayOutputStream boutstream = new ByteArrayOutputStream();
    JPEGImageEncoder enc = JPEGCodec.createJPEGEncoder(boutstream);
    enc.encode(destImage);
    FileOutputStream fimage = new FileOutputStream(new File(filename));
    boutstream.writeTo(fimage);
    fimage.close();
    } catch (Exception e) { }
    The code snippet below shows how to crerate a BufferedImage:
    BufferedImage bi = new BufferedImage((int)imWid,
    (int)(imHt),
    BufferedImage.TYPE_INT_RGB);
    Graphics2D g2d = bi.createGraphics();
    g2d.drawImage(img, dispTx,this);
    img : Your image object.
    dispTx: The Affine Transform.
    You can use other drawImage()methods for drawing images.
    Once the image is drawn, you can save it using the save() method.

Maybe you are looking for

  • NO SOUND with iMAC 24 - Please help

    I have tried everything.........searched for drivers, everything, installed boot camp drivers from the CD numerous times.........I can't get rid of the ?pci device that shows up in the device manager. I am using windows xp sp3. The ? still shows up i

  • True Delete or Empty Trash on Single Volume?

    Howdy, all! I've done a bit of poking around and I think I have the answer to this question (though it isn't a particularly satisfying one), but I'm hoping I'm missing something. I take photos on an SD card.  I copy the JPGs to my laptop, JPG+RAW to

  • Tax types not available in SD

    Hi all While I am defining tax relevancy in SD (transaction OVK3 and OVK4), I couldn't find the new tax type created in FI  (created thougth path--> financial accounting >financial accounting global settings >tax on sales/purchases > basic setting >c

  • Live type render movie issue

    This goes out to you Live type gurus.  I have a 6 second animation with video.  It renders in the timeline fine but when I "render movie" the finished product only shows about half of the total project. eg it stops half way through the entire clip. 

  • Suddenly unable to combine word documents

    Hi, I've been using Adobe Acrobat X every quarter to prepare a PDF for a board meeting, combining Word Documents and PDFs. It's always worked fine, but all of a sudden I can't combine Word anymore. The error message that I receive is "Please remove p