import java.sql.*; import static java.sql.DriverManager.*; import javax.swing.*; import java.awt.*; import java.awt.event.*; import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Random; class Connect{//建立数据库的连接 Connection conn = null; public Connect() { try { Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver"); } catch (ClassNotFoundException ex) { throw new RuntimeException(ex); } System.out.println("加载驱动成功!"); String dbURL = "jdbc:sqlserver://localhost;DatabaseName=User1001;encrypt=true;trustServerCertificate=true"; String user = "sa"; String password = "123456";//在引号中修改为自己设置的登陆密码 try { conn = getConnection(dbURL, user, password); } catch (SQLException ex) { throw new RuntimeException(ex); } System.out.println("连接数据库成功!"); try (Statement statement = conn.createStatement()) { } catch (SQLException e) { throw new RuntimeException(e); } } } class Conction extends Connect { ArrayList<String> list1 = new ArrayList<>(); ArrayList<String> list2 = new ArrayList<>(); ArrayList<String> list4 = new ArrayList<>(); String string1 = ""; String string2 = ""; public void Connect(String t1, String t2, String t3, String t4, String t5) {//注册模块 String sql = "INSERT INTO usertable2(username,potsize,potid,pwater,password) VALUES (?,?,?,?,?)"; try { PreparedStatement stat = conn.prepareStatement(sql);//进行预编译 stat.setString(1, t1); stat.setString(2, t2); stat.setString(3, t3); stat.setString(4, t4); stat.setString(5, t5); stat.executeUpdate(); } catch (SQLException ex) { throw new RuntimeException(ex); } String sql2 = "select * from usertable2"; PreparedStatement stmt = null; PreparedStatement stmt2 = null; try { stmt = conn.prepareStatement(sql); stmt2 = conn.prepareStatement(sql2); } catch (SQLException ex) { throw new RuntimeException(ex); } try (ResultSet res = stmt2.executeQuery()) { while (res.next()) { String title = res.getString("username"); list1.add(title); } for (int i = 0; i < list1.size(); i++) { if (list1.get(i).contains(t1)) { string1 = list1.get(i); } } new show1(string1, "注册成功"); } catch (SQLException ex) { throw new RuntimeException(ex); } try { stmt.close(); } catch (SQLException ex) { throw new RuntimeException(ex); } try { conn.close(); } catch (SQLException ex) { throw new RuntimeException(ex); } } public void Connect(String s1, String s2) {//登录模块 try (Statement stmt = conn.createStatement()) { ResultSet rs = stmt.executeQuery("select * from usertable2 where username='" + s1 + "'" + "and password=" + s2); if (!rs.isBeforeFirst())//获取行号 { new show1("请输入正确的用户名或者密码"); } else { while (rs.next()) { String tet = rs.getString("username"); list2.add(tet); System.out.println(tet); } for (int i = 0; i < list2.size(); i++) { if (list2.get(i).contains(s1)) ; { string2 = list2.get(i); } } new GUIshowseen1(string2); } } catch (SQLException ex) { throw new RuntimeException(ex); } } public void Connect() {//模块5可用位置查询 String h=""; String m=""; try (Statement stmt5 = conn.createStatement()) { int num=0; ResultSet rs = stmt5.executeQuery("select count(uName) from usertable3 "); while(rs.next()) { String p= rs.getString(1); num=Integer.parseInt(p,10); } h = "A区已用位置" + num + "剩余位置" + (100 - num); } catch (SQLException ex) { throw new RuntimeException(ex); } try (Statement stmt6 = conn.createStatement()) { int num=0; ResultSet rs = stmt6.executeQuery("select count(uName) from usertable6 "); while(rs.next()) { String p= rs.getString(1); num=Integer.parseInt(p,10); } m = "B区已用位置" + num + "剩余位置" + (100 - num); new show1(h,m,4); } catch (SQLException ex) { throw new RuntimeException(ex); } } public void Connect(int m, String f) throws RuntimeException {//找回密码模块 String p=""; try (Statement stmt = conn.createStatement()) { ResultSet rs = stmt.executeQuery("select password from usertable2 where username='" + f + "'"); while (rs.next()) { String tet = rs.getString(1); System.out.println(tet); p = tet; } new show1("密码是" + p); } catch (SQLException e) { throw new RuntimeException(e); } } public void Connect(int f,String m1,String m2,String m3) {//新的注册模块 String v=""; if(f<5) { v="usertable3"; } else { v="usertable6"; } String sql = "INSERT INTO "+v+"(uName,uPwt,uTime) VALUES (?,?,?)"; try { PreparedStatement stat = conn.prepareStatement(sql);//进行预编译 stat.setString(1, m1); stat.setString(2, m2); stat.setString(3, m3); stat.executeUpdate(); } catch (SQLException ex) { throw new RuntimeException(ex); } String sql2 = "select * from "+v; PreparedStatement stmt = null; PreparedStatement stmt2 = null; try { stmt = conn.prepareStatement(sql); stmt2 = conn.prepareStatement(sql2); } catch (SQLException ex) { throw new RuntimeException(ex); } try (ResultSet res = stmt2.executeQuery()) { while (res.next()) { String title = res.getString("uName"); list1.add(title); } for (int i = 0; i < list1.size(); i++) { if (list1.get(i).contains(m1)) { string1 = list1.get(i); } } } catch (SQLException ex) { throw new RuntimeException(ex); } try { stmt.close(); } catch (SQLException ex) { throw new RuntimeException(ex); } try { conn.close(); } catch (SQLException ex) { throw new RuntimeException(ex); } } public void Connect(String k1, String k2, int m,String l) {// 新的离开港口模块2 try (Statement stmt3 = conn.createStatement()) { String v=""; if(m<5) { v="usertable3"; } else { v="usertable6"; } String sql2 = "select DATEDIFF(day,uTime,'2023-06-19') as age from "+v; PreparedStatement stmt2 = null; try { stmt2 = conn.prepareStatement(sql2); } catch (SQLException ex) { throw new RuntimeException(ex); } try (ResultSet res = stmt2.executeQuery()) { while (res.next()) { String title = res.getString("age"); list4.add(title); } System.out.println(list4.get(list4.size() - 1)); new show1("共计停靠时间" + list4.get(list4.size() - 1) + "天", "离港成功"); } String sql4 = "delete from "+v+" where uName=?"; try { PreparedStatement stat = conn.prepareStatement(sql4);//进行预编译 stat.setString(1, k1); stat.executeUpdate(); } catch (SQLException ex) { throw new RuntimeException(ex); } try{ stmt2.close(); } catch (SQLException ex) { throw new RuntimeException(ex); } try{ conn.close(); } catch (SQLException ex) { throw new RuntimeException(ex); } } catch (SQLException ex) { throw new RuntimeException(ex); } } } class show1 extends JFrame{//提示模块 public show1(String s,String to){ super("注册"); JLabel tatil=new JLabel(to); JLabel name=new JLabel("用户名: "+s); tatil.setBounds(30,40,500,100); name.setBounds(30,80,500,100); tatil.setFont(new Font(name.getFont().getName(),name.getFont().getStyle(),20)); name.setFont(new Font(name.getFont().getName(),name.getFont().getStyle(),20)); JPanel jp=new JPanel(); String path="D://E//B2.jpg"; ImageIcon background=new ImageIcon(path); JLabel pack=new JLabel(background); pack.setBounds(0,0,this.getWidth(),this.getHeight()); JPanel imagePan=(JPanel) this.getContentPane(); imagePan.setOpaque(false); this.getLayeredPane().add(pack,new Integer(Integer.MIN_VALUE)); jp.add(pack); this.setSize(500,300); this.setLocation(800,400); this.add(name); this.add(tatil);this.add(jp); jp.setOpaque(false); this.setVisible(true); } public show1(String d1,String d2,int p){ super("区域查询"); JLabel tatil=new JLabel(d1); JLabel name=new JLabel(d2); tatil.setBounds(30,40,500,100); name.setBounds(30,80,500,100); tatil.setFont(new Font(name.getFont().getName(),name.getFont().getStyle(),20)); name.setFont(new Font(name.getFont().getName(),name.getFont().getStyle(),20)); JPanel jp=new JPanel(); String path="D://E//B2.jpg"; ImageIcon background=new ImageIcon(path); JLabel pack=new JLabel(background); pack.setBounds(0,0,this.getWidth(),this.getHeight()); JPanel imagePan=(JPanel) this.getContentPane(); imagePan.setOpaque(false); this.getLayeredPane().add(pack,new Integer(Integer.MIN_VALUE)); jp.add(pack); this.setSize(500,300); this.setLocation(800,400); this.add(name); this.add(tatil);this.add(jp); jp.setOpaque(false); this.setVisible(true); } public show1(String g) { super("WARN"); JLabel name=new JLabel(g); name.setBounds(30,80,500,100); name.setFont(new Font(name.getFont().getName(),name.getFont().getStyle(),30)); JPanel jp=new JPanel(); String path="D://E//B2.jpg"; ImageIcon background=new ImageIcon(path); JLabel pack=new JLabel(background); pack.setBounds(0,0,this.getWidth(),this.getHeight()); JPanel imagePan=(JPanel) this.getContentPane(); imagePan.setOpaque(false); this.getLayeredPane().add(pack,new Integer(Integer.MIN_VALUE)); jp.add(pack); this.setResizable(false); jp.add(name); this.setSize(500,500); this.setLocation(500,300); this.add(name); this.add(jp); jp.setOpaque(false); this.setVisible(true); } public show1(String s1,String s2,String s3,String s4){ super("申请成功"); JLabel t1=new JLabel("用户名: "+s1); JLabel t2=new JLabel("吨位 "+s2); JLabel t3=new JLabel("起始时间 "+s3); JLabel t4=new JLabel("停泊区域 "+s4); t1.setBounds(30,40,500,100); t2.setBounds(30,70,500,100); t3.setBounds(30,100,500,100); t4.setBounds(30,130,500,100); t1.setFont(new Font(t1.getFont().getName(),t1.getFont().getStyle(),20)); t2.setFont(new Font(t2.getFont().getName(),t2.getFont().getStyle(),20)); t3.setFont(new Font(t2.getFont().getName(),t2.getFont().getStyle(),20)); t4.setFont(new Font(t2.getFont().getName(),t2.getFont().getStyle(),20)); JPanel jp=new JPanel(); String path="D://E//A2.jpg"; ImageIcon background=new ImageIcon(path); JLabel pack=new JLabel(background); pack.setBounds(0,0,this.getWidth(),this.getHeight()); JPanel imagePan=(JPanel) this.getContentPane(); imagePan.setOpaque(false); this.getLayeredPane().add(pack,new Integer(Integer.MIN_VALUE)); jp.add(pack); this.setLocation(800,400);this.setSize(500,300); this.add(t2);this.add(t3);this.add(t4); this.add(t1);this.add(jp); jp.setOpaque(false); this.setVisible(true); } } class seek extends JFrame{ public seek() { super("密码找回");//忘记密码的模块添加 Random random=new Random(); int h=random.nextInt(100000,900000);//设置验证码模块 String t=String.valueOf(h); JButton dete=new JButton("确定"); JButton can=new JButton("取消"); JLabel name=new JLabel("用户名:"); JLabel password=new JLabel("请输入以上字符:"); JLabel pass=new JLabel("验证"); JTextField data1=new JTextField(); JTextField data2=new JTextField(t); JTextField data3=new JTextField(); data1.setBounds(250,120,150,30); data2.setBounds(250,170,150,30); data3.setBounds(250,220,150,30); name.setBounds(50,120,100,30); password.setBounds(50,220,200,30); pass.setBounds(50,170,200,30); dete.setBounds(20,400,100,30); can.setBounds(350,400,100,30); name.setFont(new Font(name.getFont().getName(),name.getFont().getStyle(),20)); password.setFont(new Font(name.getFont().getName(),name.getFont().getStyle(),20)); pass.setFont(new Font(name.getFont().getName(),name.getFont().getStyle(),20)); JPanel jp=new JPanel(); String path="D://E//12.jpg"; ImageIcon background=new ImageIcon(path); JLabel pack=new JLabel(background); pack.setBounds(0,0,this.getWidth(),this.getHeight()); JPanel imagePan=(JPanel) this.getContentPane(); imagePan.setOpaque(false); this.getLayeredPane().add(pack,new Integer(Integer.MIN_VALUE)); jp.add(pack); this.setResizable(false); this.setSize(500,500); this.setLocation(400,200); this.setResizable(false); this.add(name); this.add(password); this.add(dete); this.add(can);this.add(data1);this.add(pass); this.add(data2);this.add(data3);this.add(jp); data1.setOpaque(false);data2.setOpaque(false);data3.setOpaque(false); jp.setOpaque(false); this.setVisible(true); dete.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { String d=data1.getText(); String h=data3.getText(); if(!h.contains(data2.getText())) { new show1("请输入正确的验证码"); } else{ Conction fg = new Conction(); fg.Connect(1,d); } } }); can.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { setVisible(false); } }); } } class GUIshowseen1 extends JFrame{ public GUIshowseen1(String user) { super("登录成功"); JButton dete=new JButton("入港申请"); JButton can=new JButton("离港申请"); JLabel tite=new JLabel("欢迎您的登录"); JPanel jp=new JPanel(); String path="D://E//A1.jpg"; ImageIcon background=new ImageIcon(path); JLabel pack=new JLabel(background); pack.setBounds(0,0,this.getWidth(),this.getHeight()); JPanel imagePan=(JPanel) this.getContentPane(); imagePan.setOpaque(false); this.getLayeredPane().add(pack,new Integer(Integer.MIN_VALUE)); jp.add(pack); this.setResizable(false); this.setSize(450,450); this.setLocation(400,300); this.add(jp); jp.setOpaque(false); this.setVisible(true); dete.setBounds(200,150,100,40); can.setBounds(200,250,100,40); tite.setBounds(180,50,300,40); tite.setFont(new Font(tite.getFont().getName(),tite.getFont().getStyle(),20)); this.setResizable(false); this.setSize(500,500);this.setLocation(100,100); this.add(dete); this.add(can); this.add(tite);this.add(jp); jp.setOpaque(false); this.setVisible(true); dete.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { new applyGUI(user); } }); can.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { new levalGUI(user); } }); } } class applyGUI extends JFrame{ public applyGUI(String p){ super("停靠管理"); JButton dete=new JButton("确定"); JButton can=new JButton("取消"); JLabel name=new JLabel("请输入渔船的吨位"); JLabel password=new JLabel("输入停靠港口时间:"); JTextField data1=new JTextField(); JTextField data2=new JTextField(); data1.setBounds(260,115,150,30); data2.setBounds(260,165,150,30); password.setBounds(50,130,200,100); name.setBounds(50,80,200,100); dete.setBounds(50,400,100,30); can.setBounds(350,400,100,30); password.setFont(new Font(password.getFont().getName(),password.getFont().getStyle(),20)); name.setFont(new Font(password.getFont().getName(),password.getFont().getStyle(),20)); JPanel jp=new JPanel(); String path="D://E//A3.jpg"; ImageIcon background=new ImageIcon(path); JLabel pack=new JLabel(background); pack.setBounds(0,0,this.getWidth(),this.getHeight()); JPanel imagePan=(JPanel) this.getContentPane(); imagePan.setOpaque(false); this.getLayeredPane().add(pack,new Integer(Integer.MIN_VALUE)); jp.add(pack); this.setResizable(false); this.setSize(500,500); this.setLocation(100,100); this.add(password);this.add(dete);this.add(can); this.add(data1);this.add(name); this.add(data2);this.add(jp); this.add(jp); jp.setOpaque(false); data1.setOpaque(false);data2.setOpaque(false);//设置为透明 this.setVisible(true); this.setResizable(false); dete.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { String pswater=data1.getText(); String stim=data2.getText(); String area=""; int number=Integer.parseInt(pswater,10); if(number<5) { area="A"; Conction fg = new Conction(); fg.Connect(2,p,pswater,stim); new show1(p,pswater,stim,area); } else{ area="B"; Conction fg = new Conction(); fg.Connect(7,p,pswater,stim); new show1(p,pswater,stim,area); } } }); can.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { setVisible(false); } }); } } class levalGUI extends JFrame{ public levalGUI(String p){ super("离开港口管理"); JButton dete=new JButton("确定"); JButton can=new JButton("取消"); JLabel size=new JLabel("请输入停泊区域"); JLabel name=new JLabel("请输入离开港口时间"); JTextField data1=new JTextField(); JTextField data2=new JTextField(); data1.setBounds(260,115,150,30); data2.setBounds(260,165,150,30); name.setBounds(50,130,200,100); size.setBounds(50,80,200,100); dete.setBounds(50,400,100,30); can.setBounds(350,400,100,30); name.setFont(new Font(name.getFont().getName(),name.getFont().getStyle(),20)); size.setFont(new Font(name.getFont().getName(),name.getFont().getStyle(),20)); JPanel jp=new JPanel(); String path="D://E//A3.jpg"; ImageIcon background=new ImageIcon(path); JLabel pack=new JLabel(background); pack.setBounds(0,0,this.getWidth(),this.getHeight()); JPanel imagePan=(JPanel) this.getContentPane(); imagePan.setOpaque(false); this.getLayeredPane().add(pack,new Integer(Integer.MIN_VALUE)); jp.add(pack); this.setResizable(false); this.setSize(500,500); this.setLocation(100,100); this.add(name); this.add(dete);this.add(can); this.add(data1);this.add(size);this.add(data2); this.add(jp); jp.setOpaque(false); data1.setOpaque(false);//设置为透明 data2.setOpaque(false); this.setVisible(true); this.setResizable(false); dete.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { String op=data1.getText(); String ans="A"; String sd=""; String num=data2.getText(); if(ans.contains(op)) { Conction fg = new Conction(); fg.Connect(p,num,2,sd); } else{ Conction fg = new Conction(); fg.Connect(p,num,7,sd); } } }); can.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { setVisible(false); } }); } } class GUIshow1 extends JFrame{ public GUIshow1() { super("新用户注册"); JFrame jf=new JFrame(); JButton dete=new JButton("确定"); JButton can=new JButton("取消"); JLabel name=new JLabel("用户名:"); JLabel Sex=new JLabel("船型号:"); JLabel ID=new JLabel("船编号:"); JLabel password=new JLabel("设置密码:"); JLabel pwater=new JLabel("排水量:"); JLabel vfcd=new JLabel("验证码"); JTextField data1=new JTextField(); JTextField data2=new JTextField(); JTextField data3=new JTextField(); JTextField data4=new JTextField(); JTextField data5=new JTextField(); JTextField data6=new JTextField(); JPanel jp=new JPanel(); String path="D://E//A1.jpg"; ImageIcon background=new ImageIcon(path); JLabel pack=new JLabel(background); pack.setBounds(0,0,this.getWidth(),this.getHeight()); JPanel imagePan=(JPanel) this.getContentPane(); imagePan.setOpaque(false); this.getLayeredPane().add(pack,new Integer(Integer.MIN_VALUE)); jp.add(pack); this.setResizable(false); jp.add(name); this.setSize(450,450); this.setLocation(400,300); this.add(name); this.add(jp); jp.setOpaque(false); this.setVisible(true); Random random=new Random(); int n=random.nextInt(100000,999999); String yz=String.valueOf(n); JTextField data7=new JTextField(yz); data1.setBounds(200,95,150,30); data2.setBounds(200,145,150,30); data3.setBounds(200,195,150,30); data4.setBounds(200,245,150,30); data5.setBounds(200,295,150,30); data6.setBounds(200,345,75,30); data7.setBounds(300,345,75,30); name.setBounds(100,60,100,100); Sex.setBounds(100,110,100,100); ID.setBounds(100,160,100,100); pwater.setBounds(100,210,100,100); password.setBounds(100,260,100,100); vfcd.setBounds(100,310,100,100); dete.setBounds(20,400,100,30); can.setBounds(350,400,100,30); name.setFont(new Font(name.getFont().getName(),name.getFont().getStyle(),20)); Sex.setFont(new Font(name.getFont().getName(),name.getFont().getStyle(),20)); ID.setFont(new Font(name.getFont().getName(),name.getFont().getStyle(),20)); pwater.setFont(new Font(name.getFont().getName(),name.getFont().getStyle(),20)); password.setFont(new Font(name.getFont().getName(),name.getFont().getStyle(),20)); vfcd.setFont(new Font(name.getFont().getName(),name.getFont().getStyle(),20)); this.setResizable(false); this.setSize(500,500);this.setLocation(100,100); this.add(name); this.add(pwater); this.add(ID); this.add(Sex); this.add(dete); this.add(vfcd);this.add(password); this.add(data2); this.add(data1);this.add(can); this.add(data5);this.add(data4); this.add(data3); this.add(data6);this.add(data7); this.add(jp); data1.setOpaque(false);data3.setOpaque(false);data4.setOpaque(false); data5.setOpaque(false);data6.setOpaque(false);data2.setOpaque(false); data7.setOpaque(false);jp.setOpaque(false); this.setVisible(true); dete.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { String Name=data1.getText(); String Size=data2.getText(); String Id=data3.getText(); String Pwatert=data4.getText(); String PassWord=data5.getText(); String yz=data6.getText(); if(yz.contains(data7.getText())) { Conction fg = new Conction(); fg.Connect(Name,Size,Id,Pwatert,PassWord); } else { new show1("请输入正确的验证码"); } } }); can.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { setVisible(false); } }); } } class GUIshow2 extends JFrame{ public GUIshow2(){ super("用户登录");//忘记密码的模块添加 JButton dete=new JButton("确定"); JButton forget=new JButton("忘记密码"); JButton can=new JButton("取消"); JLabel name=new JLabel("用户名:"); JLabel password=new JLabel("密码:"); JTextField data1=new JTextField(); JTextField data2=new JTextField(); data1.setBounds(200,115,150,30); data2.setBounds(200,165,150,30); name.setBounds(100,120,100,30); password.setBounds(100,170,100,30); dete.setBounds(20,400,100,30); can.setBounds(350,400,100,30); forget.setBounds(350,270,100,30); name.setFont(new Font(name.getFont().getName(),name.getFont().getStyle(),20)); password.setFont(new Font(name.getFont().getName(),name.getFont().getStyle(),20)); JPanel jp=new JPanel(); String path="D://E//12.jpg"; ImageIcon background=new ImageIcon(path); JLabel pack=new JLabel(background); pack.setBounds(0,0,this.getWidth(),this.getHeight()); JPanel imagePan=(JPanel) this.getContentPane(); imagePan.setOpaque(false); this.getLayeredPane().add(pack,new Integer(Integer.MIN_VALUE)); jp.add(pack); this.setResizable(false); this.setSize(500,500); this.setLocation(100,100); this.add(name); this.add(password); this.add(dete); this.add(can);this.add(data1);this.add(forget); this.add(data2);this.add(jp); forget.setContentAreaFilled(false); data1.setOpaque(false);data2.setOpaque(false); jp.setOpaque(false); this.setVisible(true); dete.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { String Name = data1.getText(); String Password=data2.getText(); Conction fg = new Conction(); fg.Connect(Name,Password); } }); can.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) {setVisible(false); } }); forget.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) {new seek(); } }); } } class GUIshow5 extends JFrame{ public GUIshow5(){ super("实时位置查询"); JButton dete=new JButton("查询"); JButton can=new JButton("取消"); JLabel tit0=new JLabel("温馨提示"); JLabel tit1=new JLabel("本港口提供停泊位置 100 个"); JLabel tit2=new JLabel("其中A区域停泊吨位小于5吨"); JLabel tit3=new JLabel("其中B区域停泊吨位大于等于5吨"); tit0.setBounds(30,30,350,100); tit1.setBounds(50,80,350,100); tit2.setBounds(50,130,350,100); tit3.setBounds(50,180,400,100); dete.setBounds(20,400,100,30); can.setBounds(350,400,100,30); tit0.setFont(new Font(tit1.getFont().getName(),tit1.getFont().getStyle(),25)); tit1.setFont(new Font(tit1.getFont().getName(),tit1.getFont().getStyle(),25)); tit2.setFont(new Font(tit1.getFont().getName(),tit1.getFont().getStyle(),25)); tit3.setFont(new Font(tit1.getFont().getName(),tit1.getFont().getStyle(),25)); JPanel jp=new JPanel(); String path="D://E//A4.jpg"; ImageIcon background=new ImageIcon(path); JLabel pack=new JLabel(background); pack.setBounds(0,0,this.getWidth(),this.getHeight()); JPanel imagePan=(JPanel) this.getContentPane(); imagePan.setOpaque(false); this.getLayeredPane().add(pack,new Integer(Integer.MIN_VALUE)); jp.add(pack); this.setResizable(false); this.add(dete);this.add(can);this.add(tit1);this.add(tit2);this.add(tit0);this.add(tit3); this.setSize(500,500); this.setLocation(100,100); this.add(jp); jp.setOpaque(false); this.setVisible(true); dete.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { Conction fg = new Conction(); fg.Connect(); } }); can.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { setVisible(false); } }); } } public class Main extends JFrame implements ActionListener{ public Main() { super("船舶管理系统");//设置大小 setSize(1000, 900);//设置位置 setLocation(200, 50); String path = "D://E//10.jpg";//背景图片的路径,采用绝对路径//背景图片 ImageIcon background = new ImageIcon(path);// 把背景图片显示在一个标签里面 SimpleDateFormat df=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");//显示系统时间 JLabel showtime=new JLabel(df.format(System.currentTimeMillis())); JLabel label1=new JLabel("欢迎进入港口渔船停泊管理系统"); JButton bt1=new JButton("用户登录"); JButton regbt=new JButton("新用户注册"); JButton help=new JButton("实时可停靠位置查询"); JLabel label = new JLabel(background); JPanel jp=new JPanel(); label.setBounds(0, 0, this.getWidth(), this.getHeight());// 把标签的大小位置设置为图片刚好填充整个面板 JPanel imagePanel = (JPanel) this.getContentPane(); // 把内容窗格转化为JPanel,否则不能用方法setOpaque()来使内容窗格透明 label1.setBounds(150,25,800,200); showtime.setBounds(800,5,200,75); label1.setFont(new Font(label1.getFont().getName(),label1.getFont().getStyle(),50)); showtime.setFont(new Font(label1.getFont().getName(),label1.getFont().getStyle(),20)); bt1.setBounds(425,450,150,40); help.setBounds(425,550,150,40); regbt.setBounds(425,350,150,40); regbt.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { new GUIshow1();} }); bt1.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) {new GUIshow2(); } }); help.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) {new GUIshow5(); } }); add(regbt);add(bt1); add(help);//组件添加 add(label1);add((showtime));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(); } @Override public void actionPerformed(ActionEvent e) { } }
标签:String,RuntimeException,备份,rs,try,ex,new,代码 From: https://www.cnblogs.com/liliczw2209/p/17491631.html