⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 logingui.java

📁 实现了一些关与股票的功能 希望对大家有一些帮助
💻 JAVA
字号:
package gui;

import java.awt.BorderLayout;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.Connection;
import java.sql.SQLException;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JPasswordField;
import javax.swing.JTextField;

import model.Conn;
import model.Database;
import vo.UserinfoVO;

public class Logingui extends JFrame implements ActionListener {

	private Connection conn = null;

	private JPanel jp1 = null;

	private JPanel jp2 = null;

	private JTextField tf_name = null;

	private JPasswordField pf_pwd = null;

	private JLabel l_name = null;

	private JLabel l_pwd = null;

	private JButton ok = null;

	private JButton reg = null;

	private JButton cancel = null;

	private JButton guest = null;

	public Logingui(){
		jp1 = new JPanel(new GridLayout(2, 2, 5, 5));
		jp2 = new JPanel(new GridLayout(1, 4, 10, 10));
		tf_name = new JTextField(15);
		pf_pwd = new JPasswordField(15);
		l_name = new JLabel("用  户  名:", JLabel.CENTER);
		l_pwd = new JLabel("密        码:", JLabel.CENTER);
		ok = new JButton("登陆");
		reg = new JButton("注册");
		cancel = new JButton("取消");
		guest = new JButton("游客");

		jp1.add(l_name);
		jp1.add(tf_name);
		jp1.add(l_pwd);
		jp1.add(pf_pwd);

		jp2.add(ok);
		jp2.add(reg);
		jp2.add(cancel);
		jp2.add(guest);

		this.add(jp1);
		this.add(jp2, BorderLayout.SOUTH);
		this.pack();
		this.setVisible(true);
		this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		ok.addActionListener(this);
		reg.addActionListener(this);
		cancel.addActionListener(this);
		guest.addActionListener(this);
	}

	public void actionPerformed(ActionEvent e) {
		if (e.getSource().equals(ok)) {
			String username = tf_name.getText().trim();
			String password = pf_pwd.getText().trim();
			if (username != null && password != null && !"".equals(username)
					&& !"".equals(password)) {
				UserinfoVO uvo = new UserinfoVO();
				uvo.setUsername(username);
				uvo.setPassword(password);
				int flag = 0;
				try {
					flag = new Database().login(uvo);
				} catch (SQLException e1) {
					JOptionPane.showMessageDialog(null, "用户名或密码错误,请重新输入!");
					tf_name.setText("");
					tf_name.setText("");
					return;
				} catch (ClassNotFoundException e1) {
					JOptionPane.showMessageDialog(null, "数据库连接错误!");
				}
				if (flag == 1) {
					JOptionPane.showMessageDialog(null, "登陆成功!");
				} else {
					JOptionPane.showMessageDialog(null, "用户名或密码错误,请重新输入!");
					tf_name.setText("");
					pf_pwd.setText("");
					return;
				}
			} else {
				JOptionPane.showMessageDialog(null, "用户名或密码错误,请重新输入!");
			}
			this.setVisible(false);
			 
			Usegui use = null;
				try {
					 use = new Usegui();
				} catch (ClassNotFoundException e1) {
					// TODO Auto-generated catch block
					e1.printStackTrace();
				} catch (SQLException e1) {
					// TODO Auto-generated catch block
					e1.printStackTrace();
				}
				try {
					
					use.showinfo();
				} catch (Exception e1) {
					// TODO Auto-generated catch block
					e1.printStackTrace();
				}
			
			
		}

		if (e.getSource().equals(reg)) {
			this.setVisible(false);
			Reggui rg = new Reggui();
			rg.setVisible(true);
			rg.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
			return;
		}

		if (e.getSource().equals(cancel)) {
			JOptionPane.showMessageDialog(null, "感谢使用本系统");
			return;
		}

		if (e.getSource().equals(guest)) {
			try {
				this.setVisible(false);
				Guestgui ad=new Guestgui();
				ad.setVisible(true);
				try {
					ad.function1();
				} catch (Exception e1) {
					// TODO Auto-generated catch block
					e1.printStackTrace();
				}
				ad.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
			} catch (ClassNotFoundException e1) {
				// TODO Auto-generated catch block
				e1.printStackTrace();
			} catch (SQLException e1) {
				// TODO Auto-generated catch block
				e1.printStackTrace();
			}
		}

	}
	public static void main(String arg[]){ 
			Logingui lg = new Logingui(); 
			}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -