我正在练习使用 GUI。我一直在遵循一组说明,但是当我尝试运行程序时,只会出现一个空框架。框架内看不到任何信息。
这是我的代码:
package practice528;
import java.util.Scanner;
import java.io.*;
import javax.swing.*;
import java.awt.*;
public class Practice528
{
public static void main(String[] args)
{
JFrame frame = new JFrame("Rectangle Calculator");
frame.setVisible(true);
frame.setSize(400,300);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JLabel lengthL, widthL, areaL, perimeterL;
lengthL = new JLabel("Enter the length: ", SwingConstants.RIGHT);
widthL = new JLabel("Enter the width: ", SwingConstants.RIGHT);
areaL = new JLabel("The area is ", SwingConstants.RIGHT);
perimeterL = new JLabel("The perimeter is ", SwingConstants.RIGHT);
frame.setLayout(new GridLayout(5,2));
System.out.println();
} //end main
} //end class