我有一个小程序(这是一个 SSCCE):
package tutoringcalculator;
import java.awt.BorderLayout;
import java.awt.FlowLayout;
import javax.swing.*;
public class TutoringCalculator extends JApplet {
private JPanel _root;
public static void main(String[] args) {
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
JFrame frame = new JFrame("Tutoring Calculator");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JApplet applet = new TutoringCalculator();
applet.init();
frame.setContentPane(applet.getContentPane());
frame.pack();
frame.setLocationRelativeTo(null);
frame.setVisible(true);
applet.start();
}
});
}
private JPanel swingContainer;
@Override
public void init() {
swingContainer = new JPanel(new BorderLayout());
add(swingContainer, BorderLayout.CENTER);
createScene();
setSize(600, 400);
}
private void createScene() {
JLabel lbl;
JTextField txt;
_root = new JPanel(new FlowLayout());
// build the session minutes
lbl = new JLabel();
lbl.setText("Session Minutes:");
_root.add(lbl);
txt = new JTextField();
_root.add(txt);
swingContainer.add(_root);
}
}
我想将大小设置为 600x400 - 但我已经发布setSize(600, 400)
了applet
, frame
, swingContainer
,_root
并且没有任何变化。我得到一个看起来像这样的屏幕: