The lottery management system is realized through Mysql+Swing+jsp

catalogue

Function Preview

Back end main content

Login panel

Management panel

Data panel

   Menu bar

Panel switching

Operation database

Main form

key technology

verification

  Operating system process

Beautify form

Front end part

  Registration interface

jsp realizes front-end and back-end interaction

Function Preview

  • Login exclusive account
  • Add participant information
  • Delete sweepstaker information
  • View information about participating in the lottery
  • Jump to web registration / login
  • Switch account
  • Sign in

Back end main content

Login panel

This panel realizes the login function. The administrator logs in through the account and Password issued internally. If the login is not successful, the system will remind that other operations cannot be carried out.

  Key codes:

JLabel l=new JLabel("Welcome to the background management system!");
	   JLabel l1=new JLabel("account number:");
	   JLabel l2=new JLabel("password:");
	   l.setBounds(90,20,300,60);
	   l1.setBounds(30, 90, 100, 30);
	   l2.setBounds(30, 140, 100, 30);
	   l3.setBounds(230,80,150,50);
	   jtf.setBounds(100,90,100,30);
	   jpf.setBounds(100,140,100,30);
	   l.setForeground(Color.BLUE);
	   l.setFont(new Font("Song typeface",Font.BOLD,25));
	   l1.setFont(new Font("Regular script",Font.BOLD,17));
	   l2.setFont(new Font("Regular script",Font.BOLD,17));
	   l3.setFont(new Font("Regular script",Font.BOLD,17));
	   l3.setForeground(Color.RED);
	   setLayout(null);

Management panel

Key codes:

	 JLabel l1=new JLabel("Add raffle information:");
	 JLabel l2=new JLabel("id:");
	 JLabel l3=new JLabel("cell-phone number:");
	 JLabel l4=new JLabel("password:");
	 JLabel l5=new JLabel("prize:");
	 JLabel l6=new JLabel("date:");
	 JLabel l7=new JLabel("delete id:");
	 addb=new JButton("Confirm add");
	 deleb=new JButton("confirm deletion");
	 jtf1=new JTextField(20);
	 jtf2=new JTextField(20);
	 jtf3=new JTextField(20);
	 jtf4=new JTextField(20);
	 jtf5=new JTextField(20);
	 jtf6=new JTextField(20);
	 l1.setBounds(0,0,150,50);
	 l2.setBounds(0,35,100,50);
	 l3.setBounds(0,65,100,50);
	 l4.setBounds(0,95,100,50);
	 l5.setBounds(0,125,100,50);
	 l6.setBounds(0,155,100,50);
	 l7.setBounds(190,35,100,50);
	 addb.setBounds(70,200,90,30);
	 deleb.setBounds(260,80,90,30);
	 l1.setFont(new Font("Song typeface",Font.BOLD,20));
	 l2.setFont(new Font("Regular script",Font.BOLD,17));
	 l3.setFont(new Font("Regular script",Font.BOLD,17));
	 l4.setFont(new Font("Regular script",Font.BOLD,17));
	 l5.setFont(new Font("Regular script",Font.BOLD,17));
	 l6.setFont(new Font("Regular script",Font.BOLD,17));
	 l7.setFont(new Font("Regular script",Font.BOLD,17));
	 jtf1.setBounds(70,50,100,20);
	 jtf2.setBounds(70,80,100,20);
	 jtf3.setBounds(70,110,100,20);
	 jtf4.setBounds(70,140,100,20);
	 jtf5.setBounds(70,170,100,20);
	 jtf6.setBounds(260,50,100,20);
	 setLayout(null);

