Java小程序setSize不准确,窗口太大 [英] Java applet setSize not accurate, window too large

查看:34
本文介绍了Java小程序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?

推荐答案

您没有在小程序本身中设置小程序的大小,正如您发现的那样,尝试这样做将没有任何效果.如果要指定小程序的大小,请在调用小程序的 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小程序setSize不准确,窗口太大的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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