我昨天开始 java 编程,并开发了这个。我遇到了一个问题,因为按钮不会调整大小。如果可以,请提供帮助,并在此先感谢您。
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.*;
class BgPanel extends JPanel {
Image bg = new ImageIcon("C:\\Users\\********\\Pictures\\tiger.jpg").getImage();
@Override
public void paintComponent(Graphics g) {
g.drawImage(bg, 0, 0, getWidth(), getHeight(), this);
}
}
public class FrameTestBase extends JFrame {
public static void main(String args[]) {
JPanel bgPanel = new BgPanel();
bgPanel.setLayout(new BorderLayout());
final FrameTestBase t = new FrameTestBase();
ImageIcon img = new ImageIcon("C:\\Users\\********\\Pictures\\gear-icon.png");
t.setLayout(null);
t.setIconImage(img.getImage());
t.setTitle("Login");
t.setSize(600,600);
t.setLocationRelativeTo(null);
t.setContentPane(bgPanel);
t.setDefaultCloseOperation(EXIT_ON_CLOSE);
t.setVisible(true);
JButton registerButton = new JButton("register");
registerButton.setBounds(80, 80, 80, 80);
t.add(registerButton);
}
}