// 设置背景图片 ImageIcon background = new ImageIcon("D:\\yy\\java\\成语接龙\\background.png"); backgroundLabel = new JLabel(background); backgroundLabel.setBounds(0, 0, background.getIconWidth(), background.getIconHeight()); panel.add(backgroundLabel); SimpleButton = new JButton("娱乐模式"); SimpleButton.setBounds(100, 100, 200, 50); SimpleButton.addActionListener(this); backgroundLabel.add(SimpleButton); HardButton = new JButton("挑战模式"); HardButton.setBounds(100, 200, 200, 50); HardButton.addActionListener(this); backgroundLabel.add(HardButton); add(panel); setSize(background.getIconWidth(), background.getIconHeight()); setLocationRelativeTo(null); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setResizable(false); setVisible(true);修改这串代码,要求把界面缩小
时间: 2024-03-21 07:41:58 浏览: 56
您可以在最后添加如下代码来缩小界面:
```
setSize(background.getIconWidth()/2, background.getIconHeight()/2);
```
这样就可以把界面缩小一半了。完整代码如下:
```
// 设置背景图片
ImageIcon background = new ImageIcon("D:\\yy\\java\\成语接龙\\background.png");
backgroundLabel = new JLabel(background);
backgroundLabel.setBounds(0, 0, background.getIconWidth(), background.getIconHeight());
panel.add(backgroundLabel);
SimpleButton = new JButton("娱乐模式");
SimpleButton.setBounds(100, 100, 200, 50);
SimpleButton.addActionListener(this);
backgroundLabel.add(SimpleButton);
HardButton = new JButton("挑战模式");
HardButton.setBounds(100, 200, 200, 50);
HardButton.addActionListener(this);
backgroundLabel.add(HardButton);
add(panel);
setSize(background.getIconWidth()/2, background.getIconHeight()/2);
setLocationRelativeTo(null);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setResizable(false);
setVisible(true);
```
阅读全文
相关推荐















