java键盘移动选按钮_JAVA添加方向键在各框和按钮中,然后按Enter就选中按钮,(最好能在下面代码中改)...

importjavax.swing.*;importjava.awt.*;importjava.io.*;importjava.awt.event.*;importjava.sql.*;publicclassMyFrameimplementsActionListener{JFramef;JLabelname,Mima;JTextField...

import javax.swing.*;import java.awt.*;import java.io.*;import java.awt.event.*;import java.sql.*;public class MyFrame implements ActionListener{ JFrame f; JLabel name,Mima; JTextField tname,tMima; JPanel p1,p2,p3; JButton btlogin,btcancel,Zc; public MyFrame() { f=new JFrame("登录界面"); name=new JLabel("姓名:"); Mima=new JLabel("密码:"); tname=new JTextField(10); tMima=new JTextField(10); btlogin=new JButton("登陆"); btcancel=new JButton("取消"); Zc=new JButton("注册"); btlogin.addActionListener(this); btcancel.addActionListener(this); Zc.addActionListener(this); f.setLocation(100,100); f.setSize(300,400); p1=new JPanel(); p1.setLayout(new FlowLayout(FlowLayout.LEFT)); p2=new JPanel(); p2.setLayout(new FlowLayout(FlowLayout.LEFT)); p3=new JPanel(); p3.setLayout(new FlowLayout(FlowLayout.LEFT)); p1.add(name); p1.add(tname); p2.add(Mima); p2.add(tMima); p3.add(btlogin); p3.add(Zc);p3.add(btcancel); JPanel p=new JPanel(); p.setLayout(new GridLayout(3,1)); p.add(p1); p.add(p2);p.add(p3); f.add(p); f.setVisible(true); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); } public static void main(String[] args) { new MyFrame(); } public void actionPerformed(ActionEvent e) { if(e.getSource()==Zc) { String btnevent=e.getActionCommand(); String user=tname.getText(); String pass=tMima.getText(); String sql="insert into user values('"+user+"','"+pass+"')"; ConnDB conn=new ConnDB(); int num=conn.executeUpdate(sql); if(num>=1){ JOptionPane.showMessageDialog(null, "由于您"+btnevent+"了,注册成功,请登录!\n", "注册成功", JOptionPane.PLAIN_MESSAGE); }else{ JOptionPane.showMessageDialog(null, "鼠标按下,您注册失败,请重新注册!\n", "注册失败", JOptionPane.PLAIN_MESSAGE); } } else if(e.getSource()==btlogin) { String btnevent1=e.getActionCommand(); String user=tname.getText(); String pass=tMima.getText(); String sql= "select * from user where user='" +user+ "' and pass='"+pass+ "'"; ConnDB conn=new ConnDB(); ResultSet num1=conn.executeQuery(sql); if(num1==null) { Massages get=new Massages(); get.Mass(); }else{ JOptionPane.showMessageDialog(null, "您还不是用户,请先注册!\n", "登录失败", JOptionPane.PLAIN_MESSAGE); } } else if(e.getSource()==btcancel) { ConnDB conn=new ConnDB(); conn.closeConnDB(); } } }

展开

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值