◀ Previous Next ▶ Up ▲


ขอความช่วยเหลือด่วนค่ะ

ตอนนี้กำลังสร้างข้อสอบโดยใช้ Jbutton เป็น choice โดยการสุ่มค่าจากDatabase Access มา settext บน jbutton ค่ะ แต่ไม่สามารถ นำค่าจากดาต้าเบสมา settext ในปุ่มได้ ขอความช่วยเหลือพี่ๆด้วยค่ะ
โคดประมานนี้อ่ะค่ะ

import java.awt.*;
import java.applet.*;
import java.awt.event.*;
import java.sql.*;
import java.awt.Container;
import javax.swing.*;




class Interface extends JFrame implements ActionListener{
ResultSet recExecute,recRead;
static ConnectDatabase Data;

private JButton bt_start,bt_w1,bt_w2,bt_w3,bt_w4,bt_w5,bt_w6,bt_w7,bt_skip;
private JLabel label;
Container cp;

Interface(){

Font font = new Font("Century Gothic",Font.BOLD,15);
label = new JLabel("Click Here To Start Program...");
cp = getContentPane();
bt_start = new JButton("Start");
bt_w1 = new JButton("");
bt_w2= new JButton("");
bt_w3= new JButton("");
bt_w4= new JButton("");
bt_w5= new JButton("");
bt_w6= new JButton("");
bt_w7= new JButton("");
bt_skip= new JButton("Skip");


bt_start.setBounds(40,35,100,30);
bt_w1.setBounds(40,100,100,30);
bt_w2.setBounds(180,100,100,30);
bt_w3.setBounds(320,100,100,30);
bt_w4.setBounds(460,100,100,30);
bt_w5.setBounds(40,170,100,30);
bt_w6.setBounds(180,170,100,30);
bt_w7.setBounds(320,170,100,30);
bt_skip.setBounds(460,170,100,30);
label.setBounds(150,-75,250,250);

cp.add(bt_start);
cp.add(bt_w1);
cp.add(bt_w2);
cp.add(bt_w3);
cp.add(bt_w4);
cp.add(bt_w5);
cp.add(bt_w6);
cp.add(bt_w7);
cp.add(bt_skip);
cp.add(label);

bt_start.setFont(font);
bt_w1.setFont(font);
bt_w2.setFont(font);
bt_w3.setFont(font);
bt_w4.setFont(font);
bt_w5.setFont(font);
bt_w6.setFont(font);
bt_w7.setFont(font);
bt_skip.setFont(font);
label.setFont(font);
bt_skip.setBackground(Color.lightGray);
bt_start.addActionListener(this);
bt_w1.addActionListener(this);
bt_w2.addActionListener(this);
bt_w3.addActionListener(this);
bt_w4.addActionListener(this);
bt_w5.addActionListener(this);
bt_w6.addActionListener(this);
bt_w7.addActionListener(this);
bt_skip.addActionListener(this);
cp.setLayout(null);
setSize(600,300);
setVisible(true);
}



public void actionPerformed(ActionEvent e){
if(e.getSource() == bt_start){

}
if(e.getSource() == bt_w1){

}
if(e.getSource() == bt_w2){

}
if(e.getSource() == bt_w3){

}
if(e.getSource() == bt_w4){

}
if(e.getSource() == bt_w5){

}
if(e.getSource() == bt_w6){

}
if(e.getSource() == bt_w7){

}
if(e.getSource() == bt_skip){

}
}
public static void main(String[] args){
Data = new ConnectDatabase();
try{
Data.Connect();
}catch(SQLException e){
JOptionPane.showMessageDialog(null,e.getMessage(),"SQL Error",JOptionPane.ERROR_MESSAGE);

}catch(ClassNotFoundException e){
JOptionPane.showMessageDialog(null,e.getMessage(),"Class not found",JOptionPane.ERROR_MESSAGE);
}

Interface i = new Interface();
i.addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent e){
System.exit(0);
}
});



}
}
class ConnectDatabase{
Connection conn;
ResultSet recRead,recExecute;
Statement statRead,statExecute;
String url = "jdbc:odbc:final_db";
String sqlRead = "SELECT * FROM fWord";
String sqlExecute = "SELECT * FROM fWord";
public void Connect()throws ClassNotFoundException,SQLException{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
conn = DriverManager.getConnection(url);
statRead = conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_READ_ONLY);
statRead = conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);

}
public ResultSet getRead() throws SQLException{
recRead = statRead.executeQuery(sqlRead);
return recRead;
}

public ResultSet getExecute()throws SQLException{
recExecute = statExecute.executeQuery(sqlExecute);
return recExecute;
}
}


จากคุณ : Momo -[ 31 ม.ค. 50 - 14:21:00 A:58.8.98.30 X: ]





กระทู้ยอดนิยม