Java applet setSize不正确,窗口太大 [英] Java applet setSize not accurate, window too large

查看:138
本文介绍了Java applet setSize不正确,窗口太大的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Java小程序,J试图使用setSize将其设置为480、800,但是由于某种原因,窗口出现487,850.这是设置它的代码.

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?

推荐答案

您没有在applet本身中设置applet的大小,并且尝试这样做不会产生任何效果,正如您所发现的那样.如果要指定小程序的大小,请在调用小程序的HTML代码中执行此操作.

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.

顺便说一句,您的//TODO: handle exception告诉您一些重要的信息,您不应将catch块留空.

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

这篇关于Java applet setSize不正确,窗口太大的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