当创建两个 JLabel 一个在执行时消失?

问题描述

import java.awt.*;
import javax.swing.*;
 
public class MyCalc{
    public static void main(String[] args) {
        
        JFrame frame=new JFrame();
        frame.setTitle("Alerting Machine");
        frame.setSize(1000,1000);
        frame.getContentPane().setBackground(new java.awt.Color(204,166,166));
        frame.setResizable(false);
        
        ImageIcon image=new ImageIcon("gas.png");
        frame.setIconImage(image.getimage());
        
        JLabel label=new JLabel("ALERTING MACHINE");
        label.setHorizontalAlignment(SwingConstants.CENTER);
        label.setVerticalAlignment(SwingConstants.TOP);
        label.setFont(new Font("Arial Black",Font.BOLD,20));
        
        JLabel temp=new JLabel("AMBIENT TEMPRATURE");
        temp.setFont(new Font("Times New Roman",Font.ITALIC,20));
        temp.setHorizontalAlignment(SwingConstants.LEFT);
        
        frame.setVisible(true);
        frame.add(label);
        frame.add(temp);
    }
}

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)