慕桂英546537
通过将所需的零件添加到中来使用“复合零件” JPanel。例如import java.awt.FlowLayout;import javax.swing.*;class TimeBeforeClass { public static void main(String[] args) { SwingUtilities.invokeLater(new Runnable() { public void run() { JPanel gui = new JPanel(new FlowLayout(FlowLayout.LEFT, 3,3)); gui.add(new JLabel("Open")); gui.add(new JSpinner(new SpinnerNumberModel(15,0,20,1))); gui.add(new JLabel("minutes before class")); JOptionPane.showMessageDialog(null, gui); } }); }}请注意,我将“文本字段”交换为JSpinner-一个更合适的组件,用于选择“以分钟为单位的时间”。