| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1280 人关注过本帖
标题:关于JAVA Applet 背景图片问题
只看楼主 加入收藏
漫天花雨
Rank: 1
等 级:新手上路
帖 子:90
专家分:0
注 册:2008-7-13
结帖率:100%
收藏
 问题点数:0 回复次数:1 
关于JAVA Applet 背景图片问题
当我添加
    public void paint(Graphics g) // <======================== new ===========================>
    {
        super.paint(g);
        g.drawImage(0,0,background);
    } 时,会告诉我找不到符号。。。这是为什么呢?
我写的是一段java applet程序 想弄个背景图片进去,我仅仅给出public class代码,其他部分代码 因为比较长,就没贴进来,应该不会影响到背景图片的添加问题



public class Graph extends Applet implements ActionListener, ItemListener {

    GraphPanel panel;
    Panel controlPanel;
   
    Image background; //<================= new ========================>

    public void init() {
        
        background = getImage(getCodeBase(), "background.png"); // <======================= new ========================>
        
        
        setLayout(new BorderLayout());

        panel = new GraphPanel(this);    //creat GraphPanel instance for painting the nodes and edges
        add("Center", panel);    //set position for panel
        controlPanel = new Panel();    //creat Panel instance for furture use

        String edges = getParameter("edges");    //read from .htm file
        for (StringTokenizer t = new StringTokenizer(edges, ","); t.hasMoreTokens();) {
            String str = t.nextToken();
            int i = str.indexOf('-');    //find the index(position) of "-" in the string "str"
            if (i > 0) {
                int len = 50;
                int j = str.indexOf('/');
                if (j > 0) {
                    len = Integer.valueOf(str.substring(j + 1)).intValue();    //len is set to "int" type
                    str = str.substring(0, j);    //str contains strings of two nodes
                }

                String from = str.substring(0, i);    //strfrom is the strings of "from" node
                String to = str.substring(i + 1);    //strto is the strings of "to" node
                int tonodeNo = 0;
                int n = to.indexOf('_');

                if (n > 0) {
                    tonodeNo = Integer.valueOf(to.substring(n + 1)).intValue();
                    panel.addEdge(from, to.substring(0, n), tonodeNo, len);
                } else
                    panel.addEdge(from, to, tonodeNo, len);
            }
        }
        Dimension d = getSize();
        String center = getParameter("center");
        if (center != null) {
            Node n = panel.nodes[panel.findNode(center)];
            n.x = d.width / 2;
            n.y = d.height / 2;
            n.fixed = true;
            panel.nodes[panel.findNode(center)].isvisible = true;
        }
        panel.centerNode();
    }


    public void destroy() {
        remove(panel);
        remove(controlPanel);
    }

    public void start() {
        panel.start();
    }

    public void stop() {
        panel.stop();
    }

    public void actionPerformed(ActionEvent e) {
        Object src = e.getSource();
    }

    public void itemStateChanged(ItemEvent e) {
        Object src = e.getSource();
        boolean on = e.getStateChange() == ItemEvent.SELECTED;
    }

    public String[][] getParameterInfo() {
        String[][] info = {
                {
                        "edges",
                        "delimited string",
                        "A comma-delimited list of all the edges.  It takes the form of 'C-N1,C-N2,C-N3,C-NX,N1-N2/M12,N2-N3/M23,N3-NX/M3X,...' where C is the name of center node (see 'center' parameter) and NX is a node attached to the center node.  For the edges connecting nodes to eachother (and not to the center node) you may (optionally) specify a length MXY separated from the edge name by a forward slash." },
                { "center", "string", "The name of the center node." } };
        return info;
    }
        public void paint(Graphics g) // <======================== new ===========================>
    {
        super.paint(g);
        g.drawImage(0,0,background);
    }
}


多谢各位大侠帮忙。。。。小弟很急
搜索更多相关主题的帖子: JAVA Applet 
2009-10-26 14:26
漫天花雨
Rank: 1
等 级:新手上路
帖 子:90
专家分:0
注 册:2008-7-13
收藏
得分:0 
顶!

雪梨的深秋。。。。。。凉爽!~
2009-10-26 15:10
快速回复:关于JAVA Applet 背景图片问题
数据加载中...
 
   



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

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