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\image51854.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"); } }
这是因为窗体添加组件也区分优先级,只需要把按键组件在有参构造方法中优先添加,背景图片组件最后添加便可以解决这个问题。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)