代码如下
import controller.UserController;
import model.ChessPiece;
import javax.swing.*;
import java.awt.*;
public class UserFrame extends JFrame {
public static UserController userController;
MediaTracker tracker;
Image UserImage;
private JButton logInBtn;
private JButton registerBtn;
private JLabel introduceLabel;
public UserFrame(int frameSize){
this.setTitle("User's Panel");
this.setLayout(null);
setResizable(false);
this.setSize(frameSize , frameSize);//设置窗口边界
this.setLocationRelativeTo(null);
this.tracker = new MediaTracker(this);
UserImage = Toolkit.getDefaultToolkit().getImage("E:\\Java Learning\\project image\\进入.png\\");
tracker.addImage(UserImage,1);
try{
tracker.waitForAll();;
}catch (InterruptedException e){
System.out.println("加载图象文件失败");
}
this.introduceLabel = new JLabel();
introduceLabel.setText("Let us play CHESS!");
introduceLabel.setFont(new Font("Calibri", Font.ITALIC, 50));
introduceLabel.setSize((int)(this.getWidth()*0.6),(int)(this.getHeight()*0.2));
introduceLabel.setLocation((int)(this.getWidth()*0.2),(int)(this.getHeight()*0.5));
introduceLabel.setVisible(true);
this.add(introduceLabel);
this.registerBtn = new JButton("注册");
registerBtn.setSize((int)(this.getWidth()*0.25), (int)(this.getHeight()*0.1));
registerBtn.setLocation((int) (this.getWidth()*0.2), (int)(this.getHeight()*0.7));
add(registerBtn);
registerBtn.addActionListener(e -> {
System.out.println("click register Btn");
});
this.logInBtn = new JButton("登录");
logInBtn.setSize((int)(this.getWidth()*0.25), (int)(this.getHeight()*0.1));
logInBtn.setLocation((int) (this.getWidth()*0.55), (int)(this.getHeight()*0.7));
add(logInBtn);
logInBtn.addActionListener(e -> {
System.out.println("click log in Btn");
});
this.setVisible(true);
this.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
}
public void paint(Graphics g){
g.drawImage(UserImage,(int) (this.getWidth()*0.37),(int)(this.getHeight()*0.2),(int)(this.getWidth()*0.25),(int)(this.getHeight()*0.25),this);
logInBtn.requestFocus();
registerBtn.requestFocus();
introduceLabel.requestFocus();
}
}