Topic: 我刚刚学JAVA程序请老手帮我``把程序加精功能` |
Print this page |
1.我刚刚学JAVA程序请老手帮我``把程序加精功能` | Copy to clipboard |
Posted by: widlb Posted on: 2005-09-23 02:11 我是个刚刚学习JAVA的菜菜鸟``我知道``要多学多写``多多请教``` ``请各位``` 老手门帮帮我把这个```程序加精`` 可能还有错误``请原谅``` ``有两点不明白``一个就是怎么```讲密码输入``的字符型数据``转换成*来代替``第2个就是``` 为所输入的数据`````怎么就是`数据从数据库中``查询到的数据了```` import java.awt.*; import java.awt.event.*; import javax.swing.*; import java.sql.*; public class User implements ActionListener { JFrame frame = new JFrame("王小明是帅哥"); JTabbedPane tp = new JTabbedPane(); // 注册界面 JPanel p1,p11,p12,p13; JLabel label11,label12; JTextField text11,text12,text13; JButton button11; // 登陆界面 JPanel p2,p21,p23; JLabel label21,label22; JTextField text21,text22; JButton button21,button22; public User() { label11=new JLabel("姓名"); text11=new JTextField(10); JPanel p11 = new JPanel(); p11.setLayout(new FlowLayout()); p11.add(label11); p11.add(text11); label12=new JLabel("密码"); text12=new JTextField(10); JPanel p12 = new JPanel(); p12.setLayout(new FlowLayout()); p12.add(label12); p12.add(text12); button11=new JButton("确定"); JPanel p13 = new JPanel(); p13.setLayout(new FlowLayout()); p13.add(button11); p1 = new JPanel(); p1.setLayout(new GridLayout(0,1)); p1.add(p11); p1.add(p12); p1.add(p13); tp.addTab("注册",p1); label21=new JLabel("用户名"); text21=new JTextField(11); JPanel p21 = new JPanel(); p21.setLayout(new FlowLayout()); p21.add(label21); p21.add(text21); label22=new JLabel("密码"); text22=new JTextField(11); JPanel p22 = new JPanel(); p22.setLayout(new FlowLayout()); p22.add(label22); p22.add(text22); button21=new JButton("确定"); button22=new JButton("清楚"); JPanel p23= new JPanel(); p23.setLayout(new FlowLayout()); p23.add(button21); p23.add(button22); p2 = new JPanel(); p2.setLayout(new GridLayout(0,1)); p2.add(p21); p2.add(p22); p2.add(p23); tp.addTab("登陆",p2); frame.getContentPane().add(tp); frame.setSize(500,350); frame.show(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); button11.addActionListener(this); button21.addActionListener(this); button22.addActionListener(this); } public void actionPerformed(ActionEvent ae) { if(ae.getSource()==button11) { String []list = new String[2]; list[0] = text11.getText().trim(); list[1] = text12.getText().trim(); String sqlStr = "insert into biao(姓名,输入密码,再次输入密码) values('"+list[0]+"','"+list[1]+"','"+list[2]+"')"; System.out.println (sqlStr); this.dbConnection(sqlStr); JOptionPane.showMessageDialog(null,"添加成功"); } if(ae.getSource()==button21) { String []list = new String[1]; list[0] = text21.getText().trim(); String sqlStr = "select * from biao"; if(!"".equals(list[0])) sqlStr += " where 用户名='"+list[0]+"'"; System.out.println (sqlStr); ResultSet rs = null; rs = this.dbConnection(sqlStr); try { while(rs.next()) { String [] list1 = new String[2]; list1[0] = rs.getString(1); list1[1] = rs.getString(2); text21.setText(list[0]); text22.setText(list[1]); } } catch (Exception ex) { ex.printStackTrace(); } } if(ae.getSource()==button22) { System.out.println ("This is 22"); } } public ResultSet dbConnection(String s) { Connection con=null; Statement sql=null; ResultSet rs=null; try { Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); } catch(ClassNotFoundException cnfe) { JOptionPane.showMessageDialog(null,"驱动错误!"); } try { String urlStr = "jdbc:odbc:driver={Microsoft Access Driver (*.mdb)};DBQ=chengjiku.mdb"; con = DriverManager.getConnection(urlStr); sql =con.createStatement(); } catch(SQLException sql1) { JOptionPane.showMessageDialog(null,"数据源错误!"); } try { if(s.toLowerCase().startsWith("select")) { rs=sql.executeQuery(s); } else { sql.executeUpdate(s); } } catch(SQLException sql2) { JOptionPane.showMessageDialog(null,"数据表操作错误!"); } return rs; } public static void main(String[] args) { // TODO: Add your code here new User(); } } |
2.Re:我刚刚学JAVA程序请老手帮我``把程序加精功能` [Re: widlb] | Copy to clipboard |
Posted by: widlb Posted on: 2005-09-23 22:31 每人看``还是我很很菜啊`` ``` 郁闷```` |
3.Re:我刚刚学JAVA程序请老手帮我``把程序加精功能` [Re: widlb] | Copy to clipboard |
Posted by: chenyoufan Posted on: 2005-09-27 13:29 知道新手的痛苦,我也是新手,55555 第一个问题 用JPasswordField test = new JPasswordField(); 第二个问题没看懂是什么意思 一一! 解释一下........LZ |
Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1 客服电话 18559299278 客服信箱 714923@qq.com 客服QQ 714923 |