panel = new JPanel(); panel.setLayout(null); // 设置背景图片 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);修改这串代码,要求保留信息的基础上界面美化
时间: 2024-04-03 14:34:16 浏览: 79
panel = new JPanel();
panel.setLayout(null);
// 设置背景图片
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(120, 180, 200, 50);
SimpleButton.setFont(new Font("微软雅黑", Font.BOLD, 20));
SimpleButton.setForeground(Color.WHITE);
SimpleButton.setBackground(new Color(78, 163, 250));
SimpleButton.setBorder(BorderFactory.createLineBorder(new Color(78, 163, 250), 2));
SimpleButton.addActionListener(this);
backgroundLabel.add(SimpleButton);
// 创建挑战模式按钮
HardButton = new JButton("挑战模式");
HardButton.setBounds(120, 260, 200, 50);
HardButton.setFont(new Font("微软雅黑", Font.BOLD, 20));
HardButton.setForeground(Color.WHITE);
HardButton.setBackground(new Color(78, 163, 250));
HardButton.setBorder(BorderFactory.createLineBorder(new Color(78, 163, 250), 2));
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);
// 界面美化的修改包括设置按钮的字体、前景色和背景色,以及设置边框颜色。同时,对按钮的位置进行微调,使其更加美观。
阅读全文