|
|
- - - - - - - - - - - - - - ผู้ให้การสนับสนุน- - - - - - - - - - - - - -
|
|
|
กระทู้ #681 [Java] (จาก IP: 203.146.63.187)
ช่วยบอกจาวาที่ใช้ login หน่อยครับต้องการใช้ด่วน
ช่วยบอกจาวาที่ใช้ login หน่อยครับต้องการใช้ด่วน เอาแบบให้มันใส่รหัส ใส่ไอดี ได้ก็พอครับ และช่วยบอกวิธีใช้ให้ด้วยนะครับ ขอบคุณมากครับ
|
จากคุณ
:
kaka / deltaforce-x@hotmail.com [2006-11-05 20:36:24]
|
|
ความคิดเห็น #25750 (จาก IP: 203.118.97.85)
import javax.swing.*; import java.awt.event.*; import java.awt.*;
class login extends JFrame //implements ActionListener { private JLabel lb1,lb2,lb3,lb4; private JTextField txt1, txt2, txt3; private JButton b1; private JPasswordField pws1; public login() { setTitle("Add Data"); Container c = getContentPane(); c.setLayout(null); c.add(txt1 = new JTextField("", 3)); c.add(txt2 = new JTextField("", 3)); c.add(txt3 = new JTextField("", 3)); c.add(b1 = new JButton("Add")); c.add(lb1 = new JLabel("Product Id")); c.add(lb2 = new JLabel("Value")); c.add(lb3 = new JLabel("Description")); c.add(lb4 = new JLabel("")); //c.add(pws1 = new JPasswordField("",3)); lb1.setBounds(10,10,60,20); txt1.setBounds(100,10,90,20); lb2.setBounds(10,30,90,20); txt2.setBounds(100,30,90,20); b1.setBounds(100,120,90,20); lb3.setBounds(10,50,130,20); txt3.setBounds(100,50,90,20); lb4.setBounds(100,90,150,20); show(); } public static void main(String[] args) { login f = new login(); f.setSize(400,400); f.addWindowListener (new WindowAdapter() { public void windowClosing( WindowEvent e ) {System.exit(0); } });
} }
วิธีใช้ก็ แอดมาถามเอาละกานนะครับ |
จากคุณ
:
NonTz / nunontz@hotmail.com [2007-07-18 03:59:07]
|
|
ความคิดเห็น #25751 (จาก IP: 203.118.97.85)
อ่อ มีบางส่วนที่ต้องแก้ใขนะครับ ยังไงๆ ก้ออ่านเอานะ ไม่ยากหรอก |
จากคุณ
:
NonTz / nunontz@hotmaill.com [2007-07-18 04:09:04]
|
|
ความคิดเห็น #27455 (จาก IP: 222.123.180.79)
import java.awt.*; import java.awt.event.*; import javax.swing.*;
import java.sql.Connection; import java.sql.DriverManager; import java.sql.SQLException; import java.sql.*; import javax.swing.JOptionPane;
public class Login extends JFrame implements ActionListener { private Container container; private GridBagLayout layout; private GridBagConstraints gbc;
private JButton cmdLogin, cmdCancel; private JLabel lblUSer, lblPassword; private JTextField txtUser; private JPasswordField txtPassword;
String username = null; String password = null;
Connection conn = null; Statement stat; PreparedStatement pstat = null; Statement stmt=null; ResultSet rs = null; String dbUser = null; String dbPass = null; String dbUrl = null; boolean loop = false;
public Login() { // ***************************** Connection ******************************
try { dbUser = \"root\"; dbPass = \"123456\"; dbUrl = \"jdbc:mysql://localhost/logistic_db?\" + \"user=root&password=123456\"; Class.forName (\"com.mysql.jdbc.Driver\").newInstance (); conn = DriverManager.getConnection (dbUrl, dbUser, dbPass); System.out.println (\"Database connection established\");
stat = conn.createStatement(); System.out.println(\"connection opened\"); } catch (Exception e) { System.err.println (\"Cannot connect to database server\"); }
// ***************************** Connection ******************************
setTitle(\"Login Screen\"); // or //super(\"Login window\"); setExtendedState(JFrame.MAXIMIZED_BOTH); setResizable(false); //disable resizing and Max button
setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); setSize(300,150); setLocationRelativeTo(null);
container = getContentPane(); layout = new GridBagLayout(); container.setLayout(layout);
gbc = new GridBagConstraints();
lblUSer = new JLabel(\"Username:\"); gbc.insets = new Insets(2,2,2,2); container.add(lblUSer, gbc);
txtUser = new JTextField(15); gbc.gridx = 1; gbc.gridwidth = 3; container.add(txtUser, gbc);
lblPassword = new JLabel(\"Password:\"); gbc.gridy = 1; gbc.gridx = 0; gbc.gridwidth = 1; container.add(lblPassword, gbc);
txtPassword = new JPasswordField(15); gbc.gridx = 1; gbc.gridwidth = 3; container.add(txtPassword, gbc);
cmdLogin = new JButton(\"Login\"); cmdLogin.addActionListener( this ); gbc.gridy = 2; gbc.gridx = 1; gbc.gridwidth = 1; container.add(cmdLogin, gbc);
cmdCancel = new JButton(\"Cancel\"); cmdCancel.addActionListener( this ); gbc.gridx = 2; container.add(cmdCancel, gbc); } //Login()
public void actionPerformed(ActionEvent e){ if(e.getActionCommand().equals(\"Login\")){
username = new String(txtUser.getText()); password = new String(txtPassword.getPassword()); System.out.println(\"Username: \" + username); System.out.println(\"Password: \" + password);
do{ loop = false; //stmt = conn.createStatement(); //rs = stmt.executeQuery(\"SELECT username,password FROM Login WHERE username=\'\"+username+\"\'and password = \'\"+password+ \"\'\"); pstat = conn.prepareStatement(\"SELECT username,password from Login where username=?\"+ username + \"and password =?\"+password+ \" \");
pstat.setString(1,username); pstat.setString(2,password); rs = pstat.executeQuery(); if(!rs.next() && rs.getRow() == 0) { JOptionPane.showMessageDialog(null, \"Wrong Username or Password, try again\", \"Warning !!!\", JOptionPane.WARNING_MESSAGE); txtUser.setText(\"\"); txtPassword.setText(\"\"); loop = true;
break; } else{ JOptionPane.showMessageDialog(null, \"Welcome, you can use the program ...\", \"Welcome\", JOptionPane.WARNING_MESSAGE); } } while (loop); } else { //default icon, custom title int respond = JOptionPane.showConfirmDialog(null, \"Would you like exiting the program ?\", \"Exiting\", JOptionPane.YES_NO_OPTION); //System.out.println(respond); if(respond == 0){ dispose (); //closing the frame } } } //actionPerformed()
public static void main(String args[]) { new Login().setVisible(true); } //main()
} //Login |
จากคุณ
:
แอ / itechno.pn@windowslive.com [2009-05-26 13:13:07]
|
|
|
- - - - - - - - - - - - - - ผู้ให้การสนับสนุน- - - - - - - - - - - - - -
|
|
|
|
|