import java.awt.*;
import java.awt.event.*;
public class EXAM 
{
public static void main(String arg[])
{
Frame frame=new Frame(); Toolkit kit=Toolkit.getDefaultToolkit();
         Image back=kit.getImage("枫叶.jpg");

frame.setSize(400,300);
frame.setVisible(true);

}
}
我想在背景中添加 图片  不知道 怎么加
       

解决方案 »

  1.   

    package test;/*  
     *   Background.java  
     *  
     *   Created   on   2005年7月25日,   下午3:40  
     *//**
     * 
     * @author Administrator
     */
    public class Background extends javax.swing.JFrame {  /** Creates new form Background */
      public Background() {
        initComponents();
      }  /**
       * This method is called from within the constructor to initialize the form. WARNING: Do NOT modify this code. The content of
       * this method is always regenerated by the Form Editor.
       */
      private void initComponents() {
        jLabel1 = new javax.swing.JLabel();    addWindowListener(new java.awt.event.WindowAdapter() {
          public void windowClosing(java.awt.event.WindowEvent evt) {
            exitForm(evt);
          }
        });    jLabel1.setIcon(new javax.swing.ImageIcon("d:\\Struts2-Architecture.png"));// 楼主要的背景文件路径
        jLabel1.setText("jLabel1");
        getContentPane().add(jLabel1, java.awt.BorderLayout.CENTER);    pack();
      }  /** Exit the Application */
      private void exitForm(java.awt.event.WindowEvent evt) {
        System.exit(0);
      }  /**
       * @param args the command line arguments
       */
      public static void main(String args[]) {
        new Background().show();
      }  // Variables declaration - do not modify
      private javax.swing.JLabel jLabel1;
      // End of variables declaration}
      

  2.   

    JLabel能容纳的东西太少了,如果仅仅实现JFrame上有一个背景例子是合格的,如果要放其他的东西,建议用其他容器,或者重载paint(Graphics g)方法