| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 571 人关注过本帖
标题:来人挑错~~
只看楼主 加入收藏
LegendofMine
该用户已被删除
收藏
已结贴  问题点数:40 回复次数:2 
来人挑错~~
提示: 作者被禁止或删除 内容自动屏蔽
搜索更多相关主题的帖子: 挑错 来人 
2010-10-31 13:19
linjx0123
Rank: 9Rank: 9Rank: 9
等 级:贵宾
威 望:14
帖 子:279
专家分:1362
注 册:2006-4-7
收藏
得分:20 
package hack.

import javax.swing.*;
import java.awt.image.*;
import java.awt.*;
import *;
import javax.imageio.*;

public class WaterMarkTextField extends JTextField{
    BufferedImage img;
    TexturePaint texture;
   
    public WaterMarkTextField(File file) throws IOException{
        super();
        img = ImageIO.read(file);
        
        Rectangle rect = new Rectangle(0, 0,
                img.getWidth(null), img.getHeight(null));
        texture = new TexturePaint(img, rect);
        
      //  setOpaque(false); 这句不要
    }
   
    public void paintComponent(Graphics g) { //方法名错误
        super.paintComponent(g);
      
        Graphics2D g2 = (Graphics2D) g;
        g2.setPaint(texture);
        g.fillRect(0,0,getWidth(),getHeight()); //这两句话看不懂。其实觉得直接调用g.drawImage就行了
    }
   
    public static void main(String argv[]) throws Exception{
        JFrame frame = new JFrame("A text field");
        JTextField textfield = new WaterMarkTextField(
                new File("bg.png"));
        textfield.setText("Hello world");
        frame.getContentPane().add(textfield);
        frame.pack();
        frame.setVisible(true);
    }
}

2010-11-01 09:45
wdwy277
Rank: 2
等 级:论坛游民
帖 子:16
专家分:31
注 册:2009-5-19
收藏
得分:20 
这样的活动蛮好的,知识难度太高了,看不懂,有最简单的么
2010-11-01 23:52
快速回复:来人挑错~~
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.015695 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved