00001 package clientswing.UI;
00002
00003 import javax.swing.*;
00004 import java.util.*;
00005 import java.awt.*;
00006 import java.awt.event.*;
00007 import clientswing.model.*;
00008
00014 public class OptionPanelInsertUpdate
00015 extends BaseForm {
00017 JLabel[] labels =null;
00021 JLabel errore = new JLabel();
00023 JTextField[] textFields=null;
00025 Column[] columns=new Column[3];
00027 JButton invia = new JButton("invia");
00029 JTextField columnNumSet;
00031 boolean isError;
00032
00034 JLabel[] labelsValue =null;
00036 JTextField[] textFieldsValue=null;
00041 public OptionPanelInsertUpdate(JTextField columnNumSet) {
00042
00043 Toolkit kit = Toolkit.getDefaultToolkit();
00044 Dimension screenSize = kit.getScreenSize();
00045
00046 int screenHeight = screenSize.height;
00047 int screenWidth = screenSize.width;
00048
00049 setSize(screenWidth / 2 , screenHeight / 2);
00050 setLocation(screenWidth / 4 + 350, screenHeight / 4);
00051
00052 this.getContentPane().setLayout(null);
00053
00054 int num = 0;
00055 isError=false;
00056 try {
00057 num = Integer.parseInt(columnNumSet.getText());
00058 try {
00059 labels = new JLabel[num];
00060 textFields = new JTextField[num];
00061 labelsValue =new JLabel[num];
00062 textFieldsValue=new JTextField[num];
00063
00064 }
00065 catch (Exception ex1) {
00066 columnNumSet.setBackground(Color.pink);
00067
00068
00069
00070
00071 JOptionPane.showMessageDialog(null, "errore di inserimento", "errore di inserimento", JOptionPane.WARNING_MESSAGE);
00072 isError=true;
00073 return;
00074
00075
00076 }
00077 }
00078 catch (NumberFormatException ex) {
00079 columnNumSet.setBackground(Color.pink);
00080
00081 JOptionPane.showMessageDialog(null, "errore di inserimento", "errore di inserimento", JOptionPane.WARNING_MESSAGE);
00082 invia.setVisible(false);
00083 isError=true;
00084 return ;
00085 }
00086
00087 int i;
00088
00089
00090
00091
00092 columnNumSet.setBackground(Color.white);
00093 for (i = 0; i < labels.length; i++) {
00094
00095
00096 labels[i] = new JLabel();
00097 labels[i].setText("Nome colonna");
00098
00099 labels[i].setBounds(new Rectangle(10, 40 + 25 * i, 90, 20));
00100 labels[i].setForeground(Color.black);
00101 textFields[i] = new JTextField();
00102 textFields[i].setBounds(new Rectangle(110, 40 + 25 * i, 70, 20));
00103 this.getContentPane().add(labels[i]);
00104 this.getContentPane().add(textFields[i]);
00105
00106 labelsValue[i] = new JLabel();
00107 labelsValue[i].setText("Valore colonna");
00108
00109 labelsValue[i].setBounds(new Rectangle(190, 40 + 25 * i, 90, 20));
00110 labelsValue[i].setForeground(Color.black);
00111 textFieldsValue[i] = new JTextField();
00112 textFieldsValue[i].setBounds(new Rectangle(300, 40 + 25 * i, 70, 20));
00113 this.getContentPane().add(labelsValue[i]);
00114 this.getContentPane().add(textFieldsValue[i]);
00115
00116
00117 }
00118 int height = 140 + num * 20;
00119 this.setSize(400, height);
00120 invia.setBounds(new Rectangle(150, 45 + 25 * i, 80, 20));
00121 invia.setBackground(Color.white);
00122 invia.setForeground(Color.gray);
00123 this.getContentPane().add(invia);
00124 this.getContentPane().add(errore);
00125
00126 invia.addMouseListener(new OptionPanelInsertUpdate_invia_mouseAdapter(this));
00127
00128
00129
00130
00131 }
00132
00133 void invia_mouseClicked(MouseEvent e) {
00134
00135 System.out.println("num="+labels.length+"\n");
00136 columns = new Column[labels.length];
00137 for (int i=0;i<labels.length;i++)
00138 {
00139 columns[i] = new Column(textFields[i].getText(),textFieldsValue[i].getText());
00140 System.out.println("column valore = "+ columns[i].getValue()+"column Nome = "+ columns[i].getName());
00141 }
00142 this.hide();
00143 }
00144 public boolean getIsError()
00145 {
00146 return isError;
00147 }
00148 public Column[] getColumns(){
00149 return columns;
00150 }
00151 }
00152
00153
00154 class OptionPanelInsertUpdate_invia_mouseAdapter extends java.awt.event.MouseAdapter {
00155 OptionPanelInsertUpdate adaptee;
00156
00157 OptionPanelInsertUpdate_invia_mouseAdapter(OptionPanelInsertUpdate adaptee) {
00158 this.adaptee = adaptee;
00159 }
00160 public void mouseClicked(MouseEvent e) {
00161 adaptee.invia_mouseClicked(e);
00162 }
00163 }