Data panel

  Key codes:

	my=new mysql("select *from data");
	try {
		idlist=new ArrayList<String>();
	    my.res.last();
	    int count=my.res.getRow();
	    my.res.beforeFirst();
	    my.res.next();
		String content [][] =new String[count][4];
	    for(int i=0;i<count;i++) {                    
	        content[i][0]=my.res.getString("id");
	        content[i][1]=my.res.getString("acount");
	        content[i][2]=my.res.getString("prize");
	        content[i][3]=my.res.getString("date");  
	        idlist.add(my.res.getString("id"));
	        my.res.next();        
	       }	
	    jt=new JTable(content,row);
	} catch (SQLException e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	} 
	jt.setPreferredScrollableViewportSize(new Dimension(450,200));
	JScrollPane jsp=new JScrollPane(jt);	
	add(jsp,BorderLayout.CENTER);	

   menu bar

  Key codes:
 

    JMenu gailv = new JMenu("Winning probability");
    JMenu about = new JMenu("About the author");
    JMenu getid = new JMenu("obtain id");
    JMenu rule = new JMenu("id Lottery rules");
    JMenu manage=new JMenu("About administrator");
    JMenuItem jmi1=new JMenuItem("Handsome and good quality");
    JMenuItem jmi2=new JMenuItem("Outdoor Expert");
    JMenuItem jmi3=new JMenuItem("study hard Java");
    JMenuItem jmi4=new JMenuItem("wrong vip=50%");
    JMenuItem jmi5=new JMenuItem("vip=100%");
    JMenuItem jmi6=new JMenuItem("clown=0%");
    JMenuItem jmi7=new JMenuItem("Web address");
    JMenuItem jmi8=new JMenuItem("id Length 6");
    JMenuItem jmi9=new JMenuItem("v Get exclusive prizes at the beginning");
    JMenuItem jmi10=new JMenuItem("a You have a chance to win a prize at the beginning");
    JMenuItem jmi11	=new JMenuItem("Other formats cannot participate");
    JMenuItem jmi12=new JMenuItem("The account number is issued internally");
    JMenuItem jmi13=new JMenuItem("Account lost/Password error");
    JMenuItem jmi14=new JMenuItem("Sign in");
    JMenuItem jmi15=new JMenuItem("View data");
    JMenuItem jmi16=new JMenuItem("Return management");
    JMenuItem jmi17=new JMenuItem("Switch account");

Panel switching

How to switch after writing the panel? Two lines of code!

					setContentPane(ap);
					 revalidate();//Revalidation

  Specific examples: java to switch between panels_ Worry free # blog - CSDN blog

Operation database

Operating a database serves two purposes

  1. Get information in the database
  2. Adding, deleting and modifying data in the database

