m0_64687309 2021-12-20 00:20 采纳率: 100%
浏览 122
已结题

JFrame中JLabel不显示文字

代码如下

img

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();
    }
}


  • 写回答

1条回答 默认 最新

  • CSDN专家-sinJack 2021-12-20 00:25
    关注

    估计被你图片给覆盖了。你把图片去掉试试。

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

问题事件

  • 系统已结题 12月28日
  • 已采纳回答 12月20日
  • 创建了问题 12月20日

悬赏问题

  • ¥15 永磁直线电机的电流环pi调不出来
  • ¥15 用stata实现聚类的代码
  • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
  • ¥170 如图所示配置eNSP
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效
  • ¥15 悬赏!微信开发者工具报错,求帮改
  • ¥20 wireshark抓不到vlan
  • ¥20 关于#stm32#的问题:需要指导自动酸碱滴定仪的原理图程序代码及仿真
  • ¥20 设计一款异域新娘的视频相亲软件需要哪些技术支持