GUI 创建个Frame,往里面插入Panel,Panel的大小随Frame大小调整 setLayout setBounds

创建个Frame,往里面插入Panel,Panel的大小随Frame大小调整







public class checkGpa extends JFrame implements ActionListener { static JButton backButton = new JButton("back"); JFrame frame = new JFrame("GPA"); Label averageGPALabel = new Label("average GPA"); JTextField averageGPAField = new JTextField(); Label weightedGPALabel = new Label("weighted GPA"); JTextField weightedGPAField = new JTextField(); /** * Constructor creates a JFrame and sets its properties. * Calls the PersonalReader method to read and display student GPA information. * Adds a JPanel to the JFrame and creates and positions various GUI elements. * Sets an ActionListener for the back button to return to the previous window. * * @throws IOException if an error occurs while reading from the JSON file */ public checkGpa() throws IOException { frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); frame.setSize(400, 300); // Create and set properties for JPanel JPanel panel = new JPanel(); panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS)); panel.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10)); // Create and position GUI elements averageGPALabel.setBounds(10, 10, 20, 10); averageGPALabel.setBounds(20, 10, 100, 10); averageGPAField.setBounds(120, 10, 100, 10); weightedGPALabel.setBounds(10, 40, 100, 10); weightedGPAField.setBounds(120, 40, 100, 10); backButton.setAlignmentX(Component.CENTER_ALIGNMENT); // Display GPA information by calling PersonalReader method GPA gpa = PersonalReader(); averageGPAField.setText(gpa.getAverageGPA()); weightedGPAField.setText(gpa.getWeightedGPA()); panel.add(averageGPALabel); panel.add(averageGPAField); panel.add(weightedGPALabel); panel.add(weightedGPAField); panel.add(backButton); backButton.addActionListener(this); frame.add(panel); frame.setVisible(true); } 使用tdd修改这段代码
最新发布
05-25
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值