问题
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