/*
* @(#)TableExample.java 1.15 01/12/03
*
* Copyright 2002 Sun Microsystems, Inc. All rights reserved.
* SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
*/
/**
* A a UI around the JDBCAdaptor, allowing database data to be interactively
* fetched, sorted and displayed using Swing.
*
* NOTE: This example uses a modal dialog via the static convenience methods in
* the JOptionPane. Use of modal dialogs requires JDK 1.1.4 or greater.
*
* @version 1.15 12/03/01
* @author Philip Milne
*/
import java.applet.Applet;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.table.*;
import javax.swing.event.*;
import javax.swing.border.*;
import java.io.*;
public class TableExample implements LayoutManager {
static String[] ConnectOptionNames = { "Connect" };
static String ConnectTitle = "Connection Information";
Dimension origin = new Dimension(0, 0);
JButton fetchButton;
JButton showConnectionInfoButton;
JPanel connectionPanel;
JFrame frame; // The query/results window.
JLabel userNameLabel;
JTextField userNameField;
JLabel passwordLabel;
JTextField passwordField;
// JLabel queryLabel;
JTextArea queryTextArea;
JComponent queryAggregate;
JLabel serverLabel;
JTextField serverField;
JLabel driverLabel;
JTextField driverField;
JLabel FileNameLabel;
JTextField FileNameField;
JPanel mainPanel;
TableSorter sorter;
JDBCAdapter dataBase;
JScrollPane tableAggregate;
String FileName;
PrintWriter log;
/**
* Brigs up a JDialog using JOptionPane containing the connectionPanel.
* If the user clicks on the 'Connect' button the connection is reset.
*/
void activateConnectionDialog() {
if(JOptionPane.showOptionDialog(tableAggregate, connectionPanel, ConnectTitle,
JOptionPane.DEFAULT_OPTION, JOptionPane.INFORMATION_MESSAGE,
null, ConnectOptionNames, ConnectOptionNames[0]) == 0) {
connect();
frame.setVisible(true);
}
else if(!frame.isVisible())
System.exit(0);
}
/**
* Creates the connectionPanel, which will contain all the fields for
* the connection information.
*/
public void createConnectionDialog() {
// Create the labels and text fields.
userNameLabel = new JLabel("User name: ", JLabel.RIGHT);
userNameField = new JTextField("sa");
passwordLabel = new JLabel("Password: ", JLabel.RIGHT);
passwordField = new JTextField("sa");
serverLabel = new JLabel("Database URL: ", JLabel.RIGHT);
serverField = new JTextField("jdbc:odbc:JXC");
driverLabel = new JLabel("Driver: ", JLabel.RIGHT);
driverField = new JTextField("sun.jdbc.odbc.JdbcOdbcDriver");
FileNameLabel= new JLabel("文件名: ", JLabel.RIGHT);
FileNameField= new JTextField("XX");
connectionPanel = new JPanel(false);
connectionPanel.setLayout(new BoxLayout(connectionPanel,
BoxLayout.X_AXIS));
JPanel namePanel = new JPanel(false);
namePanel.setLayout(new GridLayout(0, 1));
namePanel.add(userNameLabel);
namePanel.add(passwordLabel);
namePanel.add(serverLabel);
namePanel.add(driverLabel);
namePanel.add(FileNameLabel);
JPanel fieldPanel = new JPanel(false);
fieldPanel.setLayout(new GridLayout(0, 1));
fieldPanel.add(userNameField);
fieldPanel.add(passwordField);
fieldPanel.add(serverField);
fieldPanel.add(driverField);
fieldPanel.add(FileNameField);
connectionPanel.add(namePanel);
connectionPanel.add(fieldPanel);
}
public TableExample() {
mainPanel = new JPanel();
// Create the panel for the connection information
createConnectionDialog();
// Create the buttons.
showConnectionInfoButton = new JButton("Configuration");
showConnectionInfoButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
activateConnectionDialog();
}
}
);
fetchButton = new JButton("Fetch");
fetchButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
fetch();
}
}
);
// Create the query text area and label.
queryTextArea = new JTextArea("SELECT * FROM uses", 25, 25);
queryAggregate = new JScrollPane(queryTextArea);
queryAggregate.setBorder(new BevelBorder(BevelBorder.LOWERED));
// Create the table.
tableAggregate = createTable();
tableAggregate.setBorder(new BevelBorder(BevelBorder.LOWERED));
// Add all the components to the main panel.
mainPanel.add(fetchButton);
mainPanel.add(showConnectionInfoButton);
mainPanel.add(queryAggregate);
mainPanel.add(tableAggregate);
mainPanel.setLayout(this);
// Create a Frame and put the main panel in it.
frame = new JFrame("TableExample");
frame.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {System.exit(0);}});
frame.setBackground(Color.lightGray);
frame.getContentPane().add(mainPanel);
frame.pack();
frame.setVisible(false);
frame.setBounds(200, 200, 640, 480);
activateConnectionDialog();
}
public void connect() {
dataBase = new JDBCAdapter(
serverField.getText(),
driverField.getText(),
userNameField.getText(),
passwordField.getText());
FileName=FileNameField.getText();
sorter.setModel(dataBase);
}
public void fetch() {
dataBase.executeQuery(queryTextArea.getText());
try {
log = new PrintWriter(new FileWriter(FileName+".java", true), true);
}
catch (IOException e) {
System.err.println("无法创建日志文件: " + e);
}
BornTop();
BornALL();
Bornexcute();
BornEdit();
BornAdd();
BornDel();
}
public void BornDel() {
log.println(" public void Del() throws Exception {");
log.println(" String Str=\"Delete From "+FileName+" where Id=\"+"+dataBase.getColumnName(0)+";");
log.println(" DBConnect dbc = new DBConnect();");
log.println(" dbc.executeUpdate(Str);");
log.println(" dbc.close();");
log.println(" }");
log.println("");
log.println(" }");
}
public void BornTop() {
log.println("package JXC.web;");
log.println("import JXC.Com.DBConnect;");
log.println("import java.lang.String;");
log.println("import JXC.util.StrFun;");
log.println("import java.sql.*;");
log.println("import javax.servlet.*;");
log.println("import javax.servlet.http.*;");
log.println("/**");
log.println(" * Title: 明细单信息");
log.println(" * Description:");
log.println(" * Copyright: Copyright (c) 2003");
log.println(" * Company: torch");
log.println(" * @author: wind");
log.println(" * @version 1.0");
log.println(" */");
}
public void BornALL() {
log.println("public class "+FileName +"{");
for (int i=0;i<dataBase.getColumnCount();i++)
log.println(" private "+dataBase.getColumnClassStr(i)+" "+dataBase.getColumnName(i)+";");
log.println(" public void "+FileName +"(){}");
for (int i=0;i<dataBase.getColumnCount();i++) {
String Fieldtype=dataBase.getColumnClassStr(i);
String Fieldname=dataBase.getColumnName(i);
log.println(" public "+Fieldtype+" get"+LowerOne(Fieldname)+"() {");
log.println(" return "+Fieldname+";");
log.println(" }");
log.println(" public void set"+LowerOne(Fieldname)+"("+Fieldtype+" anew) {");
log.println(" this."+Fieldname+"=anew;");
log.println(" }");
if (i==0) {
log.println(" public void set"+LowerOne(Fieldname)+"(String anew) {");
log.println(" if (anew!=null)");
log.println(" this."+Fieldname+"=Integer.parseInt(anew);");
log.println(" }");
}
}
}
public void Bornexcute(){
log.println(" public boolean ex
小浣熊6616
- 粉丝: 1
- 资源: 4
最新资源
- 机器人研究数模实验方案LQR控制,m函数调用simulink中的控制算法,在simscape Multibody中的物理模型中测试 跑通模型花了很多时间,这个能帮你节省下时间 方法适合所有机器人研
- 2023华数杯C题总结PDF
- 国内可用AI工具合集(更新到20241130)
- P2轿车并联模型,完全基于正向开发,先计算整车阻力,然后根据当前车辆模式进行扭矩分配
- 混合储能系统能量管理simulink仿真模型 蓄电池和超级电容构成的混合储能系统能量管理控制策略 采用lpf分配系统功率,放电过程中超级电容soc限值管理策略,soc高时多放电,小时少放电
- 三相整流仿真,电压外环电流内环双闭环pi控制,svpwm,pll锁相环,整流电压稳定在650v 功率等级可修改 当前为10kw 如需其他功率等级,与对应修改系统及控制参数 单相整流仿真,双闭环控制 有
- 无监督分类算法代码.zip
- 基于西门子S7-200 PLC和组态王组态3泵恒压供水系统控制
- xilinx FPGA srio 接口verilog源码程序,顶层接口封装为fifo,使用简单方便,已运用在实际项目上 本源码支持srio NWRITE、NWRITE-R、SWRITE、MAINTE
- 导轨搬运设备程序,包含三菱PLC以及信捷HMI源程序,程序包含注释,可附带电气接线图 PLC型号FX3U,人机型号:TH765 可用于各种搬运码垛设备开发参照套用,也可以作为工控爱者学习参考 不包含硬
- Python基础题库100题及答案PDF
- 通过Matlab Simulink仿真平台,以IEEE10节点配电系统为背景,通过仿真分析风机和光伏接入位置和容量对电压分布和波动的影响 包含word说明文档
- vofa+-1.3.12-x64-installer
- 1200W开关电源原理图及PCB文件
- TMC5160 步进驱动器例程
- HTML5实现好看的儿童特长培训班网页源码.zip
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
- 1
- 2
- 3
- 4
- 5
- 6
前往页