Java applet setSize not accurate, window too large

感情迁移 提交于 2019-12-04 02:20:09

问题


I have a Java applet that J am trying to to set to 480, 800 using setSize but the window comes up 487,850 for some reason. here is the code where it is set.

public void init() {
        setSize(480,800);
        setBackground(Color.BLUE);
        setFocusable(true);
        addMouseListener(this);
        addKeyListener(this);
        Frame frame = (Frame) this.getParent().getParent();
        frame.setTitle("SwingBall");
        try {
         base = getDocumentBase();
        } catch (Exception e) {
        // TODO: handle exception
        }
}

There is no other mention of setting size anywhere else in code, any idea as to why this is happening?


回答1:


You don't set the size of the applet in the applet itself, and trying to do this will have no effect, as you're finding out. If you want to specify the size of the applet, you do this in the HTML code that calls the applet.

As an aside, your //TODO: handle exception is telling you something important, that you shouldn't leave the catch block empty.



来源:https://stackoverflow.com/questions/24027411/java-applet-setsize-not-accurate-window-too-large

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!