📄 insertframe.java~83~
字号:
package blapp;import javax.swing.*;import java.awt.*;import java.sql.*;import java.awt.event.*;import java.util.*;import javax.swing.event.*;public class insertFrame extends JInternalFrame{ public Statement stmt; public int fw,fh; String hystring; Frame1 f; JComboBox jComboBox1 = new JComboBox(); JLabel jLabel1 = new JLabel(); JLabel jLabel2 = new JLabel(); JTextField jTextField1 = new JTextField(); JScrollPane jScrollPane1 = new JScrollPane(); JEditorPane jEditorPane1 = new JEditorPane(); JButton jButton1 = new JButton(); JButton jButton2 = new JButton(); public insertFrame(Statement st,Connection c,Frame1 fr,int w,int h) { try { jbInit(); } catch(Exception e) { e.printStackTrace(); } stmt=st; f=fr; fw=w; fh=h; } private void jbInit() throws Exception { this.setResizable(false); this.getContentPane().setLayout(null); //this.setSize(new Dimension(523, 428)); this.addInternalFrameListener(new insertFrame_this_internalFrameAdapter(this)); this.setTitle("信息录入"); this.setBackground(new Color(212,208,200)); //this.addWindowListener(new insertFrame_this_windowAdapter(this)); jComboBox1.setBackground(SystemColor.desktop); jComboBox1.setFont(new java.awt.Font("Dialog", 0, 14)); jComboBox1.setForeground(Color.white); jComboBox1.setBorder(BorderFactory.createEtchedBorder()); jComboBox1.setBounds(new Rectangle(101, 23, 215, 28)); jLabel1.setFont(new java.awt.Font("Dialog", 0, 14)); jLabel1.setText("行业类型"); jLabel1.setBounds(new Rectangle(23, 25, 70, 25)); jLabel2.setBounds(new Rectangle(23, 66, 70, 25)); jLabel2.setText("案例名称"); jLabel2.setFont(new java.awt.Font("Dialog", 0, 14)); jTextField1.setBackground(SystemColor.desktop); jTextField1.setForeground(Color.white); jTextField1.setBorder(BorderFactory.createEtchedBorder()); jTextField1.setText(""); jTextField1.setBounds(new Rectangle(101, 65, 403, 27)); jScrollPane1.setBorder(BorderFactory.createEtchedBorder()); jScrollPane1.setBounds(new Rectangle(10, 108, 498, 245)); jButton1.setBounds(new Rectangle(337, 367, 81, 27)); jButton1.setFont(new java.awt.Font("Dialog", 0, 14)); jButton1.setBorder(BorderFactory.createEtchedBorder()); jButton1.setText("确定"); jButton1.addActionListener(new insertFrame_jButton1_actionAdapter(this)); jButton2.setText("取消"); jButton2.addActionListener(new insertFrame_jButton2_actionAdapter(this)); jButton2.setBounds(new Rectangle(425, 367, 81, 27)); jButton2.setFont(new java.awt.Font("Dialog", 0, 14)); jButton2.setBorder(BorderFactory.createEtchedBorder()); this.getContentPane().add(jComboBox1, null); this.getContentPane().add(jLabel1, null); this.getContentPane().add(jLabel2, null); this.getContentPane().add(jTextField1, null); this.getContentPane().add(jScrollPane1, null); this.getContentPane().add(jButton2, null); this.getContentPane().add(jButton1, null); jScrollPane1.getViewport().add(jEditorPane1, null); openframe of=new openframe(this,new Dimension(523,431),f); } void inserted() { String insertsql = "insert into neirong (hyname,subname,texts) values('" +jComboBox1.getSelectedItem().toString() + "','" +jTextField1.getText() +"','"+jEditorPane1.getText()+"')"; try { stmt.executeUpdate(insertsql); JOptionPane.showMessageDialog(this, "成功加入!", "提示", JOptionPane.PLAIN_MESSAGE); } catch(SQLException sqlex) { JOptionPane.showMessageDialog(this, "系统错误,请与系统管理员联系!"+sqlex.toString(), "提示", JOptionPane.ERROR_MESSAGE); } } void this_windowOpened(WindowEvent e) { } void jButton2_actionPerformed(ActionEvent e) { f.jMenuItem1.setEnabled(true); super.dispose(); } void jButton1_actionPerformed(ActionEvent e) { if(jTextField1.getText().equals("")) { JOptionPane.showMessageDialog(this, "案例名称不能为空!", "提示", JOptionPane.PLAIN_MESSAGE); } else { inserted(); } } void this_internalFrameOpened(InternalFrameEvent e) { Vector vlist=new Vector(); try { String query1="SELECT hyname FROM hytype"; ResultSet rst=stmt.executeQuery(query1); while(rst.next()) { hystring=rst.getString("hyname"); vlist.addElement(String.valueOf(hystring)); } ComboBoxModel cm=new DefaultComboBoxModel(vlist); jComboBox1.setModel(cm); }catch(SQLException sqlex) {} } class openframe extends Thread{ boolean flag=true; int w ,h; Dimension dim; JInternalFrame jintfr; JFrame jframe; public openframe( JInternalFrame jin,Dimension d,Frame1 fra){ this.start(); jintfr=jin; dim=d; jframe=fra; } public void run() { w=jintfr.getWidth(); h=jintfr.getHeight(); while(flag) { if(jintfr.getWidth()<=dim.width ) { w=w+15; jintfr.setSize(w,h); } if(jintfr.getHeight()<=dim.height) { h=h+10; jintfr.setSize(w,h); } if(jintfr.getWidth()>dim.width&&jintfr.getHeight()>dim.height) { flag=false; } jintfr.setLocation((jintfr.getWidth()-fw) / 2, (jintfr.getHeight()-fh) / 3); try{ this.sleep(4);} catch(InterruptedException e) {} } } }}class insertFrame_this_windowAdapter extends java.awt.event.WindowAdapter { insertFrame adaptee; insertFrame_this_windowAdapter(insertFrame adaptee) { this.adaptee = adaptee; } public void windowOpened(WindowEvent e) { adaptee.this_windowOpened(e); }}class insertFrame_jButton2_actionAdapter implements java.awt.event.ActionListener { insertFrame adaptee; insertFrame_jButton2_actionAdapter(insertFrame adaptee) { this.adaptee = adaptee; } public void actionPerformed(ActionEvent e) { adaptee.jButton2_actionPerformed(e); }}class insertFrame_jButton1_actionAdapter implements java.awt.event.ActionListener { insertFrame adaptee; insertFrame_jButton1_actionAdapter(insertFrame adaptee) { this.adaptee = adaptee; } public void actionPerformed(ActionEvent e) { adaptee.jButton1_actionPerformed(e); }}class insertFrame_this_internalFrameAdapter extends javax.swing.event.InternalFrameAdapter { insertFrame adaptee; insertFrame_this_internalFrameAdapter(insertFrame adaptee) { this.adaptee = adaptee; } public void internalFrameOpened(InternalFrameEvent e) { adaptee.this_internalFrameOpened(e); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -