📄 studentselect.java
字号:
package Student;
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import java.sql.*;
public class StudentSelect extends JFrame{
Container cp=this.getContentPane();
JButton b1=new JButton();
JButton b2=new JButton();
JLabel jl1=new JLabel();
JLabel jl2=new JLabel();
JTextField jtf=new JTextField(15);
JPanel jp1=new JPanel();
JPanel jp2=new JPanel();
JPanel jp3=new JPanel();
String ID,CID;
public StudentSelect(String id)
{
ID=id;
try{
jbinit();
}catch(Exception e){e.printStackTrace();}
}
private void jbinit()
{
jl1.setText("填写选择课程");
jl1.setFont(new Font("ITALIC",Font.BOLD,16));
jp1.add(jl1);
jl2.setText("所选课程号");
jl2.setForeground(Color.RED);
jl2.setFont(new Font("SansSerif", Font.PLAIN, 12));
jp2.add(jl2);
jp2.add(jtf);
cp.setLayout(new BorderLayout());
cp.add(jp1,BorderLayout.NORTH);
cp.add(jp2,BorderLayout.CENTER);
b1.setText("确定");
b1.setForeground(Color.BLUE);
class Confirm implements ActionListener
{
String ID;
int then=0;
public Confirm(String IDt)
{
ID=IDt;
}
public void actionPerformed(ActionEvent e)
{
try{
MyJDBC k=new MyJDBC();
String sql="insert into wengxinzhi.result values('"+jtf.getText()+"','"+ID+"',null)";
then=k.insert(sql);
System.out.println();
if(then>0)
{
JOptionPane.showMessageDialog(null,"数据已提交");
}
}catch(Exception o){
o.printStackTrace();
JOptionPane.showMessageDialog(null,"更新数据失败");
}
}
}
b1.addActionListener(new Confirm(ID));
b2.setText("取消");
b2.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
dispose();
}
});
b2.setForeground(Color.BLUE);
jp3.add(b1);
jp3.add(b2);
cp.add(jp3,BorderLayout.SOUTH);
this.setTitle("选修课程");
this.setSize(300,200);
this.setLocation(200,200);
this.setVisible(true);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -