首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > J2SE开发 >

加载背景图片有关问题

2013-06-25 
加载背景图片问题public void LanuchFrame(){this.setLocation(100,100)this.setSize(400,300)layoutne

加载背景图片问题
public void LanuchFrame(){
this.setLocation(100,100);
this.setSize(400,300);
layout=new FlowLayout(FlowLayout.LEFT,20,5);
getContentPane().setLayout(layout);
        button1=new JButton("文件传输");
        button2=new JButton("图片发送");
        button3=new JButton("视频会话");
panel=new JPanel();
panel.add(button1);
panel.add(button2);
panel.add(button3);
    getContentPane().add(panel);
    add(taContent);
add(tfTxt);
}这是我窗口代码,我想加载一张背景图片,是透明的能够显示图片上方的文字,
加载背景图片有关问题
就是在这个窗口中加载一张充满整个频幕的图片。
求高人改正啊!代码如下:

package org.zhangming.swing;

import java.awt.BorderLayout;
import java.awt.Container;
import java.awt.FlowLayout;
import java.awt.Image;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.*;


public class TestBackImage extends JFrame
{
private JButton button1,button2,button3;
private JTextField text;
private JTextArea area;
private ImageIcon icon;
private JPanel panelS,panelN;
private JLabel backLabel;
TestBackImage()
{
     button1=new JButton("文件传输");
     button2=new JButton("图片发送");
     button3=new JButton("视频会话");
     text = new JTextField(20);
     area = new JTextArea(15,20);
     
     button1.addActionListener(new ActionListener(){
     @Override
    public void actionPerformed(ActionEvent e)
    {
    
    area.setText(area.getText() + "\n" +text.getText());
    text.setText("");
    
    }
     });
     
     icon = new ImageIcon("e:/Tulips.jpg");
     backLabel = new JLabel(icon);
     backLabel.setSize(280,380);
     icon.setImage(icon.getImage().getScaledInstance(280,380,Image.SCALE_DEFAULT));
     panelS = new JPanel();
     panelN = new JPanel();
     
     panelN.setLayout(new FlowLayout());
     panelN.add(button1);
     panelN.add(button2);


     panelN.add(button3);
     
     panelS.add(area,BorderLayout.CENTER);
     panelS.add(text,BorderLayout.SOUTH);
     
     this.getLayeredPane().add(backLabel,Integer.MIN_VALUE);
     
     Container container = this.getContentPane();
     container.add(panelN,BorderLayout.NORTH);
     container.add(panelS,BorderLayout.CENTER);
     
     //该怎样将JFrame上的ContentPane这层设为透明啊

    ((JComponent) container).setOpaque(false);

//     panelN.setOpaque(false);
//     panelS.setOpaque(false);
//     AWTUtilities.setWindowOpacity(this, 0.8F); 
   
     this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
     this.setSize(280,380);
     this.setResizable(false);
     this.setVisible(true);
}
public static void main(String[] args)
{
new TestBackImage();
}
}



注: 在文本框输入文字,点击“传送文件”按钮方能出现文本域,还有就是其他两个按钮只有当鼠标经过时才会显示出来,
求大神帮忙看下

热点排行