For the first purpose: use the pre edited PreparedStatement to obtain data, and then loop out various data
For the second purpose: directly use Statement+execute(cmd).
Get information:
 

		try {
			 Class.forName("com.mysql.jdbc.Driver");
		} catch (ClassNotFoundException e) {
			e.printStackTrace();
		}
		try {
			c = (Connection) DriverManager.getConnection("jdbc:mysql://127.0.0.1:3306/chou_jiang?characterEncoding=UTF-8",
			        "root", "root");
			PreparedStatement ps=(PreparedStatement) c.prepareStatement(cmd);
			res=(ResultSet) ps.executeQuery();//Results obtained	
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

Addition, deletion and modification information:

	try {
		 Class.forName("com.mysql.jdbc.Driver");
	} catch (ClassNotFoundException e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	}
	try {
		Connection c = (Connection) DriverManager.getConnection("jdbc:mysql://127.0.0.1:3306/chou_jiang?characterEncoding=UTF-8",
		        "root", "root");
		Statement s=c.createStatement();
		s.execute(cmd);
	} catch (SQLException e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	}

Main form

The main window acts as a container, adds various panels to the container to visualize the data, and sets various states in the living window, such as whether it has been logged in? Have you checked in repeatedly? Add various event monitoring in the form. For example, click the login form to set it as the management panel, and click the view data form to set it as the data panel
Key codes:

   setTitle("Lottery management system");
   setBounds(200, 150, 480, 300);//Set the size and position of the form.
   setVisible(true);
   setLayout(null);

key technology

verification

Verify login status / check-in

	boolean state=false;//Login status
	boolean sign=false;//Check in
if(state==true) {
				if(sign==true) {
					JOptionPane.showMessageDialog(null, "Please do not check in again","Tips",JOptionPane.INFORMATION_MESSAGE);
				}else {
					sign=true;
					JOptionPane.showMessageDialog(null, "You have successfully checked in","Sign in",JOptionPane.INFORMATION_MESSAGE);
				}
				
			}else {
				JOptionPane.showMessageDialog(null, "Please sign in after logging in","warning!",JOptionPane.WARNING_MESSAGE);
			}


Verify whether the account password is correct
The advantage of using HashMap to store account and password is that the key and value of HashMap are one-to-one correspondence and will not be added repeatedly.

			if(map.containsKey(zh)) {
				if(map.get(zh).equals(mm)) {
					state=true;
					setContentPane(ap);
					 revalidate();//Revalidation
				}else {
					lg.l3.setText("Password error");
				}
			}else {
				 lg.l3.setText("Account does not exist");
			}

 
Operating system process

  By clicking a button or menu item, the system opens a web page (or exe) through the local browser (or program)
For example, a web page has been opened:


The general edge browser is located in C:\Program Files (x86)\Microsoft\Edge\Application. Baidu website: Baidu once, you know

try {
				ProcessBuilder pb=new ProcessBuilder("C:\\Program Files (x86)\\Microsoft\\Edge\\Application\\msedge_proxy.exe",
						"https://www.baidu.com/");
				pb.start();
			} catch (IOException e1) {
				e1.printStackTrace();
			}


Beautify form

Add a background picture to the swing text box_ Worry free # blog - CSDN blog

swing pop up menu bar with Icon_ Worry free # blog - CSDN blog

List of icons supported by swing_ Worry free # blog - CSDN blog

The title of Swing's form flashes, and the text racing light effect_ Worry free # blog - CSDN blog

Swing's beautify maximize, close, minimize buttons, beautify borders_ Worry free # blog - CSDN blog

Front end part

Because we haven't learned BootStrap yet, the front-end interface is not good-looking. We can only realize a simple registration and login interface

After learning, the picture rotation function will be added. As for the lucky draw, you can refer to a complete lucky draw system Advanced lottery system (including interface beautification, click the button to jump to the website)_ Worry free # blog - CSDN blog

In this project, the lottery principle is basically the same as that of this project. The difference in this project is that the lottery system uses io stream to save data, while this project saves data by operating the database.

  Registration interface

 

<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title>Registration interface</title>
		<script type="text/javascript">
			function yanzhengmiam(){
				var acount=document.getElementById('shoujihao').value;
				var password=document.getElementById('mima').value;
				if(acount.length!=11||password.length<6){
						
				}

</script>
	</head>
	<body>
		<div class="div1" align="center">	
			<form action="http://localhost:8080/myjsp/zhuce.jsp" method="post">
				<span id="sjh">cell-phone number</span>
				<input type="text" name="shoujihao" id="shoujihao" value="" />
				<br />
				<span id="mim">dense&nbsp;&nbsp;&nbsp;code</span>
				<input type="password" name="mima" id="password" value="" />
				<br />
				<input type="submit" value="register"/>
				<a href="Sign in.html">Existing account? Click login</a>
			</form>		
		</div>	
	</body>
</html>

jsp realizes front-end and back-end interaction

You can learn more about: eclipse uses jsp_ Worry free # blog - CSDN blog

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ page import="java.sql.*"%>

<html>
<head>
<title>adopt JSP Open data table</title>
</head>
<body>

 <%  
	try {
		 Class.forName("com.mysql.jdbc.Driver");
	} catch (ClassNotFoundException e) {
		e.printStackTrace();
	}
	try {
	Connection	c = (Connection) DriverManager.getConnection("jdbc:mysql://127.0.0.1:3306/chou_jiang?characterEncoding=UTF-8",
		        "root", "root");
		PreparedStatement ps=(PreparedStatement) c.prepareStatement("select *from data");
	ResultSet	res=(ResultSet) ps.executeQuery();//Results obtained	
	out.print("Query results:");  
    out.print("<br />");  
    out.println("cell-phone number"+"  "+"password "+"  "+"id");  
    out.print("<br />");  
    while (res.next()) {  	
     out.println(res.getString("acount")+"   &nbsp  "+res.getString("password")+"  &nbsp "+res.getString("id")); //Output query results  
    }  

	} catch (SQLException e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	}
%>   

Keywords: Java Database MySQL Eclipse swing

Added by adityamenon90 on Sat, 04 Dec 2021 01:58:50 +0200