package com.welcome; import java.awt.BorderLayout; import java.awt.Container; import java.awt.FlowLayout; import java.awt.Font; import java.awt.GridLayout; import java.awt.Image; import java.awt.Toolkit; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.event.WindowAdapter; import java.awt.event.WindowEvent; import java.net.URL; import javax.swing.ImageIcon; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JOptionPane; import javax.swing.JPanel; import javax.swing.JTextField; import com.cranerpt.CraneRPT; import com.monitor.Monitor; import com.report.Report; import com.storage.Storage; import com.transport.Transport; public class Welcome implements ActionListener{ static int WIDTH=500; static int HEIGHT=500; static int XLoc=450; static int YLoc=200; JFrame jframe=new JFrame(); JPanel jpanel=new JPanel(); JPanel northJPanel=new JPanel(); JPanel southJPanel=new JPanel(); JLabel label=new JLabel(); JButton reportButton=new JButton(); JButton CraneRPTButton=new JButton(); JButton StorageButton=new JButton(); JButton TransportButton=new JButton(); JButton MonitorButton=new JButton(); ImageIcon background = new ImageIcon("src/Image/12.JPG"); JLabel backgroundLabel = new JLabel(background);//将背景图放在标签里。 Container container=jframe.getContentPane(); public Welcome() { jframe.setContentPane(jpanel); jframe.setSize(WIDTH, HEIGHT); jframe.setResizable(false); jframe.getLayeredPane().add(backgroundLabel, new Integer(Integer.MIN_VALUE)); backgroundLabel.setBounds(0,0,jframe.getWidth(),jframe.getHeight()); jframe.getLayeredPane().setLayout(null); jpanel.setOpaque(false); init(); paint(); reportButton.addActionListener(this); CraneRPTButton.addActionListener(this); StorageButton.addActionListener(this); TransportButton.addActionListener(this); MonitorButton.addActionListener(this); } public void init() { URL url=this.getClass().getResource("/Image/BOE_2.png"); Image image=Toolkit.getDefaultToolkit().getImage(url); jframe.setIconImage(image); jframe.setTitle("Welcome"); jframe.setSize(WIDTH,HEIGHT); jframe.setLocation(XLoc,YLoc); jframe.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); jframe.addWindowListener( new WindowAdapter(){ public void windowClosing(WindowEvent e){ System.exit(0); } } ); } public void paint() { reportButton.setText("Report"); CraneRPTButton.setText("CraneRPT"); StorageButton.setText("Storage"); TransportButton.setText("Transport"); MonitorButton.setText("Monitor"); label.setText("欢迎界面"); label.setFont(new Font("宋体",Font.BOLD|Font.PLAIN,25)); reportButton.setFocusable(false); CraneRPTButton.setFocusable(false); StorageButton.setFocusable(false); TransportButton.setFocusable(false); MonitorButton.setFocusable(false); label.setBounds(170,100,300,40); reportButton.setBounds(80,200,100,35); CraneRPTButton.setBounds(210,200,100,35); StorageButton.setBounds(340,200,100,35); TransportButton.setBounds(80,300,100,35); MonitorButton.setBounds(210,300,100,35); backgroundLabel.add(label); backgroundLabel.add(reportButton); backgroundLabel.add(CraneRPTButton); backgroundLabel.add(StorageButton); backgroundLabel.add(TransportButton); backgroundLabel.add(MonitorButton); container.add(jpanel); jframe.setVisible(true); } @Override public void actionPerformed(ActionEvent e) { // TODO Auto-generated method stub if(e.getSource()==reportButton) { Report report=new Report(); } if(e.getSource()==CraneRPTButton) { CraneRPT craneRpt=new CraneRPT(); } if(e.getSource()==StorageButton) { Storage storage=new Storage(); } if(e.getSource()==TransportButton) { Transport transport =new Transport (); } if(e.getSource()==MonitorButton) { Monitor monitor=new Monitor(); } } public static void main(String []args) { Welcome welcome=new Welcome(); } }
图片路径设置要正确才行!
时间: 2024-11-09 03:51:30