栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Java

java+swing中,运行窗体时,按键不会立刻跟随背景图片出现,只有鼠标滑过按键位置时,按键才会出现

Java 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

java+swing中,运行窗体时,按键不会立刻跟随背景图片出现,只有鼠标滑过按键位置时,按键才会出现

package hospital;
import java.awt.Color;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.enterprise.inject.New;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.Jframe;
import javax.swing.JLabel;
import javax.swing.JPanel;


public class HomePage extends Jframe{
	
    private JLabel la1, la2;
    
    private Font laFont = new Font("隶书", Font.BOLD, 60);
    private Font btFont=new Font("宋体",Font.BOLD,25);
    
    
    ImageIcon background = new ImageIcon("WebRoot\image\2051854.jpg");
    JLabel bgJLabel = new JLabel(background);
    
    JButton doctorJButton=new JButton("医生信息管理");
    JButton patientJButton=new JButton("病人信息管理");
    JButton wardJButton=new JButton("科室信息管理");
    
    
    
 
    public HomePage() {}
    
    
    public HomePage(String a){
      	super(a);
    	this.setLayout(null);
    	
    	this.add(doctorJButton);
        this.add(patientJButton);
        this.add(wardJButton);
        doctorJButton.setFont(btFont);
        patientJButton.setFont(btFont);
        wardJButton.setFont(btFont);

        doctorJButton.setBounds(0, 0, 200, 200);
        patientJButton.setBounds(0, 200, 200, 200);
        wardJButton.setBounds(0, 400, 200, 200);
    
    
        la1 = new JLabel("欢迎使用");
        la2 = new JLabel("医院信息管理系统");
 
        
        this.add(la1);
        this.add(la2);
        la1.setBounds(500, 100, 500, 100);
        la1.setFont(laFont);
        la2.setBounds(400,200, 600, 100);
        la2.setFont(laFont);
       
 
        this.add(bgJLabel);
        bgJLabel.setBounds(0, 0, 1000, 600);
        
        wardJButton.addActionListener(new ActionListener() {
			
			@Override
			public void actionPerformed(ActionEvent e) {
				// TODO Auto-generated method stub
				
				new department("科室管理界面");
				HomePage.this.setVisible(false);
				
			}
		});
       
    
    	this.setTitle("主页面");
    	this.setResizable(true);
    	this.setVisible(true);
    	this.setSize(1000, 600);
    	this.setLocationRelativeTo(null);
    	this.setDefaultCloseOperation(Jframe.EXIT_ON_CLOSE);
    	
    	
    }
    public static void main(String[] args) {
		HomePage homePage=new HomePage("主页面1");
		
		
	}

}

这是因为窗体添加组件也区分优先级,只需要把按键组件在有参构造方法中优先添加,背景图片组件最后添加便可以解决这个问题。

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/583897.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号