import java.awt.Color;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
import java.io.IOException;
import java.sql.SQLException;
import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.JTextField;
import com.linuxense.javadbf.DBFException;
import jxl.read.biff.BiffException;
public class mainFrame extends test implements ActionListener{
JFrame frame;
JButton open1 = new JButton("browse...");
JButton open2 = new JButton("browse...");
JButton excelButton = new JButton("Execute");
JButton dbfButton = new JButton("Execute");
JTextField nameField1 = new JTextField(60);
JTextField nameField2 = new JTextField(60);
JScrollPane jsp;
JTextArea info = new JTextArea();
File file;
public mainFrame() {
frame = new JFrame("Dtabase Interface");
JLabel banner = new JLabel("Database Interface(Oracle)");
banner.setFont(new java.awt.Font("Dialog",1,25));
banner.setForeground(Color.blue);
banner.setBounds(140,5,370,70);
frame.add(banner);
frame.setLayout(null);
jsp = new JScrollPane(info,JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
JPanel p1 = new JPanel();
JPanel p2 = new JPanel();
JPanel p3 = new JPanel();
info.setEditable(false);
open1.addActionListener(this);
open2.addActionListener(this);
excelButton.addActionListener(this);
dbfButton.addActionListener(this);
p1.setBorder(BorderFactory.createLineBorder(new Color(1,46,4), 2));
JLabel banner1 = new JLabel("choose a xls file:");
banner1.setFont(new java.awt.Font("Dialog",1,14));
banner1.setForeground(Color.orange);
banner1.setBounds(5,25,170,20);
JLabel banner2 = new JLabel("table name:");
banner2.setFont(new java.awt.Font("Dialog",1,14));
banner2.setForeground(Color.orange);
banner2.setBounds(5,50,130,20);
p1.setBounds(100,80,380,160);
p1.add(nameField1);
p1.add(open1);
p1.add(banner1);
p1.add(banner2);
p1.add(excelButton);
p1.setLayout(null);
nameField1.setBounds(120,50,210,20);
nameField2.setBounds(120,50,210,20);
open1.setBounds(180,25,80,20);
open2.setBounds(180,25,80,20);
excelButton.setBounds(120,100,80,40);
p2.setBorder(BorderFactory.createLineBorder(new Color(1,46,4), 2));
JLabel banner3 = new JLabel("choose a dbf file:");
banner3.setFont(new java.awt.Font("Dialog",1,14));
banner3.setForeground(Color.orange);
banner3.setBounds(5,25,170,20);
JLabel banner4 = new JLabel("table name:");
banner4.setFont(new java.awt.Font("Dialog",1,14));
banner4.setForeground(Color.orange);
banner4.setBounds(5,50,130,20);
p2.setBounds(100,270,380,160);
p2.add(nameField2);
p2.add(open2);
p2.add(dbfButton);
p2.add(banner3);
p2.add(banner4);
p2.setLayout(null);
dbfButton.setBounds(120,100,80,40);
p3.setBorder(BorderFactory.createLineBorder(new Color(1,46,4), 2));
p3.setBounds(100,450,380,120);
p3.add(jsp);
p3.setLayout(null);
jsp.setBounds(15,30,350,80);
info.append("click 'browse...' to choose a file you want to read from, \n enter the table name in the field below, then click 'Execute', \n the table will be created base on the data in the file. ");
frame.add(p1);
frame.add(p2);
frame.add(p3);
frame.setSize(620,620);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
}
public void open(){
JFileChooser filechooser = new JFileChooser();
filechooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
int select = filechooser.showOpenDialog(frame);
if (select == JFileChooser.APPROVE_OPTION) {
file = filechooser.getSelectedFile();
if (file == null) {
return;
}
System.out.println(file.getPath());
}
}
public void actionPerformed(ActionEvent e) {
JButton jb = (JButton) e.getSource();
if (jb == open1) {
open();
} else if (jb == open2) {
open();
} else if (jb == excelButton) {
String name = nameField1.getText();
System.out.println(name);
excelReader er = new excelReader(file);
try {
er.readAndCreate(conn, name);
} catch (BiffException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
} catch (InstantiationException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
} catch (IllegalAccessException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
} catch (ClassNotFoundException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
} catch (SQLException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
} else if (jb == dbfButton) {
String name = nameField2.getText();
System.out.println(name);
dbfReader dr = new dbfReader(file);
try {
dr.readAndCreate(conn, name);
} catch (DBFException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
} catch (SQLException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
}
}
}