import javax.swing.*;
import javax.swing.border.Border;
import javax.swing.border.LineBorder;
import java.awt.*;
import static java.awt.FlowLayout.CENTER;
public class Main extends JFrame {
public Main() {
//设置标题
super("志文的小demo");
//设置大小
setSize(1000, 800);
//设置位置
setLocation(200, 50);
//背景图片的路径。(相对路径或者绝对路径。本例图片放于"java项目名"的文件下)
String path = "D://E//2.jpeg";
// 背景图片
ImageIcon background = new ImageIcon(path);
// 把背景图片显示在一个标签里面
JLabel label1=new JLabel("欢迎进入港口渔船停泊管理系统");
JButton bt1=new JButton("用户认证登录");
JButton bt2=new JButton("新用户注册");
JButton bt3=new JButton("管理员登录");
JButton bt5=new JButton("实时可停靠位置查询");
JButton bt4=new JButton("零时停靠");
JButton bt6=new JButton("海港救助");
JLabel label = new JLabel(background);
JPanel jp=new JPanel();
// 把标签的大小位置设置为图片刚好填充整个面板
label.setBounds(0, 0, this.getWidth(), this.getHeight());
// 把内容窗格转化为JPanel,否则不能用方法setOpaque()来使内容窗格透明
JPanel imagePanel = (JPanel) this.getContentPane();
label1.setBounds(150,25,800,150);
label1.setFont(new Font(label1.getFont().getName(),label1.getFont().getStyle(),50));
// label1.setBorder(new LineBorder(Color.WHITE));
bt4.setBounds(425,600,150,30);
bt1.setBounds(425,560,150,30);
bt2.setBounds(425,520,150,30);
bt3.setBounds(425,480,150,30);
bt5.setBounds(425,440,150,30);
bt6.setBounds(425,400,150,30);
bt1.setOpaque(false);
jp.add(bt4);
jp.add(bt1);
jp.add(bt2);
jp.add(bt3);
jp.add(bt5);
jp.add(bt6);
add(bt1);
add(bt2);
add(bt4);
add(bt3);
add(bt6);
add(bt5);
add(label1);
label.setText("hduihe");
add(jp);
jp.setOpaque(false);
imagePanel.setOpaque(false);
// 把背景图片添加到分层窗格的最底层作为背景
this.getLayeredPane().add(label, new Integer(Integer.MIN_VALUE));
//设置可见
setVisible(true);
//点关闭按钮时退出
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
public static void main(String[] args) {
new Main();
}
}