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> list3 = new ArrayList<>(); ArrayList<String> list4 = new ArrayList<>(); String string1 = ""; String string2 = ""; String string3 = ""; 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(); } } catch (SQLException ex) { throw new RuntimeException(ex); } } public void Connect(String c1, String c2, String c3)//入港模块 { try (Statement stmt3 = conn.createStatement()) { ResultSet rs = stmt3.executeQuery("select * from usertable2 where username='" + c1 + "'" + "and password=" + c2); if (!rs.isBeforeFirst())//获取行号 { new show1("请输入正确的用户名或者密码"); } else { String sql4 = "INSERT INTO usertable4(PNM,PASS,STIM) VALUES (?,?,?)"; try { PreparedStatement stat = conn.prepareStatement(sql4);//进行预编译 stat.setString(1, c1); stat.setString(2, c2); stat.setString(3, c3); stat.executeUpdate(); } catch (SQLException ex) { throw new RuntimeException(ex); } String sql2 = "select * from usertable4"; PreparedStatement stmt = null; PreparedStatement stmt2 = null; try { stmt = conn.prepareStatement(sql4); stmt2 = conn.prepareStatement(sql2); } catch (SQLException ex) { throw new RuntimeException(ex); } try (ResultSet res = stmt2.executeQuery()) { while (res.next()) { String title = res.getString("PNM"); list3.add(title); } for (int i = 0; i < list3.size(); i++) { if (list3.get(i).contains(c1)) { string3 = list3.get(i); } } new show1(string3, "申请成功"); } 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); } } } catch (SQLException ex) { throw new RuntimeException(ex); } } public void Connect(String k1, String k2, int m) {// 模块4 try (Statement stmt3 = conn.createStatement()) { ResultSet rs = stmt3.executeQuery("select * from usertable4 where PNM='" + k1 + "'" + "and PASS=" + k2); if (!rs.isBeforeFirst())//获取行号 { new show1("请输入正确的用户名或者密码"); } else { String sql2 = "select DATEDIFF(day,STIM,'2023-06-16') as age from usertable4 "; 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 usertable4 where PNM=?"; 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); } } public void Connect() {//模块5可用位置查询 try (Statement stmt5 = conn.createStatement()) { int num=0; ResultSet rs = stmt5.executeQuery("select count(PNM) from usertable4 "); while(rs.next()) { String p= rs.getString(1); num=Integer.parseInt(p,10); } String h = "已用位置" + num + "剩余位置" + (100 - num); new show1(h); } 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); } } } 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 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); } } 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() { 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) { } }); 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 GUIshow3 extends JFrame{ public GUIshow3(){ super("停靠管理"); JButton dete=new JButton("确定"); JButton can=new JButton("取消"); JButton forget=new JButton("忘记密码"); JLabel name=new JLabel("用户名:"); JLabel password=new JLabel("登录密码:"); JLabel st=new JLabel("输入停靠港口时间:"); JTextField data1=new JTextField(); JTextField data2=new JTextField(); JTextField data3=new JTextField(); data1.setBounds(260,115,150,30); data2.setBounds(260,165,150,30); data3.setBounds(260,215,150,30); name.setBounds(50,80,100,100); password.setBounds(50,130,100,100); st.setBounds(50,180,200,100); dete.setBounds(50,400,100,30); can.setBounds(350,400,100,30); forget.setBounds(350,270,100,30); forget.setContentAreaFilled(false); name.setFont(new Font(name.getFont().getName(),name.getFont().getStyle(),20)); password.setFont(new Font(name.getFont().getName(),name.getFont().getStyle(),20)); st.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(password);this.add(st);this.add(dete);this.add(can); this.add(data1); this.add(data2);this.add(data3);this.add(jp);this.add(forget); this.add(jp); jp.setOpaque(false); data1.setOpaque(false);data2.setOpaque(false);data3.setOpaque(false);//设置为透明 this.setVisible(true); this.setResizable(false); dete.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { String g1=data1.getText(); String g2=data2.getText();String g3=data3.getText(); Conction fg = new Conction(); fg.Connect(g1,g2,g3); } }); 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 GUIshow4 extends JFrame{ public GUIshow4(){ super("停靠管理"); JButton dete=new JButton("确定");//组件添加 JButton can=new JButton("取消"); JLabel name=new JLabel("用户名:"); JLabel password=new JLabel("登录密码:"); JButton forget=new JButton("忘记密码"); JTextField data1=new JTextField(); JTextField data2=new JTextField(); data1.setBounds(260,115,150,30);//绝对位置设置 data2.setBounds(260,165,150,30); name.setBounds(50,80,100,100); password.setBounds(50,130,100,100); dete.setBounds(50,400,100,30); can.setBounds(350,400,100,30); forget.setBounds(350,270,100,30); forget.setContentAreaFilled(false);//将按钮设置为透明 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//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.setSize(500,500); this.setLocation(100,100); forget.setContentAreaFilled(false); this.add(name); this.add(password);this.add(dete);this.add(can); this.add(data1); this.add(data2);this.add(forget);this.add(jp); this.add(jp); jp.setOpaque(false); data1.setOpaque(false); data2.setOpaque(false); this.setResizable(false); this.setVisible(true); dete.addActionListener(new ActionListener() {//确定事件处理 @Override public void actionPerformed(ActionEvent e) { String g1=data1.getText(); String g2=data2.getText(); Conction fg = new Conction(); fg.Connect(g1,g2,5); } }); 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 tit1=new JLabel("本港口提供停泊位置 100 个"); tit1.setBounds(50,80,350,100); dete.setBounds(20,400,100,30); can.setBounds(350,400,100,30); tit1.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.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("志文的小demo");//设置大小 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 tstop=new JButton("离港申请"); //JButton stop=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)); // help.setBounds(425,550,150,40); // tstop.setBounds(425,500,150,40); // stop.setBounds(425,450,150,40); bt1.setBounds(425,450,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(); } }); /*stop.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { new GUIshow3(); } });*/ /* tstop.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { new GUIshow4(); } }); help.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) {new GUIshow5(); } });*/ add(regbt);add(bt1); //add(stop); add(help);//组件添加 //add(tstop); 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) { } }
标签:课程设计,java,name,setBounds,add,new,100,JLabel From: https://www.cnblogs.com/liliczw2209/p/17490420.html