🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.jbuilder.java.swing
Article #7605

Here's some more information

#7605
From: Jason Swett
Date: Sun, 07 Jan 2001 15:06
71 lines
2848 bytes
I tried writing the following application after reading a bit more.  I
created my own "ImagePanel" by slightly extending JPanel, but still can't
get the image to display.  Can you tell me what's wrong with the code?
Thanks.  (I added a re-paint button just for kicks, but it doesn't
accomplish anything.)

package testpaint1;

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class Frame1 extends JFrame {
  JPanel contentPane;
  JButton jButton1 = new JButton();
  ImagePanel imagePanel1 = new ImagePanel();

  /**Construct the frame*/
  public Frame1() {
    enableEvents(AWTEvent.WINDOW_EVENT_MASK);
    try {
      jbInit();
    }
    catch(Exception e) {
      e.printStackTrace();
    }
  }

  /**Component initialization*/
  private void jbInit() throws Exception  {

    jButton1.setText("Repaint");
    jButton1.setBounds(new Rectangle(28, 31, 79, 27));
    jButton1.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(ActionEvent e) {
        jButton1_actionPerformed(e);
      }
    });
    contentPane = (JPanel) this.getContentPane();
    contentPane.setLayout(null);
    this.setSize(new Dimension(400, 300));
    this.setTitle("Frame Title");
    imagePanel1.setBounds(new Rectangle(28, 79, 227, 132));
    contentPane.add(jButton1, null);
    contentPane.add(imagePanel1, null);
  }

  /**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);
    }
  }

  void jButton1_actionPerformed(ActionEvent e) {
    repaint();
  }

}

// Define a custom Jpanel -- with images

class ImagePanel extends JPanel {
  public void paintComponent(Graphics g) {
    super.paintComponent(g);
    Toolkit toolkit = Toolkit.getDefaultToolkit();
    Image image1 = toolkit.getImage("C:\176.JPG");
    g.drawImage(image1,0,0,this);
  }
}
Technical Details
Message-ID: <3a588647_2@dnews>
Path: arc1-ca.pugleaf.net!supernews.google.com!sn-xit-02!supernews.com!news.tele.dk!193.190.198.17!newsfeeds.belnet.be!naxos.belnet.be!news.belnet.be!bornews.borland.com!dnews!204.157.20.118
References: <3a587c79_2@dnews>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 111d45,3d5e8a1122bfe253
X-Google-Attributes: gid111d45,public
X-Google-ArrivalTime: 2001-01-07 07:10:49 PST
From: "Jason Swett" <swettboy@ncats.net>
Newsgroups: borland.public.jbuilder.java.swing
References: <3a587c79_2@dnews>
Subject: Here's some more information
Date: Sun, 7 Jan 2001 10:06:58 -0500
Lines: 74
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 5.50.4133.2400
X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4133.2400
NNTP-Posting-Host: 204.157.20.118
Message-ID: <3a588647_2@dnews>
X-Trace: 7 Jan 2001 07:07:51 -0800, 204.157.20.118
Path: arc1-ca.pugleaf.net!supernews.google.com!sn-xit-02!supernews.com!news.tele.dk!193.190.198.17!newsfeeds.belnet.be!naxos.belnet.be!news.belnet.be!bornews.borland.com!dnews!204.157.20.118