zoukankan      html  css  js  c++  java
  • java界面登陆

    网站系统开发需要掌握的技术:

    1. 至少熟悉一种建站程序。
    2. 对空间和域名的知识有一定的了解。

    3. 有一些美工基础。

    4. 对编程有一些了解。

    5. 代码知识基本的要懂。

    6. css+div会一点。

    7. 简单的网站优化技术。

    8. 熟悉引擎规则。

    9. 当然其他的还要懂很多,有以上的基础做一个简单的网站就可以了。

    import java.awt.event.*;
    import java.awt.*;
    import javax.swing.*;
    import java.sql.Connection;
    import java.sql.DriverManager;
    import java.sql.ResultSet;
    import java.sql.SQLException;
    import java.sql.Statement;
    class B extends JFrame implements ActionListener
    {
    JPanel Interface = new JPanel(null)
    {
    public void paintComponent(Graphics g)
    {
    super.paintComponent(g);
    ImageIcon img=new ImageIcon("F:\ff123.jpg");
    g.drawImage(img.getImage(),0,0,getWidth(),getHeight(),img.getImageObserver());
    }
    };
    JButton Determine=new JButton("确定");
    JLabel Prompt;
    B(int a)
    {
    if(a==1)
    Prompt=new JLabel("用户名不存在!");
    if(a==2)
    Prompt=new JLabel("密码错误!");
    if(a==3)
    Prompt=new JLabel("登陆成功!");
    if(a==4)
    Prompt=new JLabel("请输入用户信息!");
    Prompt.setBounds(50,30,150,23);
    Determine.setBackground(Color.WHITE);
    Determine.setForeground(Color.black);
    Determine.setBounds(103,60,64,25);
    Determine.setFont(new Font("黑体",Font.PLAIN,15));
    Prompt.setFont(new Font("黑体",Font.PLAIN,15));
    Prompt.setHorizontalAlignment(SwingConstants.CENTER);
    Prompt.setForeground(Color.black);
    Interface.add(Prompt);
    Interface.add(Determine);
    getContentPane().add(Interface);
    Determine.addActionListener(this);
    setTitle("提示");
    setSize(250,150);
    setVisible(true);
    setResizable(false);
    setLocationRelativeTo(null);
    setLayout(new GridLayout());
    setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
    }
    public void actionPerformed(ActionEvent e)
    {
    dispose();
    }
    }
    class A extends JFrame implements ActionListener
    {
    JPanel Interface = new JPanel(null)
    {
    public void paintComponent(Graphics g)
    {
    super.paintComponent(g);
    ImageIcon img=new ImageIcon("F:\ff123.jpg");
    g.drawImage(img.getImage(),0,0,getWidth(),getHeight(),img.getImageObserver());
    }
    };
    JLabel[] title = new JLabel [2];
    JTextField getid = new JTextField();
    JPasswordField getcode = new JPasswordField();
    JButton Land = new JButton("登录");
    A()
    {
    for(int i=0;i<2;i++)
    title[i]=new JLabel();
    title[0].setText("用户名:");
    title[1].setText("密 码:");
    title[0].setBounds(90, 70, 50, 23);
    getid.setBounds(140,70,150,23);
    title[1].setBounds(90, 110, 50, 23);
    getcode.setBounds(140,110,150,23);
    Land.setBounds(100,180,180,25);
    Land.setBackground(Color.cyan);
    Land.setForeground(Color.black);
    for(int i=0;i<2;i++)
    {
    title[i].setFont(new Font("黑体",Font.PLAIN,13));
    title[i].setForeground(Color.black);
    }
    Land.setFont(new Font("黑体",Font.PLAIN,15));
    Interface.add(title[0]);
    Interface.add(getid);
    Interface.add(title[1]);
    Interface.add(getcode);
    Interface.add(Land);
    Land.addActionListener(this);
    getContentPane().add(Interface);
    setTitle("登陆窗口");
    setSize(400,300);
    setVisible(true);
    setResizable(false);
    setLocationRelativeTo(null);
    setLayout(new GridLayout());
    setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
    }
    public void actionPerformed(ActionEvent e) //触发事件后的处理方法
    {
    String str1=null;
    String str2=null;
    str1=getid.getText().replaceAll(" ","");
    str2=String.valueOf(getcode.getPassword()).replaceAll(" ","");
    boolean result1=true;
    if(str1==null||str1.equals(""))
    result1=false;
    if(str2==null||str2.equals(""))
    result1=false;
    if(result1)
    {
    int result2=queryresult(str1,str2);
    if(result2==0)
    new B(1);
    if(result2==1)
    new B(2);
    if(result2==2)
    new B(3);
    }
    else
    new B(4);
    }
    public int queryresult(String id,String code)
    {
    String conURL="jdbc:mysql://localhost:33060/jaovo_msg";
    int result=0;
    try
    {
    Class.forName("com.mysql.jdbc.Driver");
    }
    catch (java.lang.ClassNotFoundException e1)
    {
    System.out.println(e1.getMessage());
    }
    try {
    Connection con;
    con = DriverManager.getConnection(conURL,"root","root");
    Statement add=con.createStatement();
    String str="select * from example";
    ResultSet rs=add.executeQuery(str);
    while(rs.next())
    {
    String a1;
    String a2;
    a1=rs.getString("用户名");
    a2=rs.getString("用户密码");
    if(a1.equals(id))
    {
    if(a2.equals(code))
    result=2;
    else
    result=1;
    }
    }
    rs.close();
    con.close();
    }
    catch (SQLException e)
    {
    e.printStackTrace();
    System.out.println(e.getMessage());
    }
    return result;
    }
    }
    public class Example4
    {
    public static void main(String args[])
    {
    new A();
    }
    }

    实验结果截图:

    课堂测试未按时完成成的原因:思维错误

    对这门课的希望和自己的目标,并具体列出你计划每周花多少时间在这门课上:

    能够进行简单软件的开发,每周预期花16~20个小时

  • 相关阅读:
    python之高阶函数
    [第二版]多线程的发送与接收
    基本函数与结构
    unp.h
    gdb调试命令
    System V共享内存区
    Posix 共享内存区
    System V信号量
    Posix 信号量
    记录锁
  • 原文地址:https://www.cnblogs.com/DaisyYuanyq/p/7885886.html
Copyright © 2011-2022 走看看