📄 frmlogon.java
字号:
package client;
import java.awt.*;
import java.awt.event.*;
import java.io.*;
import java.net.InetAddress;
import java.net.Socket;
import java.net.UnknownHostException;
import java.sql.*;
import javax.swing.*;
public class frmLogOn extends JFrame implements ActionListener,ItemListener
{
static final int port=8080;
Socket s;
DataOutputStream dos;
DataInputStream dis;
JButton btRegister,btLogOn;
JRadioButton jrbIndividual,jrbComp,jrbInvest,jrbBank;
JTextField jtfID,jtfIP;
JPasswordField jpfPW;
int sort;
member strMeg=new member();
public frmLogOn()
{
this.setTitle("登录");
setSize(400, 300);
setBackground(Color.BLACK);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JLabel labelID=new JLabel("系统帐号");
labelID.setBackground(Color.BLACK);
JLabel labelPW=new JLabel(" 密码");
JLabel jlbIP=new JLabel("登录地址");
JLabel labelGetPW=new JLabel("忘记密码?");
labelGetPW.addMouseListener(new MouseAdapter(){
public void mousePressed(MouseEvent e)
{
try {
s=new Socket(jtfIP.getText().trim(),port);
dos=new DataOutputStream(s.getOutputStream());
dis=new DataInputStream(s.getInputStream());
} catch (UnknownHostException e1) {
e1.printStackTrace();
} catch (IOException e1) {
e1.printStackTrace();
}
new frmGetPW(dos,dis);
}
});
labelGetPW.setForeground(Color.red);
jtfID=new JTextField("fang",23);
jtfIP=new JTextField("127.0.0.1",23);
jpfPW=new JPasswordField("5231371",23);
jrbIndividual=new JRadioButton("个人用户");
jrbComp=new JRadioButton("软件公司用户");
jrbInvest=new JRadioButton("投资公司用户");
jrbBank=new JRadioButton("银行用户");
ButtonGroup group=new ButtonGroup();
group.add(jrbIndividual);
group.add(jrbComp);
group.add(jrbInvest);
group.add(jrbBank);
jrbIndividual.addItemListener(this);
jrbComp.addItemListener(this);
jrbInvest.addItemListener(this);
jrbBank.addItemListener(this);
final JButton b1=new JButton("注册");
btLogOn=new JButton("登录");
final Container con=this.getContentPane();
b1.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
if(e.getSource()==b1)
{
try {
if(jtfIP.getText().trim().equals(""))
{
JOptionPane.showMessageDialog(null,"请务必填写IP地址","提示",JOptionPane.INFORMATION_MESSAGE);
}
else
{
s=new Socket(jtfIP.getText().trim(),port);
dos=new DataOutputStream(s.getOutputStream());
dis=new DataInputStream(s.getInputStream());
}
} catch (UnknownHostException e1) {
e1.printStackTrace();
} catch (IOException e1) {
e1.printStackTrace();
}
new frmRegister(dos,dis);
}
}
});
btLogOn.addActionListener(this);
con.setBackground(Color.LIGHT_GRAY);
GridLayout gl=new GridLayout(5,1);
con.setLayout(gl);
JPanel p2=new JPanel();
JPanel p3=new JPanel();
JPanel p4=new JPanel();
p2.add(labelID);
p2.add(jtfID);
con.add(p2);
p3.add(labelPW);
p3.add(jpfPW);
p3.add(labelGetPW);
con.add(p3);
JPanel p1=new JPanel();
p1.add(jrbIndividual);
p1.add(jrbComp);
p1.add(jrbInvest);
p1.add(jrbBank);
con.add(p1);
JPanel p5=new JPanel();
p5.add(jlbIP);
p5.add(jtfIP);
con.add(p5);
p4.add(b1);
p4.add(btLogOn);
con.add(p4);
this.setVisible(true);
}
public void actionPerformed(ActionEvent e) {
if(e.getSource()==btLogOn)
{
try {
if(jtfIP.getText().trim().equals(""))
{
JOptionPane.showMessageDialog(null,"请务必填写IP地址","提示",JOptionPane.INFORMATION_MESSAGE);
}
else
{
s=new Socket(jtfIP.getText().trim(),port);
dos=new DataOutputStream(s.getOutputStream());
dis=new DataInputStream(s.getInputStream());
}
} catch (UnknownHostException e1) {
e1.printStackTrace();
} catch (IOException e1) {
e1.printStackTrace();
}
if(sort==0||jtfID.getText().trim().equals("")||new String (jpfPW.getPassword()).equals(""))
{
JOptionPane.showMessageDialog(null,"请完善资料","提示",JOptionPane.INFORMATION_MESSAGE);
}
else
{
ClientMessage_member message=new ClientMessage_member();
try {
message.UpdateInfo(dos, dis,jtfID.getText().trim(),new String(jpfPW.getPassword()),null,null, sort,0,2);
if(!dis.readBoolean())
{
JOptionPane.showMessageDialog(null,"无此用户","提示",JOptionPane.INFORMATION_MESSAGE);
}
else
{
this.setVisible(false);
strMeg=message.GetInfo(dos, dis,2);
new frmMain(dos,dis,s,strMeg);
}
} catch (IOException e1) {
// TODO 自动生成 catch 块
e1.printStackTrace();
} catch (SQLException e2) {
// TODO 自动生成 catch 块
e2.printStackTrace();
}
}
}
}
public void itemStateChanged(ItemEvent e) {
if(jrbIndividual.isSelected())
{
sort=1;
}
if(jrbComp.isSelected())
{
sort=2;
}
if(jrbInvest.isSelected())
{
sort=3;
}
if(jrbBank.isSelected())
{
sort=4;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -