|
|
|
รบกวนช่วยดู CODE JAVA หน่อยครับ >> ต้องการ โค้ด ที่เวลา กดปุ่ม OK หลังจาก ใส่ พาส กะ ชื่อถูกต้อง ให้ลิงค์ไปที่หน้า frmWelcome<< |
|
|
|
|
|
|
|
ต้องการ โค้ด ที่เวลา กดปุ่ม OK หลังจาก ใส่ พาส กะ ชื่อถูกต้อง ให้ลิงค์ไปที่หน้า frmWelcome
ขอบคุณครับ
หน้า log in
/*
* FrmLogin.java
*
* Created on 30 มิถุนายน 2555, 11:06 น.
*/
package com.sau;
import java.awt.*;//เวลานำรูปมาใช้ ต้อง import ก่อน
import javax.swing.JOptionPane;
/**
*
* @author Administrator
*/
public class FrmLogin extends javax.swing.JFrame {
/** Creates new form FrmLogin */
public FrmLogin() {
initComponents();
setLocationRelativeTo(getRootPane());
Image imgTitle=Toolkit.getDefaultToolkit().getImage(getClass().getResource("/image/dng_gmslogo.png"));
setIconImage(imgTitle);
}
/** This method is called from within the constructor to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the Form Editor.
*/
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {
jLabel1 = new javax.swing.JLabel();
jSeparator1 = new javax.swing.JSeparator();
jLabel2 = new javax.swing.JLabel();
txtUname = new javax.swing.JTextField();
jLabel3 = new javax.swing.JLabel();
txtPassw = new javax.swing.JTextField();
jSeparator2 = new javax.swing.JSeparator();
btnOK = new javax.swing.JButton();
btnCancel = new javax.swing.JButton();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
setTitle("โปรแกรม Log In");
jLabel1.setFont(new java.awt.Font("2005_iannnnnDVD", 0, 24));
jLabel1.setForeground(new java.awt.Color(102, 51, 255));
jLabel1.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
jLabel1.setText("กรุณา Log In ก่อนเข้าใช้งาน");
jLabel2.setFont(new java.awt.Font("2005_iannnnnDVD", 0, 24));
jLabel2.setForeground(new java.awt.Color(255, 0, 204));
jLabel2.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
jLabel2.setText("ป้อนชื่อผู้ใช้ :");
jLabel3.setFont(new java.awt.Font("2005_iannnnnDVD", 0, 24));
jLabel3.setForeground(new java.awt.Color(255, 0, 204));
jLabel3.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
jLabel3.setText("ป้อนรหัสผ่าน :");
btnOK.setFont(new java.awt.Font("AngsanaUPC", 1, 18));
btnOK.setForeground(new java.awt.Color(0, 153, 255));
btnOK.setText("ตกลง");
btnOK.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnOKActionPerformed(evt);
}
});
btnCancel.setFont(new java.awt.Font("AngsanaUPC", 1, 18));
btnCancel.setForeground(new java.awt.Color(0, 153, 255));
btnCancel.setText("ยกเลิก");
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(jSeparator2, javax.swing.GroupLayout.DEFAULT_SIZE, 548, Short.MAX_VALUE)
.addContainerGap())
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(jSeparator1, javax.swing.GroupLayout.DEFAULT_SIZE, 548, Short.MAX_VALUE)
.addContainerGap())
.addGroup(layout.createSequentialGroup()
.addGap(99, 99, 99)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jLabel3)
.addComponent(jLabel2))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(txtUname, javax.swing.GroupLayout.PREFERRED_SIZE, 213, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(txtPassw, javax.swing.GroupLayout.DEFAULT_SIZE, 213, Short.MAX_VALUE))
.addContainerGap())
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addContainerGap(229, Short.MAX_VALUE)
.addComponent(btnOK)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(btnCancel)
.addGap(203, 203, 203))
.addGroup(layout.createSequentialGroup()
.addComponent(jLabel1, javax.swing.GroupLayout.DEFAULT_SIZE, 548, Short.MAX_VALUE)
.addGap(20, 20, 20))
);
layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {txtPassw, txtUname});
layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {btnCancel, btnOK});
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(jLabel1)
.addGap(18, 18, 18)
.addComponent(jSeparator1, javax.swing.GroupLayout.PREFERRED_SIZE, 10, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jLabel2)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel3)
.addComponent(txtPassw, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
.addComponent(txtUname, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(63, 63, 63)
.addComponent(jSeparator2, javax.swing.GroupLayout.PREFERRED_SIZE, 10, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(18, 18, 18)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(btnOK)
.addComponent(btnCancel))
.addContainerGap(74, Short.MAX_VALUE))
);
layout.linkSize(javax.swing.SwingConstants.VERTICAL, new java.awt.Component[] {txtPassw, txtUname});
pack();
}// </editor-fold>
private void btnOKActionPerformed(java.awt.event.ActionEvent evt) {
if(txtUname.getText().trim().equals("")){
JOptionPane.showMessageDialog(null,"ป้อนชื่อผู้ใช้ด้วยค่ะ");
}else if(txtPassw.getText().trim().equals("")){
JOptionPane.showMessageDialog(null,"ป้อนรหัสผ่านด้วยค่ะ" );
}else{
CheckLogin cl = new CheckLogin();//สร้างตัวแทนของคลาส
if(cl.checkUP(txtUname.getText().trim(), txtPassw.getText().trim()))/*ต้องส่งค่าไปให้ คลาส CheckLogin เพื่อตรวจสอบ*/{
JOptionPane.showMessageDialog(null,"ยินดีต้อนรับ" );
}else{
JOptionPane.showMessageDialog(null,"ชื่อผู้ใช้ รหัสผ่านไม่ถูกต้อง!!!");
txtPassw.setText("");
txtUname.setText("");
}
} // TODO add your handling code here:
}
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new FrmLogin().setVisible(true);
}
});
}
// Variables declaration - do not modify
private javax.swing.JButton btnCancel;
private javax.swing.JButton btnOK;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel2;
private javax.swing.JLabel jLabel3;
private javax.swing.JSeparator jSeparator1;
private javax.swing.JSeparator jSeparator2;
private javax.swing.JTextField txtPassw;
private javax.swing.JTextField txtUname;
// End of variables declaration
}
เช็ค log in
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package com.sau;
/**
*
* @author Administrator
*/
public class CheckLogin {
public boolean checkUP(String u,String p){
if(u.equals("abc")&& p.equals("123")){
return true;
}else{
return false;
}
}
}
หน้าโปรแกรม ยินดีต้อนรับ
/*
* FrmWelcome.java
*
* Created on 30 มิถุนายน 2555, 9:37 น.
*/
package com.sau;
import javax.swing.JOptionPane;
/**
*
* @author Administrator
*/
public class FrmWelcome extends javax.swing.JFrame {
/** Creates new form FrmWelcome */
public FrmWelcome() {
initComponents();
setLocationRelativeTo(getRootPane());//ทำให้รันอยู่ตรงกลางหน้าจอ//
}
/** This method is called from within the constructor to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the Form Editor.
*/
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {
jLabel1 = new javax.swing.JLabel();
jLabel2 = new javax.swing.JLabel();
txtName = new javax.swing.JTextField();
jSeparator1 = new javax.swing.JSeparator();
jSeparator2 = new javax.swing.JSeparator();
btnOK = new javax.swing.JButton();
btnExit = new javax.swing.JButton();
btnCancel = new javax.swing.JButton();
jSeparator3 = new javax.swing.JSeparator();
lblShowname = new javax.swing.JLabel();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
setTitle("โปรแกรมยินดีต้อนรับ");
jLabel1.setFont(new java.awt.Font("2005_iannnnnDVD", 1, 36));
jLabel1.setForeground(new java.awt.Color(255, 102, 0));
jLabel1.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
jLabel1.setText("โปรแกรมยินดีต้อนรับ");
jLabel2.setFont(new java.awt.Font("2005_iannnnnDVD", 1, 24));
jLabel2.setForeground(new java.awt.Color(255, 153, 0));
jLabel2.setText("ป้อนชื่อ");
btnOK.setFont(new java.awt.Font("AngsanaUPC", 1, 18));
btnOK.setText("ตกลง");
btnOK.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnOKActionPerformed(evt);
}
});
btnExit.setFont(new java.awt.Font("AngsanaUPC", 1, 18));
btnExit.setText("ปิดโปรแกรม");
btnExit.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnExitActionPerformed(evt);
}
});
btnCancel.setFont(new java.awt.Font("AngsanaUPC", 1, 18));
btnCancel.setText("ยกเลิก");
btnCancel.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnCancelActionPerformed(evt);
}
});
lblShowname.setFont(new java.awt.Font("AngsanaUPC", 1, 24));
lblShowname.setForeground(new java.awt.Color(0, 0, 255));
lblShowname.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
lblShowname.setText("??????????");
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(jSeparator2, javax.swing.GroupLayout.DEFAULT_SIZE, 430, Short.MAX_VALUE))
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(jLabel2)
.addGap(18, 18, 18)
.addComponent(txtName, javax.swing.GroupLayout.PREFERRED_SIZE, 296, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addContainerGap()
.addComponent(jSeparator1, javax.swing.GroupLayout.DEFAULT_SIZE, 430, Short.MAX_VALUE))
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addContainerGap()
.addComponent(jLabel1, javax.swing.GroupLayout.DEFAULT_SIZE, 430, Short.MAX_VALUE))
.addGroup(layout.createSequentialGroup()
.addGap(81, 81, 81)
.addComponent(btnOK)
.addGap(18, 18, 18)
.addComponent(btnCancel)
.addGap(18, 18, 18)
.addComponent(btnExit))
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(jSeparator3, javax.swing.GroupLayout.DEFAULT_SIZE, 430, Short.MAX_VALUE))
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(lblShowname, javax.swing.GroupLayout.DEFAULT_SIZE, 430, Short.MAX_VALUE)))
.addContainerGap())
);
layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {btnCancel, btnExit, btnOK});
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(25, 25, 25)
.addComponent(jLabel1)
.addGap(18, 18, 18)
.addComponent(jSeparator1, javax.swing.GroupLayout.PREFERRED_SIZE, 10, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(18, 18, 18)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel2)
.addComponent(txtName, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(27, 27, 27)
.addComponent(jSeparator2, javax.swing.GroupLayout.PREFERRED_SIZE, 10, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(btnCancel)
.addComponent(btnOK)
.addComponent(btnExit))
.addGap(18, 18, 18)
.addComponent(jSeparator3, javax.swing.GroupLayout.PREFERRED_SIZE, 10, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(lblShowname)
.addContainerGap(23, Short.MAX_VALUE))
);
pack();
}// </editor-fold>
private void btnOKActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
if(txtName.getText().trim().equals("")){
JOptionPane.showMessageDialog(null,"กรุณาป้อนชื่อ","คำเตื่อน",JOptionPane.WARNING_MESSAGE);
}else{
lblShowname.setText(txtName.getText().trim());
}
}
private void btnCancelActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
txtName.setText("");
lblShowname.setText("??????????");
}
private void btnExitActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
if (JOptionPane.showConfirmDialog(null,"คุณต้องการปิดโปรแกรมใช่หรือไม่?","ยืนยัน",JOptionPane.YES_NO_OPTION)==JOptionPane.YES_OPTION){
dispose();
}
}
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new FrmWelcome().setVisible(true);
}
});
}
// Variables declaration - do not modify
private javax.swing.JButton btnCancel;
private javax.swing.JButton btnExit;
private javax.swing.JButton btnOK;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel2;
private javax.swing.JSeparator jSeparator1;
private javax.swing.JSeparator jSeparator2;
private javax.swing.JSeparator jSeparator3;
private javax.swing.JLabel lblShowname;
private javax.swing.JTextField txtName;
// End of variables declaration
}
Tag : - - - -
|
|
|
|
|
|
Date :
2012-07-05 23:25:53 |
By :
Aol2SunG |
View :
2384 |
Reply :
1 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
จาก Code ติดปัญหาตรงไหนครับ
|
|
|
|
|
Date :
2012-07-06 06:15:32 |
By :
mr.win |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 02
|