?? scstfrom.java~10~
字號:
package testsystem;
import java.awt.*;
import java.sql.*;
import javax.swing.*;
import java.awt.Rectangle;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class scstFrom extends JFrame {
private ImageIcon im1 = new ImageIcon("img\\red_forum.gif");
public scstFrom() {
try {
jbInit();
} catch (Exception exception) {
exception.printStackTrace();
}
}
private void jbInit() throws Exception {
this.setResizable(false);
setTitle("刪除試題");
jLabel2.setFont(new java.awt.Font("隸書", Font.BOLD, 20));
getContentPane().setLayout(null);
jt1.setBounds(new Rectangle(100, 78, 172, 34));
jLabel2.setForeground(SystemColor.desktop);
jLabel2.setHorizontalAlignment(SwingConstants.CENTER);
jLabel2.setText("試 題 刪 除");
jLabel2.setBounds(new Rectangle(87, 18, 191, 33));
jLabel1.setForeground(Color.red);
jButton1.addActionListener(new scstFrom_jButton1_actionAdapter(this));
jButton1.setIcon(im1);
this.getContentPane().add(jLabel2);
jButton1.setBounds(new Rectangle(131, 189, 111, 35));
jButton1.setText("刪除");
this.getContentPane().add(jt1);
this.getContentPane().add(jLabel1);
this.getContentPane().add(jButton1);
jLabel1.setText("請輸入要刪除的試題編號,一但刪除不可恢復請重新添加!");
jLabel1.setBounds(new Rectangle(39, 139, 319, 26));
}
public static void main(String[] args) {
scstFrom scstfrom = new scstFrom();
}
JTextField jt1 = new JTextField();
JLabel jLabel1 = new JLabel();
JLabel jLabel2 = new JLabel();
JButton jButton1 = new JButton();
public void jButton1_actionPerformed(ActionEvent e) {
String num=jt1.getText().trim();
Connection con=null;
Statement s1=null;
ResultSet rs=null;
try
{
if(num.length()!=0)
{
try
{
Integer num1=Integer.parseInt(num);
}
catch(Exception ce)
{
JOptionPane.showMessageDialog(null,"編號必須是數字!","提示",JOptionPane.ERROR_MESSAGE);
}
con=DBcon.link();
s1=con.createStatement();
rs=s1.executeQuery("select * from Question where Num='"+num+"'");
if(rs.next())
{
s1.executeUpdate("delete from Question where Num="+num+"");
JOptionPane.showMessageDialog(null,""+num+"號試題刪除成功!");
int p=JOptionPane.showConfirmDialog(null,"您是否還要添加?","提示",JOptionPane.YES_NO_OPTION);
if(p==0)
{
this.setVisible(false);
}
else
{
jt1.setText("");
jt1.requestFocus();
return;
}
}
else
{
JOptionPane.showMessageDialog(null,"對不起,您要刪除的試題編號不存在!");
jt1.setText("");
jt1.requestFocus();
}
}
else
{
JOptionPane.showMessageDialog(null,"刪除失敗");
}
}
catch(SQLException co)
{
co.getMessage();
}
}
}
class scstFrom_jButton1_actionAdapter implements ActionListener {
private scstFrom adaptee;
scstFrom_jButton1_actionAdapter(scstFrom adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.jButton1_actionPerformed(e);
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -