📄 inputcourse.java~4~
字号:
package scoremis;import java.awt.*;import java.awt.event.*;import javax.swing.*;import java.sql.*;/** * <p>Title: </p> * <p>Description: </p> * <p>Copyright: Copyright (c) 2007</p> * <p>Company: </p> * @author not attributable * @version 1.0 */public class InputCourse extends JFrame{ JLabel jLabel1 = new JLabel("课程基本信息注册"); JLabel jLabel2 = new JLabel("课程名称:"); JTextField course = new JTextField(); JLabel jLabel3 = new JLabel("学时:"); JTextField period = new JTextField(); JLabel jLabel4 = new JLabel("学分:"); JTextField credit = new JTextField(); JButton sure = new JButton("确定"); JButton con = new JButton("继续"); JButton cancel = new JButton("退出"); JLabel jLabel5=new JLabel("是否必修"); ButtonGroup bg=new ButtonGroup(); JRadioButton bx1=new JRadioButton("必修"); JRadioButton bx2=new JRadioButton("选修"); String sql = " "; public InputCourse() { try { jbInit(); } catch (Exception exception) { exception.printStackTrace(); } } private void jbInit() throws Exception { setTitle("课程注册"); getContentPane().setLayout(null); //设置布局管理器为"空"布局 jLabel1.setFont(new java.awt.Font("Dialog", 1, 22)); //设置个组件的位置 jLabel1.setBounds(new Rectangle(77, 13, 186, 47)); jLabel2.setFont(new java.awt.Font("Dialog", 0, 12)); jLabel2.setText("课程名称:"); jLabel2.setBounds(new Rectangle(70, 79, 69, 35)); course.setBounds(new Rectangle(144, 84, 148, 30)); jLabel3.setFont(new java.awt.Font("Dialog", 0, 12)); jLabel3.setText("学 时:"); jLabel3.setBounds(new Rectangle(70, 119, 68, 33)); period.setBounds(new Rectangle(144, 121, 148, 29)); jLabel4.setFont(new java.awt.Font("Dialog", 0, 12)); jLabel4.setToolTipText(""); jLabel4.setText("学 分:"); jLabel4.setBounds(new Rectangle(70, 154, 75, 38)); credit.setBounds(new Rectangle(144, 158, 148, 28)); sure.setBounds(new Rectangle(59, 270, 71, 28)); sure.setFont(new java.awt.Font("Dialog", 0, 12)); con.setBounds(new Rectangle(144, 270, 71, 28)); con.setFont(new java.awt.Font("Dialog", 0, 12)); cancel.setBounds(new Rectangle(229, 270, 71, 28)); cancel.setFont(new java.awt.Font("Dialog", 0, 12)); jLabel5.setBounds(new Rectangle(68, 204, 75, 38)); bx1.setBounds(new Rectangle(143, 204, 75, 38)); bx2.setBounds(new Rectangle(218, 204, 75, 38)); sure.addActionListener(new EventHandel()); //给按钮添加监视器 con.addActionListener(new EventHandel()); cancel.addActionListener(new EventHandel()); this.getContentPane().add(jLabel1);//添加各个组件 this.getContentPane().add(course); this.getContentPane().add(jLabel2); this.getContentPane().add(jLabel3); this.getContentPane().add(period); this.getContentPane().add(credit); this.getContentPane().add(con); this.getContentPane().add(cancel); this.getContentPane().add(sure); bg.add(bx1);bg.add(bx2); this.getContentPane().add(jLabel4); this.getContentPane().add(jLabel5); this.getContentPane().add(bx1); this.getContentPane().add(bx2); } class EventHandel implements ActionListener{//事件处理类 public void actionPerformed(ActionEvent e){ if (e.getSource() ==con){//处理 "继续"事件 course.setText(" "); period.setText(" "); credit.setText(" "); }else if(e.getSource()==cancel ){//处理 "退出"事件 setVisible(false); }else{//处理 "确定添加"事件 dbconn db=new dbconn(); String kc=course.getText() ; String xs=period.getText() ; String xf=credit.getText() ; boolean bx=bx1.isSelected(); sql="insert into course(cname,period,credit,bxxx) values('"+kc+"','"+xs+"','"+xf+"',"+bx+")"; int i=db.Update(sql); if (i>0) JOptionPane.showMessageDialog(null,"课程录入成功!!"); else JOptionPane.showMessageDialog(null,"录入失败!!"); } } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -