当前位置: 代码迷 >> Java相关 >> 关于JAVA Applet 背景图片问题
  详细解决方案

关于JAVA Applet 背景图片问题

热度:824   发布时间:2009-10-26 14:26:15.0
关于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  

----------------解决方案--------------------------------------------------------
顶!
----------------解决方案--------------------------------------------------------
  相关解决方案