private void jButton1ActionPerformed(
      java.awt.event.ActionEvent evt) { // GEN-FIRST:event_jButton1ActionPerformed
    // TODO add your handling code here:

    try {
      Class.forName("com.mysql.jdbc.Driver");
      // System.out.println(" connection established");
      String url = "jdbc:mysql://localhost:3306/recommendedsystem";
      Connection con = DriverManager.getConnection(url, "root", "root");
      // System.out.println("conn built");
      Statement stmt = con.createStatement();
      ResultSet rs = stmt.executeQuery("select * from mobile_products");

      Vector v1 = new Vector();
      while (rs.next()) {

        Vector v = new Vector();
        String s = rs.getString(1);
        String s1 = rs.getString(3);
        String s2 = rs.getString(4);
        System.out.println(s);
        v.add(s);
        v.add(s1);
        v.add(s2);
        v1.addElement(v);
      }

      Vector columnNames = new Vector();
      columnNames.addElement("Product Name");
      columnNames.addElement("Functionality");
      columnNames.addElement("Descriptionality");
      JTable table = new JTable(v1, columnNames);
      // table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
      for (Object cName : columnNames) {
        //   table.getColumn(i).setMinWidth(50);
        table.getColumn((String) cName).setMinWidth(50);
      }

      //   JTable table=new JTable(v1,columnNames);
      JScrollPane jp = new JScrollPane(table);
      jp.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS);
      jp.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
      jp.setVisible(true);
      table.setVisible(true);
      //  jPanel2.setLayout(null);
      //     if(jPanel2.getComponents().length >0)
      //        jPanel2.removeAll();

      jPanel1.add(jp);

      jPanel1.setSize(400, 500);
      jPanel1.updateUI();
      jp.updateUI();
      update(this.getGraphics());
      jPanel1.setVisible(true);

    } catch (Exception e1) {
    }
  } // GEN-LAST:event_jButton1ActionPerformed
示例#2
0
 void init() {
   updateTableContent();
   table.setModel(myTable);
   table.setDefaultRenderer(JButton.class, new ComboBoxCellRenderer());
   JScrollPane scrollPane = new JScrollPane(table);
   setLayout(new BorderLayout());
   add(scrollPane, BorderLayout.CENTER);
   table.setVisible(true);
   addHandler();
 }
 public void detalle_oc(OrdenCompra cod) {
   // id=Integer.parseInt(tf_valor.getText());
   detalleOrdenCompraQuery = entityManager.createNamedQuery("DetalleOrdenCompra.findByCodOrden");
   detalleOrdenCompraQuery.setParameter("codOrden", cod);
   List<DetalleOrdenCompra> oc = detalleOrdenCompraQuery.getResultList();
   if (oc.isEmpty()) {
     JOptionPane.showMessageDialog(
         null, "Código de orden de compra inexistente", "Error", JOptionPane.ERROR_MESSAGE);
     tf_valor.setText(null);
     return;
   }
   detalleOrdenCompraList.clear();
   detalleOrdenCompraList.addAll(oc);
   masterTableDetalle.setVisible(true);
 }
示例#4
0
  /** Diese Methode sortiert alle Highscores und fuegt sie in die Tabelle ein. */
  public void sort() {
    Collections.sort(highscorelist);
    Vector<Object> tableContent = new Vector<Object>();
    for (Highscore hsc : highscorelist) {
      if (highscorelist.indexOf(hsc) < 25) {
        Vector<Object> line = new Vector<Object>();
        line.add(hsc.getName());
        line.add(hsc.getPoints());
        line.add(hsc.getNumOfRestCells());
        long tempSystem = hsc.getSystemtime();
        Date date = new Date(tempSystem);
        Format format = new SimpleDateFormat("dd.MM.yyyy HH:mm:ss");
        line.add(format.format(date));
        tableContent.add(line);
        lf.addHighscore(hsc, highscorelist.indexOf(hsc));
      }
    }

    Vector<String> titel = new Vector<String>();
    titel.add("Name");
    titel.add("Punkte");
    titel.add("Restzellen");
    titel.add("Erreicht");
    table1 = new JTable(tableContent, titel);

    table1.getColumn("Name").setPreferredWidth(200);
    table1.getColumn("Punkte").setPreferredWidth(100);
    table1.getColumn("Restzellen").setPreferredWidth(100);
    table1.getColumn("Erreicht").setPreferredWidth(200);
    table1.getTableHeader().setBackground(Color.lightGray);
    table1.setEnabled(false);

    DefaultTableCellRenderer centerRenderer = new DefaultTableCellRenderer();
    centerRenderer.setHorizontalAlignment(SwingConstants.RIGHT);
    for (int x = 0; x < table1.getColumnCount(); x++) {
      table1.getColumnModel().getColumn(x).setCellRenderer(centerRenderer);
      table1.getTableHeader().getColumnModel().getColumn(x).setCellRenderer(centerRenderer);
    }

    table1.setDefaultRenderer(String.class, centerRenderer);

    frame1.pack();
    frame1.setLocationRelativeTo(null);
    table1.setVisible(true);
    frame1.getContentPane().add(new JScrollPane(table1));
  }
  public CurrentBorrowList(Reader reader) {
    this.reader = reader;
    JTable jt = new JTable();
    jt.setSize(500, 200);
    DefaultTableModel dtm =
        new DefaultTableModel(new String[] {"bookid", "bookname", "readerid", "borrrowdate"}, 1);
    dtm.setRowCount(0);
    String[] arr = new String[4];
    arr[0] = "书号";
    arr[1] = "书名";
    arr[2] = "读者号";
    arr[3] = "借阅日期";

    dtm.addRow(arr);

    try {
      String sql =
          "select * from tb_borrowreturnrecord where readerid =  '"
              + reader.getRid()
              + "'and returndate IS NULL";
      ResultSet rs = SQLHelper.executeQuery(sql);
      while (rs.next()) {
        arr[0] = rs.getString("bookid");
        arr[1] = rs.getString("bookname");
        arr[2] = rs.getString("readerid");
        arr[3] = rs.getString("borrowdate");
        dtm.addRow(arr);
      }

    } catch (SQLException e) {
      // TODO: handle exception
      e.printStackTrace();
    }
    jt.setModel(dtm);
    jt.setVisible(true);
    jf.add(jt);
    jf.setTitle("当前借阅记录");
    jf.setSize(300, 200);
    jf.setVisible(true);
  }
  public AllReaderList() {
    JTable jt = new JTable();
    jt.setSize(500, 200);
    DefaultTableModel dtm =
        new DefaultTableModel(new String[] {"rid", "rname", "gender", "tel", "email"}, 1);
    dtm.setRowCount(0);
    String[] arr = new String[5];
    arr[0] = "读者ID";
    arr[1] = "姓名";
    arr[2] = "性别";
    arr[3] = "电话";
    arr[4] = "邮箱";

    dtm.addRow(arr);

    String sql;
    try {
      sql = "select * from tb_reader ";

      ResultSet rs = SQLHelper.executeQuery(sql);
      while (rs.next()) {
        arr[0] = rs.getString("rid");
        arr[1] = rs.getString("rname");
        arr[2] = rs.getString("gender");
        arr[3] = rs.getString("tel");
        arr[4] = rs.getString("email");
        dtm.addRow(arr);
      }

    } catch (SQLException e) {
      // TODO: handle exception
      e.printStackTrace();
    }
    jt.setModel(dtm);
    jt.setVisible(true);
    jf.add(jt);
    jf.setTitle("所有读者列表");
    jf.setSize(300, 200);
    jf.setVisible(true);
  }
  void tableInitialise(JTable table) {

    JScrollPane scroll;
    TableColumn column = null;

    int colunms = table.getColumnCount();
    for (int y = 0; y < colunms; y++) {
      column = table.getColumnModel().getColumn(y);
      /*将每一列的默认宽度设置为100*/
      column.setPreferredWidth(100);
    }
    /*
     * 设置JTable自动调整列表的状态,此处设置为关闭
     */
    table.setAutoResizeMode(JTable.AUTO_RESIZE_ALL_COLUMNS);

    table.setFont(new Font("Menu.font", Font.PLAIN, 14));
    table.getTableHeader().setFont(new Font("Menu.font", Font.BOLD, 15));
    /*用JScrollPane装载JTable,这样超出范围的列就可以通过滚动条来查看*/

    scroll = new JScrollPane(table);
    TablePanel.removeAll();

    TablePanel.setLayout(new BoxLayout(TablePanel, BoxLayout.Y_AXIS));
    TablePanel.add(scroll);

    TablePanel.revalidate();

    table.setRowSelectionAllowed(true); // 设置JTable可被选择
    table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); // 设置JTable为单行选择
    table.getTableHeader().setBackground(new Color(206, 231, 255)); // 设置JTable表头颜色
    table.getTableHeader().setReorderingAllowed(false); // 设置JTable每个字段的顺序不可以改变
    table.getTableHeader().setResizingAllowed(false); // 设置JTable每个表头的大小不可以改变
    makeFace(table); // 设置JTable 颜色

    table.setVisible(true);
  }
示例#8
0
  public JPanel init() {

    comp = new GridBagConstraints();
    this.setLayout(new GridBagLayout());

    table = new JTable(new CategoryTableModel());
    table.setVisible(true);

    scrollPane = new JScrollPane(table);
    table.setFillsViewportHeight(true);
    comp.gridx = 0;
    comp.gridy = 0;

    this.add(scrollPane, comp);

    JPanel buttons = new JPanel();
    GridBagConstraints com = new GridBagConstraints();
    buttons.setLayout(new GridBagLayout());

    addCategory = new JButton("Add new category");
    addCategory.addActionListener(this);
    com.gridx = 0;
    buttons.add(addCategory, com);

    removeCategory = new JButton("Remove selected category");
    removeCategory.addActionListener(this);
    com.gridx = 2;
    com.gridy = 0;
    buttons.add(removeCategory, com);

    comp.gridy = 2;
    this.add(buttons, comp);

    this.setSize(450, 450);
    return this;
  }
示例#9
0
  public static void main(String[] args) throws Exception {
    // assigning all variables needed prior to runtime
    Properties props = new Properties();
    FileInputStream _fin = new FileInputStream("properties.config");
    props.load(_fin);
    final String _host = props.getProperty("login.location");
    String _port = props.getProperty("login.location.port");
    final int _intport = Integer.parseInt(_port);
    _fin.close();

    Socket _socket = null;
    PrintWriter _pout = null;
    BufferedReader _bin = null;
    String s = null;
    ArrayList<String> _list = new ArrayList<String>();

    OmegaTableFrame _frame = new OmegaTableFrame();
    JScrollPane _scrollpane = new JScrollPane();
    OmegaTableModel _tablemodel = new OmegaTableModel(_list);
    JTable _table = new JTable(_tablemodel);
    _table.setVisible(true);
    _scrollpane.add(_table);
    _scrollpane.setVisible(true);
    _frame.add(_scrollpane);
    _frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    _frame.setVisible(true);

    FileInputStream fstream = new FileInputStream("loader_file.in");
    DataInputStream dinstream = new DataInputStream(fstream);
    BufferedReader br = new BufferedReader(new InputStreamReader(dinstream));
    while ((br.readLine() != null)) {
      System.out.println(br.readLine());
    }
    System.out.println("File ended.");
    dinstream.close();
  }
示例#10
0
  public storiconoleggio() {

    storico = new JFrame("Storico cliente:");
    storico.setDefaultCloseOperation(DISPOSE_ON_CLOSE);
    storico.setVisible(true);

    operazioni = new JPanel();
    operazioni.setLayout(new BoxLayout(operazioni, BoxLayout.Y_AXIS));

    sotto = new JPanel();

    gruppo = Box.createVerticalBox();

    indietro = new JButton("Indietro");

    ascoltatore = new listenernolcli();

    Object righe[][] = {
      {"# Noleggio", "ID Bagnino", "# Ombrellone", "Data Noleggio", "Num. Lettini", "ID Cliente"}
    };
    Object colonne[] = {"", "", "", "", "", ""};
    JTable tabella = new JTable(righe, colonne);

    try {
      String url = "jdbc:mysql://127.0.0.1:3306/lido";
      String userid = "root";
      String paswordd = "root";
      con = DriverManager.getConnection(url, userid, paswordd);
      requete = con.createStatement();
      rs =
          requete.executeQuery(
              "SELECT * FROM lido.bagnino_noleggia_ombrellone WHERE cliente_idcliente ="
                  + login.getNomeUtente());
      ResultSetMetaData md = rs.getMetaData();
      int columnCount = md.getColumnCount();

      Vector columns = new Vector(columnCount);

      for (int i = 1; i <= columnCount; i++) columns.add(md.getColumnName(i));
      Vector data = new Vector();
      Vector row;

      while (rs.next()) {
        row = new Vector(columnCount);
        for (int i = 1; i <= columnCount; i++) {
          row.add(rs.getString(i));
        }
        data.add(row);
      }
      table = new JTable(data, columns);
      table.setPreferredScrollableViewportSize(new Dimension(500, 70));
      table.setFillsViewportHeight(true);
      table.setVisible(true);
      table.validate();

    } catch (SQLException sqle) {

      System.out.println(sqle);
      sqle.printStackTrace();
    }

    indietro.addActionListener(ascoltatore);

    operazioni.add(tabella);
    operazioni.add(table);

    sotto.add(indietro);

    gruppo.add(operazioni);
    gruppo.add(sotto);
    storico.add(gruppo);
    storico.pack();
  }
  public RemoveTeacherTimetable() {
    frame = new JFrame("RemoveTeacherTimetable");
    frame.setContentPane(panel);
    frame.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
    frame.setVisible(true);
    tableView.setVisible(
        false); // hiding the unnecessary part before it is used, which makes the outlook more
                // pretty
    afterDeletion.setVisible(false);
    panelWidth = afterDeletion.getWidth() + 40;
    frame.pack();

    退出Button.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
            RemoveModule removeModule = new RemoveModule();
            frame.dispatchEvent(new WindowEvent(frame, WindowEvent.WINDOW_CLOSING));
          }
        });

    删除Button.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
            DefaultTableModel tableModel;
            tableModel = new DefaultTableModel();
            createTableModel(tableModel);
            tableView.setModel(tableModel);
            try {
              Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
            } catch (Exception ex) {
              ex.printStackTrace();
              JOptionPane.showMessageDialog(
                  null, "failed to load the driver function", "ERROR", JOptionPane.ERROR_MESSAGE);
            }
            try {
              Connection con =
                  DriverManager.getConnection(
                      Administrator.URL, Administrator.USER, Administrator.PASSWORD);
              Statement st = con.createStatement();
              String Ayear = ayear.getText();
              String Semester = semester.getText();
              String T_id = t_id.getText();
              String C_id = c_id.getText();
              String query =
                  "DELETE FROM tc WHERE Ayear = '"
                      + Ayear
                      + "' AND Semester = '"
                      + Semester
                      + "' AND T_id = '"
                      + T_id
                      + "' AND C_id = '"
                      + C_id
                      + "'";
              if (!Ayear.isEmpty() && !Semester.isEmpty() && !T_id.isEmpty() && !C_id.isEmpty())
                st.executeUpdate(query);

              ResultSet rs = st.executeQuery("SELECT * FROM tc");
              while (rs.next()) {
                Vector<java.io.Serializable> vcRows = new Vector<>();
                vcRows.addElement(rs.getString(1));
                vcRows.addElement(rs.getInt(2));
                vcRows.addElement(rs.getString(3));
                vcRows.addElement(rs.getString(4));
                vcRows.addElement(rs.getString(5));
                tableModel.addRow(vcRows);
              }
              rs.close();
              st.close();
              con.close();
              tableView.setAutoResizeMode(
                  JTable
                      .AUTO_RESIZE_ALL_COLUMNS); // adjust the panel according to the table's
                                                 // current height, and set them visible
              panelHeight = tableView.getRowHeight() * tableView.getRowCount() + 50;
              afterDeletion.setPreferredSize(new Dimension(panelWidth, panelHeight));
              afterDeletion.setVisible(true);
              tableView.setVisible(true);
              frame.pack();

            } catch (Exception ex) {
              ex.printStackTrace();
              JOptionPane.showMessageDialog(
                  null,
                  "failed to excute the SQL statement\n" + ex.getMessage(),
                  "ERROR",
                  JOptionPane.ERROR_MESSAGE);
            }
          }

          private void createTableModel(DefaultTableModel tableModel) {
            tableModel.addColumn("Ayear");
            tableModel.addColumn("Semester");
            tableModel.addColumn("T_id");
            tableModel.addColumn("C_id");
            tableModel.addColumn("Rating");
          }
        });
  }
示例#12
0
  public QueryTeacher() {
    frame = new JFrame("QueryTeacher");
    frame.setContentPane(panel);
    frame.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
    frame.setVisible(true);
    tableView.setVisible(false);
    afterInsert.setVisible(false);
    panelWidth = afterInsert.getWidth();
    frame.pack();

    退出Button.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
            new QueryModule();
            frame.dispatchEvent(new WindowEvent(frame, WindowEvent.WINDOW_CLOSING));
          }
        });

    查询Button.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
            DefaultTableModel tableModel = new DefaultTableModel();
            createTableModel(tableModel);
            tableView.setModel(tableModel);
            try {
              Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
            } catch (Exception ex) {
              ex.printStackTrace();
              JOptionPane.showMessageDialog(
                  null,
                  "failed to load the driver function/n" + ex.getMessage(),
                  "ERROR",
                  JOptionPane.ERROR_MESSAGE);
            }
            try {
              Connection con =
                  DriverManager.getConnection(
                      Administrator.URL, Administrator.USER, Administrator.PASSWORD);
              Statement st = con.createStatement();
              String T_id = t_id.getText();
              String T_name = t_name.getText();
              String T_sex = t_sex.getText();
              String T_birth = t_birth.getText();
              String T_prov = t_prov.getText();
              String T_region = t_region.getText();
              String Dept_id = dept_id.getText();
              String Col_id = col_id.getText();
              String Prof = prof.getText();
              String Sal = sal.getText();

              String query = "SELECT * FROM teacher where 1 = 1";
              if (!T_id.isEmpty() && T_id != "") query += "and T_id like '%" + T_id + "%'";
              if (!T_name.isEmpty() && T_name != "") query += "and T_name like '%" + T_name + "%'";
              if (!T_sex.isEmpty() && T_sex != "") query += "and T_sex like '%" + T_sex + "%'";
              if (!T_birth.isEmpty() && T_birth != "")
                query += "and T_birth like '%" + T_birth + "%'";
              if (!T_prov.isEmpty() && T_prov != "") query += "and T_prov like '%" + T_prov + "%'";
              if (!T_region.isEmpty() && T_region != "")
                query += "and T_region like '%" + T_region + "%'";
              if (!Dept_id.isEmpty() && Dept_id != "")
                query += "and Dept_id like '%" + Dept_id + "%'";
              if (!Col_id.isEmpty() && Col_id != "") query += "and Col_id like '%" + Col_id + "%'";
              if (!Prof.isEmpty() && Prof != "") query += "and Prof like '%" + Prof + "%'";
              if (!Sal.isEmpty() && Sal != "") query += "and Sal like '%" + Sal + "%'";

              ResultSet rs = st.executeQuery(query);
              while (rs.next()) {
                Vector<java.io.Serializable> vcRows = new Vector<>();
                vcRows.addElement(rs.getString(1));
                vcRows.addElement(rs.getString(2));
                vcRows.addElement(rs.getString(3));
                vcRows.addElement(rs.getDate(4));
                vcRows.addElement(rs.getString(5));
                vcRows.addElement(rs.getString(6));
                vcRows.addElement(rs.getString(7));
                vcRows.addElement(rs.getString(8));
                vcRows.addElement(rs.getString(9));
                vcRows.addElement(rs.getInt(10));
                tableModel.addRow(vcRows);
              }
              rs.close();
              st.close();
              con.close();
              tableView.setAutoResizeMode(
                  JTable
                      .AUTO_RESIZE_ALL_COLUMNS); // adjust the panel according to the table's
                                                 // current height, and set them visible
              panelHeight = tableView.getRowHeight() * tableView.getRowCount() + 50;
              afterInsert.setPreferredSize(new Dimension((int) (panelWidth * 1.4), panelHeight));
              afterInsert.setVisible(true);
              tableView.setVisible(true);
              frame.pack();

            } catch (Exception ex) {
              ex.printStackTrace();
              JOptionPane.showMessageDialog(
                  null,
                  "failed to excute the SQL statement\n" + ex.getMessage(),
                  "ERROR",
                  JOptionPane.ERROR_MESSAGE);
            }
          }

          private void createTableModel(DefaultTableModel tableModel) {
            tableModel.addColumn("T_id");
            tableModel.addColumn("T_name");
            tableModel.addColumn("T_sex");
            tableModel.addColumn("T_birth");
            tableModel.addColumn("T_prov");
            tableModel.addColumn("T_region");
            tableModel.addColumn("Dept_id");
            tableModel.addColumn("Col_id");
            tableModel.addColumn("Prof");
            tableModel.addColumn("Sal");
          }
        });
  }
示例#13
0
  /** Initialize the contents of the frame. */
  private void initialize() {
    frmWow = new JFrame();
    frmWow.setIconImage(
        Toolkit.getDefaultToolkit().getImage(Wow.class.getResource("/org/wowdoge/doge.png")));
    frmWow.addWindowListener(
        new WindowAdapter() {
          @Override
          public void windowOpened(WindowEvent arg0) {
            try {
              if (coreWallet.getWalletFilePath() == null) {
                DialogStart d = new DialogStart();
                d.setLocationRelativeTo(frmWow);
                if (d.showDialog()) {
                  String path = d.getWalletFilePath();
                  File f = new File(path);
                  coreWallet.run(f.getParentFile(), f.getName());
                  mnRecent.addFileToFileHistory(path);
                  mnRecent.storeToPreferences();
                } else {
                  System.exit(0);
                }
              } else coreWallet.run();
            } catch (Exception e) {
              JOptionPane.showMessageDialog(
                  null,
                  "Failed to open wallet.\nDetails:\n" + e.getMessage(),
                  "Error",
                  JOptionPane.ERROR_MESSAGE);
              try {
                coreWallet.stop();
              } finally {
                System.exit(1);
              }
              // Improve!
              // e.printStackTrace();
            }
          }

          @Override
          public void windowClosing(WindowEvent e) {
            try {
              coreWallet.stop();
            } catch (Exception e1) {
              JOptionPane.showMessageDialog(
                  null, e1.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);
            }
          }
        });
    frmWow.setTitle("Wow - Doge Wallet");
    frmWow.setBounds(100, 100, 819, 503);
    frmWow.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frmWow.getContentPane().setLayout(new BorderLayout(0, 0));

    tabbedPane = new JTabbedPane(JTabbedPane.TOP);
    frmWow.getContentPane().add(tabbedPane, BorderLayout.CENTER);

    JPanel panelWallet = new JPanel();
    tabbedPane.addTab("Wallet", null, panelWallet, null);
    panelWallet.setLayout(new BorderLayout(0, 0));

    JSplitPane splitPaneWallet = new JSplitPane();
    panelWallet.add(splitPaneWallet, BorderLayout.CENTER);

    JPanel panelAddresses = new JPanel();
    panelAddresses.setMinimumSize(new Dimension(200, 10));
    panelAddresses.setPreferredSize(new Dimension(280, 10));
    splitPaneWallet.setLeftComponent(panelAddresses);
    panelAddresses.setLayout(new BorderLayout(0, 0));

    JScrollPane scrollPaneAddresses = new JScrollPane();
    scrollPaneAddresses.setAutoscrolls(true);
    panelAddresses.add(scrollPaneAddresses, BorderLayout.CENTER);

    listAddresses = new JList();
    listAddresses.addListSelectionListener(
        new ListSelectionListener() {
          public void valueChanged(ListSelectionEvent arg0) {
            refreshAddressAndQRCode();
          }
        });
    scrollPaneAddresses.setViewportView(listAddresses);

    JToolBar toolBarAddresses = new JToolBar();
    panelAddresses.add(toolBarAddresses, BorderLayout.NORTH);

    JButton btnNewAddress = new JButton("New Address");
    btnNewAddress.setToolTipText("Create new wallet address for receiving coins");
    btnNewAddress.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent arg0) {
            coreWallet.createNewKeys(1);
            System.out.println(coreWallet.getKeys());
          }
        });
    btnNewAddress.setActionCommand("");
    toolBarAddresses.add(btnNewAddress);

    JButton btnNewAddresses = new JButton("Create Multiple");
    btnNewAddresses.setToolTipText("Create multiple wallet addresses for receiving coins");
    btnNewAddresses.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            DialogAddress dialog = new DialogAddress();
            dialog.setLocationRelativeTo(frmWow);
            if (dialog.showDialog()) {
              int number = dialog.getNumberOfAddressToCreate();
              coreWallet.createNewKeys(number);
              System.out.println(coreWallet.getKeys());
            }
          }
        });
    toolBarAddresses.add(btnNewAddresses);

    JSplitPane splitPaneAddressAndTransactoions = new JSplitPane();
    splitPaneAddressAndTransactoions.setOrientation(JSplitPane.VERTICAL_SPLIT);
    splitPaneWallet.setRightComponent(splitPaneAddressAndTransactoions);

    JPanel panelAddress = new JPanel();
    panelAddress.setPreferredSize(new Dimension(10, 100));
    splitPaneAddressAndTransactoions.setLeftComponent(panelAddress);
    panelAddress.setLayout(new BorderLayout(0, 0));

    JPanel panelDogeQRMain = new JPanel();
    panelDogeQRMain.setPreferredSize(new Dimension(240, 120));
    panelAddress.add(panelDogeQRMain, BorderLayout.CENTER);
    panelDogeQRMain.setLayout(new BorderLayout(0, 0));

    JPanel panelDogeQR = new JPanel();
    panelDogeQRMain.add(panelDogeQR);

    btnDoge = new JButton("");
    btnDoge.addComponentListener(
        new ComponentAdapter() {
          @Override
          public void componentResized(ComponentEvent e) {
            int min =
                btnDoge.getWidth() > btnDoge.getHeight() ? btnDoge.getHeight() : btnDoge.getWidth();
            min = (int) (min * 0.9);
            // System.out.println("RESIZED");
            btnDoge.setIcon(
                new ImageIcon(
                    new ImageIcon(Wow.class.getResource("/org/wowdoge/doge.png"))
                        .getImage()
                        .getScaledInstance(min, min, Image.SCALE_SMOOTH)));
          }
        });
    btnDoge.setToolTipText("Send payment");
    btnDoge.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent arg0) {
            tabbedPane.setSelectedComponent(panelAddressBook);
          }
        });
    panelDogeQR.setLayout(new GridLayout(0, 2, 0, 0));
    panelDogeQR.add(btnDoge);
    btnDoge.setIcon(new ImageIcon(Wow.class.getResource("/org/wowdoge/doge.png")));
    btnDoge.setSize(new Dimension(500, 500));
    btnDoge.setAlignmentX(Component.CENTER_ALIGNMENT);
    btnDoge.setMaximumSize(new Dimension(500, 500));
    btnDoge.setMinimumSize(new Dimension(120, 120));
    btnDoge.setPreferredSize(new Dimension(200, 200));

    btnQRCode = new JButton("");
    btnQRCode.addComponentListener(
        new ComponentAdapter() {
          @Override
          public void componentResized(ComponentEvent arg0) {
            String address = (String) listAddresses.getSelectedValue();
            // System.out.println("Addres:" + address);
            if (address != null) {
              txtAddress.setText(address);
              btnQRCode.setIcon(
                  new ImageIcon(new QRImage(address, btnQRCode.getWidth(), btnQRCode.getHeight())));
            }
          }
        });
    btnQRCode.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent arg0) {}
        });
    btnQRCode.setToolTipText("Request payment");
    panelDogeQR.add(btnQRCode);
    btnQRCode.setSize(new Dimension(120, 120));
    btnQRCode.setAlignmentX(Component.CENTER_ALIGNMENT);
    btnQRCode.setMinimumSize(new Dimension(120, 120));
    btnQRCode.setMaximumSize(new Dimension(500, 500));
    btnQRCode.setPreferredSize(new Dimension(200, 200));

    JPanel panelAddressNameBalance = new JPanel();
    panelAddress.add(panelAddressNameBalance, BorderLayout.NORTH);
    panelAddressNameBalance.setLayout(new BoxLayout(panelAddressNameBalance, BoxLayout.Y_AXIS));

    JLabel lblReceivingAddress = new JLabel(" Receiving Address:");
    lblReceivingAddress.setPreferredSize(new Dimension(59, 30));
    lblReceivingAddress.setAlignmentX(Component.CENTER_ALIGNMENT);
    panelAddressNameBalance.add(lblReceivingAddress);

    JPanel panel_1 = new JPanel();
    panelAddressNameBalance.add(panel_1);
    panel_1.setLayout(new BoxLayout(panel_1, BoxLayout.X_AXIS));

    txtAddress = new JTextField();
    txtAddress.setPreferredSize(new Dimension(14, 30));
    panel_1.add(txtAddress);
    txtAddress.setFont(new Font("Lucida Grande", Font.PLAIN, 18));
    txtAddress.setHorizontalAlignment(SwingConstants.CENTER);
    txtAddress.setBackground(SystemColor.window);
    txtAddress.setEditable(false);
    txtAddress.setColumns(10);

    JPanel panel_2 = new JPanel();
    panel_2.setVisible(false);
    panelAddressNameBalance.add(panel_2);
    panel_2.setLayout(new BoxLayout(panel_2, BoxLayout.X_AXIS));

    JLabel lblDescription = new JLabel(" Name:");
    lblDescription.setPreferredSize(new Dimension(55, 16));
    panel_2.add(lblDescription);

    txtName = new JTextField();
    panel_2.add(txtName);
    txtName.setFont(new Font("Lucida Grande", Font.PLAIN, 16));
    txtName.setText("Donation");
    txtName.setHorizontalAlignment(SwingConstants.CENTER);
    txtName.setBackground(Color.WHITE);
    txtName.setColumns(10);

    JPanel panel_3 = new JPanel();
    panel_3.setVisible(false);
    panelAddressNameBalance.add(panel_3);
    panel_3.setLayout(new BoxLayout(panel_3, BoxLayout.X_AXIS));

    JLabel lblBalance = new JLabel(" Balance:");
    lblBalance.setPreferredSize(new Dimension(55, 16));
    panel_3.add(lblBalance);

    txtBalance = new JTextField();
    panel_3.add(txtBalance);
    txtBalance.setFont(new Font("Lucida Grande", Font.PLAIN, 15));
    txtBalance.setText("NA");
    txtBalance.setHorizontalAlignment(SwingConstants.CENTER);
    txtBalance.setBackground(SystemColor.window);
    txtBalance.setEditable(false);
    txtBalance.setColumns(10);

    JLabel lblDoge = new JLabel("DOGE");
    lblDoge.setPreferredSize(new Dimension(40, 16));
    panel_3.add(lblDoge);

    JPanel panelReceivedSent = new JPanel();
    panelReceivedSent.setVisible(false);
    panelAddress.add(panelReceivedSent, BorderLayout.SOUTH);
    panelReceivedSent.setLayout(new GridLayout(0, 1, 0, 0));

    JPanel panelReceived = new JPanel();
    panelReceivedSent.add(panelReceived);
    panelReceived.setLayout(new FlowLayout(FlowLayout.CENTER, 5, 5));

    JLabel labelReceived = new JLabel("Received:");
    labelReceived.setHorizontalAlignment(SwingConstants.CENTER);
    labelReceived.setFont(new Font("Lucida Grande", Font.PLAIN, 13));
    panelReceived.add(labelReceived);

    txtReceived = new JTextField();
    txtReceived.setText("NA");
    txtReceived.setHorizontalAlignment(SwingConstants.CENTER);
    txtReceived.setFont(new Font("Lucida Grande", Font.PLAIN, 13));
    txtReceived.setEditable(false);
    txtReceived.setColumns(10);
    txtReceived.setBackground(SystemColor.window);
    panelReceived.add(txtReceived);

    JLabel lblDogeReceived = new JLabel("DOGE");
    panelReceived.add(lblDogeReceived);

    JPanel panelSent = new JPanel();
    panelReceivedSent.add(panelSent);
    panelSent.setLayout(new FlowLayout(FlowLayout.CENTER, 5, 5));

    JLabel labelSent = new JLabel("Sent:");
    labelSent.setPreferredSize(new Dimension(59, 16));
    labelSent.setHorizontalAlignment(SwingConstants.CENTER);
    labelSent.setFont(new Font("Lucida Grande", Font.PLAIN, 13));
    panelSent.add(labelSent);

    txtSent = new JTextField();
    txtSent.setText("NA");
    txtSent.setHorizontalAlignment(SwingConstants.CENTER);
    txtSent.setFont(new Font("Lucida Grande", Font.PLAIN, 13));
    txtSent.setEditable(false);
    txtSent.setColumns(10);
    txtSent.setBackground(SystemColor.window);
    panelSent.add(txtSent);

    JLabel lblDogeSent = new JLabel("DOGE");
    panelSent.add(lblDogeSent);

    JTable tableAddressTransactions = new JTable();
    tableAddressTransactions.setVisible(false);
    splitPaneAddressAndTransactoions.setRightComponent(tableAddressTransactions);

    panelTransactions = new JPanel();
    tabbedPane.addTab("Transactions", null, panelTransactions, null);
    panelTransactions.setLayout(new BorderLayout(0, 0));

    JScrollPane scrollPane = new JScrollPane();
    scrollPane.setAutoscrolls(true);
    panelTransactions.add(scrollPane, BorderLayout.CENTER);

    tableTransactions = new JTable();
    tableTransactions.setRowHeight(30);
    tableTransactions.setAutoscrolls(true);
    tableTransactions.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
    tableTransactions.setAutoResizeMode(JTable.AUTO_RESIZE_ALL_COLUMNS);
    scrollPane.setViewportView(tableTransactions);

    panelAddressBook = new JPanel();
    tabbedPane.addTab("Address Book", null, panelAddressBook, null);
    panelAddressBook.setLayout(new BorderLayout(0, 0));

    JScrollPane scrollPaneAddressBook = new JScrollPane();
    panelAddressBook.add(scrollPaneAddressBook, BorderLayout.CENTER);

    tableAddressBook = new JTable();
    tableAddressBook.addMouseListener(
        new MouseAdapter() {
          @Override
          public void mouseClicked(MouseEvent arg0) {
            if (arg0.getClickCount() == 2) {
              JTable target = (JTable) arg0.getSource();
              int row = target.getSelectedRow();
              // int column = target.getSelectedColumn();
              if (row != -1) {
                Contact c = addressBookTableModel.getAddressBook().getContacts().get(row);
                send(c.getAddress(), c.getAmount());
              }
            }
          }
        });
    tableAddressBook.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    tableAddressBook.setRowHeight(25);
    scrollPaneAddressBook.setViewportView(tableAddressBook);

    JToolBar toolBarAddressbook = new JToolBar();
    panelAddressBook.add(toolBarAddressbook, BorderLayout.NORTH);

    JButton btnNewRecipient = new JButton("New");
    btnNewRecipient.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent arg0) {
            DialogContact d = new DialogContact();
            d.setLocationRelativeTo(frmWow);
            d.edit(false);
            d.setNetworkParameters(coreWallet.getNetworkParameters());
            if (d.showDialog()) {
              Contact c =
                  new Contact(d.getName(), d.getAddress(), d.getDescription(), d.getAmount());
              addressBookTableModel.getAddressBook().addContact(c);
              addressBookTableModel.getAddressBook().sort();

              try {
                addressBookTableModel.getAddressBook().save();
              } catch (IOException e1) {
                e1.printStackTrace();
                JOptionPane.showMessageDialog(
                    frmWow,
                    e1.getMessage(),
                    "Error During Address Book Save",
                    JOptionPane.ERROR_MESSAGE);
              } catch (ClassNotFoundException e1) {
                e1.printStackTrace();
                JOptionPane.showMessageDialog(
                    frmWow,
                    e1.getMessage(),
                    "Error During Address Book Save",
                    JOptionPane.ERROR_MESSAGE);
              } catch (BackingStoreException e1) {
                e1.printStackTrace();
                JOptionPane.showMessageDialog(
                    frmWow,
                    e1.getMessage(),
                    "Error During Address Book Save",
                    JOptionPane.ERROR_MESSAGE);
              }
              addressBookTableModel.fireTableDataChanged();
            }
          }
        });
    btnNewRecipient.setToolTipText("New address template to send payments to");
    toolBarAddressbook.add(btnNewRecipient);

    JButton btnEdit = new JButton("Edit");
    btnEdit.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            DialogContact d = new DialogContact();
            d.setLocationRelativeTo(frmWow);
            d.edit(true);
            int index = tableAddressBook.getSelectedRow();
            if (index != -1) {
              d.setNetworkParameters(coreWallet.getNetworkParameters());
              Contact c = addressBookTableModel.getAddressBook().getContacts().get(index);
              d.setName(c.getName());
              d.setAddress(c.getAddress());
              d.setDescription(c.getDescription());
              d.setAmount(c.getAmount());
              if (d.showDialog()) {
                c.setName(d.getName());
                c.setAddress(d.getAddress());
                c.setDescription(d.getDescription());
                c.setAmount(d.getAmount());
                addressBookTableModel.getAddressBook().sort();
                try {
                  addressBookTableModel.getAddressBook().save();
                } catch (IOException e1) {
                  e1.printStackTrace();
                  JOptionPane.showMessageDialog(
                      frmWow,
                      e1.getMessage(),
                      "Error During Address Book Save",
                      JOptionPane.ERROR_MESSAGE);
                } catch (ClassNotFoundException e1) {
                  e1.printStackTrace();
                  JOptionPane.showMessageDialog(
                      frmWow,
                      e1.getMessage(),
                      "Error During Address Book Save",
                      JOptionPane.ERROR_MESSAGE);
                } catch (BackingStoreException e1) {
                  e1.printStackTrace();
                  JOptionPane.showMessageDialog(
                      frmWow,
                      e1.getMessage(),
                      "Error During Address Book Save",
                      JOptionPane.ERROR_MESSAGE);
                }
                addressBookTableModel.fireTableDataChanged();
              }
            }
          }
        });
    btnEdit.setToolTipText("Edit address template");
    toolBarAddressbook.add(btnEdit);

    JButton btnDelete = new JButton("Delete");
    btnDelete.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent arg0) {
            int index = tableAddressBook.getSelectedRow();
            if (index != -1) {
              Contact c = addressBookTableModel.getAddressBook().getContacts().get(index);
              if (JOptionPane.showConfirmDialog(
                      frmWow,
                      "Do you really want to delete Address Template?\nName: "
                          + c.getName()
                          + "\nAddress: "
                          + c.getAddress()
                          + "\nDescription: "
                          + c.getDescription()
                          + "\nAmount: "
                          + c.getAmount(),
                      "Confirm Deletion",
                      JOptionPane.YES_NO_OPTION,
                      JOptionPane.QUESTION_MESSAGE)
                  == JOptionPane.YES_OPTION) {
                addressBookTableModel.getAddressBook().getContacts().remove(c);
                try {
                  addressBookTableModel.getAddressBook().save();
                } catch (IOException e1) {
                  e1.printStackTrace();
                  JOptionPane.showMessageDialog(
                      frmWow,
                      e1.getMessage(),
                      "Error During Address Book Save",
                      JOptionPane.ERROR_MESSAGE);
                } catch (ClassNotFoundException e1) {
                  e1.printStackTrace();
                  JOptionPane.showMessageDialog(
                      frmWow,
                      e1.getMessage(),
                      "Error During Address Book Save",
                      JOptionPane.ERROR_MESSAGE);
                } catch (BackingStoreException e1) {
                  e1.printStackTrace();
                  JOptionPane.showMessageDialog(
                      frmWow,
                      e1.getMessage(),
                      "Error During Address Book Save",
                      JOptionPane.ERROR_MESSAGE);
                }
                addressBookTableModel.fireTableDataChanged();
              }
            }
          }
        });
    btnDelete.setToolTipText("Delete address template");
    toolBarAddressbook.add(btnDelete);

    JButton btnSend = new JButton("Send");
    btnSend.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent arg0) {
            int row = tableAddressBook.getSelectedRow();
            if (row != -1) {
              Contact c = addressBookTableModel.getAddressBook().getContacts().get(row);
              send(c.getAddress(), c.getAmount());
            }
          }
        });
    btnSend.setFont(new Font("Lucida Grande", Font.PLAIN, 13));
    btnSend.setToolTipText("Send payment to address template");
    toolBarAddressbook.add(btnSend);

    Component horizontalGlue = Box.createHorizontalGlue();
    toolBarAddressbook.add(horizontalGlue);

    JButton btnSendToAddress = new JButton("Send to Address");
    btnSendToAddress.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent arg0) {
            send(null, 0);
          }
        });
    btnSendToAddress.setToolTipText("Send payment to specified address");
    btnSendToAddress.setFont(new Font("Lucida Grande", Font.PLAIN, 14));
    toolBarAddressbook.add(btnSendToAddress);

    Component horizontalGlue_1 = Box.createHorizontalGlue();
    toolBarAddressbook.add(horizontalGlue_1);

    Component horizontalStrut = Box.createHorizontalStrut(20);
    horizontalStrut.setPreferredSize(new Dimension(110, 0));
    toolBarAddressbook.add(horizontalStrut);

    JToolBar toolBarTotal = new JToolBar();
    frmWow.getContentPane().add(toolBarTotal, BorderLayout.NORTH);

    tglbtnLock = new JToggleButton("Not Encrypted");
    tglbtnLock.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent arg0) {
            if (coreWallet.isEncrypted()) {
              DialogPassword d = new DialogPassword();
              d.setLocationRelativeTo(frmWow);
              if (d.showDialog()) {
                try {
                  coreWallet.decrypt(new String(d.getPassword()));
                } catch (KeyCrypterException e) {
                  e.printStackTrace();
                  JOptionPane.showMessageDialog(
                      frmWow, "Wallet dencryption failed!", "Error", JOptionPane.ERROR_MESSAGE);
                }
              }
            } else {
              DialogEncrypt d = new DialogEncrypt();
              d.setLocationRelativeTo(frmWow);
              if (d.showDialog()) {
                // System.out.println("NAZDAR");
                // System.out.println(d.getPassword());
                try {
                  coreWallet.encrypt(new String(d.getPassword()));
                } catch (Exception e) { // KeyCrypterException
                  e.printStackTrace();
                  JOptionPane.showMessageDialog(
                      frmWow, "Wallet encryption failed!\n", "Error", JOptionPane.ERROR_MESSAGE);
                }
              }
            }
            updateEncryptionState();
          }
        });
    toolBarTotal.add(tglbtnLock);
    tglbtnLock.setToolTipText("Wallet not encrypted");

    JLabel lblTotal = new JLabel("Balance:");
    lblTotal.setFont(new Font("Lucida Grande", Font.PLAIN, 23));
    toolBarTotal.add(lblTotal);

    textTotalBalance = new JTextField();
    textTotalBalance.setPreferredSize(new Dimension(250, 28));
    textTotalBalance.setFont(new Font("Lucida Grande", Font.PLAIN, 23));
    textTotalBalance.setHorizontalAlignment(SwingConstants.CENTER);
    textTotalBalance.setBackground(SystemColor.window);
    textTotalBalance.setEditable(false);
    toolBarTotal.add(textTotalBalance);
    textTotalBalance.setColumns(10);

    JLabel lblTotalDoge = new JLabel("DOGE ");
    lblTotalDoge.setFont(new Font("Lucida Grande", Font.PLAIN, 23));
    toolBarTotal.add(lblTotalDoge);

    JToolBar toolBarStatus = new JToolBar();
    frmWow.getContentPane().add(toolBarStatus, BorderLayout.SOUTH);

    lblStatus = new JLabel(" Connecting...    ");
    toolBarStatus.add(lblStatus);

    progressBarStatus = new JProgressBar();
    progressBarStatus.setPreferredSize(new Dimension(250, 20));
    toolBarStatus.add(progressBarStatus);

    JLabel label = new JLabel("    ");
    toolBarStatus.add(label);
  }
示例#14
0
  public UpdateUsercode() {
    frame = new JFrame("UpdateUsercode");
    frame.setContentPane(panel);
    frame.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
    frame.setVisible(true);
    tableView.setVisible(
        false); // hiding the unnecessary part before it is used, which makes the outlook more
                // pretty
    afterUpdate.setVisible(false);
    panelWidth = afterUpdate.getWidth() + 40;
    frame.pack();

    退出Button.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
            frame.dispatchEvent(new WindowEvent(frame, WindowEvent.WINDOW_CLOSING));
          }
        });
    更改Button.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
            DefaultTableModel tableModel = new DefaultTableModel();
            createTableModel(tableModel);
            tableView.setModel(tableModel);
            try {
              Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
            } catch (Exception ex) {
              ex.printStackTrace();
              JOptionPane.showMessageDialog(
                  null, "failed to load the driver function", "ERROR", JOptionPane.ERROR_MESSAGE);
            }
            try {
              Connection con =
                  DriverManager.getConnection(
                      Administrator.URL, Administrator.USER, Administrator.PASSWORD);
              Statement st = con.createStatement();
              String old_U_id = old_u_id.getText();
              String U_id = u_id.getText();
              String U_name = u_name.getText();
              String Password = password.getText();
              String Privilege = privilege.getText();
              String query =
                  "UPDATE usercode SET U_id = '"
                      + U_id
                      + "', U_name = '"
                      + U_name
                      + "', Password = '******', Privilege = '"
                      + Privilege
                      + "' WHERE U_id = '"
                      + old_U_id
                      + "'";
              if (!old_U_id.isEmpty()
                  && !U_id.isEmpty()
                  && !U_name.isEmpty()
                  && !Password.isEmpty()
                  && !Privilege.isEmpty()) st.executeUpdate(query);

              ResultSet rs = st.executeQuery("SELECT * FROM usercode");
              while (rs.next()) {
                Vector<String> vcRows = new Vector<>();
                vcRows.addElement(rs.getString(1));
                vcRows.addElement(rs.getString(2));
                vcRows.addElement(rs.getString(3));
                vcRows.addElement(rs.getString(4));
                tableModel.addRow(vcRows);
              }
              rs.close();
              st.close();
              con.close();
              tableView.setAutoResizeMode(
                  JTable
                      .AUTO_RESIZE_ALL_COLUMNS); // adjust the panel according to the table's
                                                 // current height, and set them visible
              panelHeight = tableView.getRowHeight() * tableView.getRowCount() + 50;
              afterUpdate.setPreferredSize(new Dimension(panelWidth, panelHeight));
              afterUpdate.setVisible(true);
              tableView.setVisible(true);
              frame.pack();

            } catch (Exception ex) {
              ex.printStackTrace();
              JOptionPane.showMessageDialog(
                  null,
                  "failed to excute the SQL statement\n" + ex.getMessage(),
                  "ERROR",
                  JOptionPane.ERROR_MESSAGE);
            }
          }

          private void createTableModel(DefaultTableModel tableModel) {
            tableModel.addColumn("U_id");
            tableModel.addColumn("U_name");
            tableModel.addColumn("Password");
            tableModel.addColumn("Privilege");
          }
        });
  }
示例#15
0
  private void updateTable() {
    dataExchange.transferString("updateTable");
    listProduct = new ArrayList<ProductEntity>();
    int size = dataExchange.acceptInt();

    for (int i = 0; i < size; i++) {
      listProduct.add(dataExchange.acceptProductEntity());
    }

    listGroup = new ArrayList<GroupEntity>();
    size = dataExchange.acceptInt();

    for (int i = 0; i < size; i++) {
      listGroup.add(dataExchange.acceptGroupEntity());
    }

    listSubGroup = new ArrayList<SubGroupEntity>();
    size = dataExchange.acceptInt();

    for (int i = 0; i < size; i++) {
      listSubGroup.add(dataExchange.acceptSubGroupEntity());
    }

    listProductTable = new ArrayList<ProductTableEntity>();

    for (int i = 0; i < listProduct.size(); i++) {
      ProductTableEntity entity = new ProductTableEntity();

      for (int j = 0; j < listGroup.size(); j++) {

        if (listProduct.get(i).getGroupId() == listGroup.get(j).getGroupId()) {
          entity.setGroupName(listGroup.get(j).getGroupName());
          break;
        }
      }

      for (int j = 0; j < listSubGroup.size(); j++) {

        if (listProduct.get(i).getSubGroupId() == listSubGroup.get(j).getSubGroupId()) {
          entity.setSubGroupName(listSubGroup.get(j).getSubGroupName());
          break;
        }
      }
      entity.setProductId(i + 1);
      entity.setProductName(listProduct.get(i).getProductName());
      entity.setAmount(listProduct.get(i).getAmount());
      entity.setPrice(listProduct.get(i).getPrice());
      listProductTable.add(entity);
    }
    productTableModel.removeIsAll();

    for (int i = 0; i < listProductTable.size(); i++) {
      String[] table = {
        String.valueOf(listProductTable.get(i).getProductId()),
        listProductTable.get(i).getProductName(),
        listProductTable.get(i).getGroupName(),
        listProductTable.get(i).getSubGroupName(),
        String.valueOf(listProductTable.get(i).getAmount()),
        String.valueOf(listProductTable.get(i).getPrice())
      };
      productTableModel.addDate(table);
    }
    table.setVisible(false);
    table.setVisible(true);
  }
示例#16
0
  public TablePanel() {
    this.tableModel = new BetTableModel();
    this.table = new JTable(tableModel);
    popup = new JPopupMenu();

    table.setDefaultEditor(BookMaker.class, new BookMakerEditor());
    table.setDefaultRenderer(BookMaker.class, new BookMakerRenderer());
    table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
    table.setRowHeight(25);

    JMenuItem removeItem = new JMenuItem("Delete bet");
    popup.add(removeItem);

    table.addMouseListener(
        new MouseAdapter() {
          public void mousePressed(MouseEvent e) {

            int row = table.rowAtPoint(e.getPoint());

            table.getSelectionModel().setSelectionInterval(row, row);

            if (e.getButton() == MouseEvent.BUTTON3) {
              popup.show(table, e.getX(), e.getY());
            }
          }
        });

    TableColumn col = null;
    int width = 0;
    for (int i = 0; i < tableModel.getColumnCount(); i++) {
      col = table.getColumnModel().getColumn(i);
      switch (i) {
        case 0:
          width = 50;
          break;
        case 1:
          width = 114;
          break;
        case 2:
          width = 40;
          break;
        case 3:
          width = 50;
          break;
        case 4:
          width = 50;
          break;
        case 5:
          width = 40;
          break;
        case 6:
          width = 70;
          break;
        case 7:
          width = 85;
          break;
        default:
          width = 75;
          break;
      }
      col.setPreferredWidth(width);
    }

    removeItem.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent arg0) {
            int row = table.getSelectedRow();

            if (betTableListener != null) {
              betTableListener.rowDeleted(row);
              tableModel.fireTableRowsDeleted(row, row);
            }
          }
        });

    table.setVisible(true);
    setLayout(new BorderLayout());
    setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
    this.setSize(1000, this.getHeight());
    add(new JScrollPane(table), BorderLayout.CENTER);
  }
  @SuppressWarnings({"unchecked", "rawtypes"})
  public InterfaceTrans() {

    setTitle("Pantalla Principal");
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    setSize(1280, 720); // Tamaño
    setLocationRelativeTo(null); // Centrar ventana

    // donde se ejecute el programa
    setResizable(true);
    setVisible(true);

    // Quito la visibilidad de los elementos del padre que no necesito
    super.contentPane.setVisible(false); // para que se vea mi Panel en vez
    // del gris heredado
    super.menu2.setVisible(false);
    super.tb1.setVisible(false);

    // Añado a la barra los elementos que si necesito

    abrir = new JMenuItem("Abrir...   Alt+B");
    abrir.setMnemonic('B');
    abrir.setIcon(new ImageIcon(InterfaceTrans.class.getResource(""))); // ""
    // para
    // colocar
    // un
    // icono
    abrir.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent ae) {
            try {
              InterfaceTrans.archivotrans();
            } catch (Throwable e) {
              e.printStackTrace();
            }
          }
        });
    super.menu1.add(abrir);

    // -------------- Tabla ----------------------------------------------
    // -------------------------------------------------------------------

    tabla = new JTable();

    // ARRAY QUE CAPTURA EL CONTENIDO
    contenido = new Object[Tablas.transporte.size()][6];
    int contador = 0;
    for (Entry<Integer, Transporte> entrada : Tablas.transporte.entrySet()) {
      contenido[contador][0] = entrada.getValue().getId();
      contenido[contador][1] = entrada.getValue().getIdCliente();
      contenido[contador][2] = entrada.getValue().getIdProducto();
      contenido[contador][3] = entrada.getValue().isTipoViaje();
      contenido[contador][4] = entrada.getValue().getFechaEntrega();
      contenido[contador][5] = entrada.getValue().getFechaRecogida();
      contador++;
    }

    ModeloTablaTrans =
        new DefaultTableModel(contenido, columnas) {
          private static final long serialVersionUID = 1L;

          public boolean isCellEditable(int rowIndex, int columnIndex) {
            return false;
          }
        };
    // -----

    // COJEMO EL MODELO DE LA TABLA
    tabla = new JTable(ModeloTablaTrans);
    tabla.setShowVerticalLines(true);
    tabla.setShowHorizontalLines(true);
    tabla.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); // SELECCION SENCILLA
    tabla.setVisible(true);

    sp = new JScrollPane(tabla); // Necesita un Scroll para que se vean las  columnas
    sp.setBounds(608, 182, 616, 337);

    // -------A partir de aqui el tabbedPaned-------------------

    separador = new JTabbedPane();
    panel1 = new JPanel();
    panel1.setBackground(Color.LIGHT_GRAY); // asi le damos color al panel
    panel1.setLayout(null);
    lblId_Transporte = new JLabel("N\u00BA Transporte:");
    lblId_Transporte.setFont(new Font("Arial", Font.BOLD, 13));
    lblId_Cliente = new JLabel("ID Cliente:");
    lblId_Cliente.setFont(new Font("Arial", Font.BOLD, 13));
    lblId_Producto = new JLabel("ID Producto:");
    lblId_Producto.setFont(new Font("Arial", Font.BOLD, 13));
    lblTipo_Viaje = new JLabel("Tipo Viaje:");
    lblTipo_Viaje.setFont(new Font("Arial", Font.BOLD, 13));
    lblFechaEnvio = new JLabel("Fecha Envio:");
    lblFechaEnvio.setFont(new Font("Arial", Font.BOLD, 13));
    lblFechaRecepcion = new JLabel("Fecha Rcogida:");
    lblFechaRecepcion.setFont(new Font("Arial", Font.BOLD, 13));

    // ----------cajas de texto ----------------

    cajaId_Transporte = new JTextField();
    cajaId_Transporte.setEnabled(false);
    cajaId_Cliente = new JTextField();
    cajaId_Producto = new JTextField();
    cajaTipo_Viaje = new JTextField();

    // --------botones-------------------

    guardar = new JButton("Guardar");
    guardar.addActionListener(
        new ActionListener() {

          public void actionPerformed(ActionEvent e) {

            Transporte t = new Transporte();
            Disparador d = new Disparador("idTransporte");
            SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy");
            if (t.insertar(
                    d.nextValue(),
                    Integer.parseInt(cajaId_Cliente.getText()),
                    Integer.parseInt(cajaId_Producto.getText()),
                    cajaTipo_Viaje.getText(),
                    sdf.format(dateEnvio.getCalendar().getTime()),
                    sdf.format(dateRecep.getCalendar().getTime()))
                == true) {
              JOptionPane.showMessageDialog(
                  null, "El registro " + d.insert() + " se ha insertado correctamente");
            }
          }
        });

    borrar = new JButton("LIMPIAR REGISTRO");
    borrar.addActionListener(
        new ActionListener() {

          public void actionPerformed(ActionEvent e) { // usado para dejar las vacías

            cajaId_Transporte.setText(null);
            cajaId_Cliente.setText(null);
            cajaId_Producto.setText(null);
            cajaTipo_Viaje.setText(null);
            dateRecep.setCalendar(null); // vaciamos la caja del calendario
            dateEnvio.setCalendar(null); // vaciamos la caja del calendario
          }
        });
    lblId_Transporte.setBounds(73, 181, 187, 28);
    lblId_Cliente.setBounds(73, 220, 187, 30);
    lblId_Producto.setBounds(73, 261, 187, 30);
    lblTipo_Viaje.setBounds(73, 302, 187, 30);
    lblFechaEnvio.setBounds(73, 343, 187, 28);
    lblFechaRecepcion.setBounds(73, 382, 187, 30);

    // ----------Cajas-------------

    cajaId_Transporte.setBounds(270, 179, 124, 30);
    cajaId_Cliente.setBounds(270, 221, 250, 30);
    cajaId_Producto.setBounds(270, 262, 250, 30);
    cajaTipo_Viaje.setBounds(270, 302, 85, 30);

    // ----------Botones-------------

    guardar.setBounds(270, 423, 85, 30);
    borrar.setBounds(384, 423, 136, 30);

    dateRecep.setBounds(270, 382, 250, 30);
    panel1.add(sp);

    panel1.add(guardar);
    panel1.add(borrar);
    panel1.add(lblId_Transporte);
    panel1.add(lblId_Cliente);
    panel1.add(lblId_Producto);
    panel1.add(lblTipo_Viaje);
    panel1.add(lblFechaEnvio);
    panel1.add(lblFechaRecepcion);

    panel1.add(cajaId_Transporte);
    panel1.add(cajaId_Cliente);
    panel1.add(cajaId_Producto);
    panel1.add(cajaTipo_Viaje);

    separador.addTab("Gestion  de Transporte", null, panel1, "Separador1"); // Añadimos
    // el
    // Panel1
    // al
    // separador

    panel1.add(dateRecep);

    dateEnvio = new JDateChooser();
    dateEnvio.setBounds(270, 343, 250, 30);
    panel1.add(dateEnvio);

    btnOk = new JButton("OK");
    btnOk.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            cajaTipo_Viaje.setText((String) comboBox.getSelectedItem());
          }
        });
    btnOk.setBounds(473, 302, 47, 30);
    panel1.add(btnOk);

    comboBox = new JComboBox();
    comboBox.setModel(
        new DefaultComboBoxModel(new String[] {"Entrega", "Recogida", "Mixto", "Anulado"}));
    comboBox.setBounds(365, 302, 98, 30);
    panel1.add(comboBox);

    btnNewButton = new JButton("Generar N\u00BA");
    btnNewButton.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            cajaId_Transporte.setText(new Disparador("idTransporte").nextValue() + "");
          }
        });
    btnNewButton.setBounds(404, 182, 116, 26);
    panel1.add(btnNewButton);

    lblModuloTransporte = new JLabel("MODULO TRANSPORTE");
    lblModuloTransporte.setFont(new Font("Tahoma", Font.BOLD | Font.ITALIC, 30));
    lblModuloTransporte.setBounds(101, 28, 362, 37);
    panel1.add(lblModuloTransporte);

    JSeparator separatortitulo = new JSeparator();
    separatortitulo.setBackground(Color.BLACK);
    separatortitulo.setBounds(46, 68, 417, 10);
    panel1.add(separatortitulo);

    label = new JLabel("");
    label.setIcon(
        new ImageIcon(InterfaceTrans.class.getResource("/FinalLaGestionTransport/truckmini.png")));
    label.setBounds(47, 11, 62, 54);
    panel1.add(label);

    label_logo = new JLabel("");
    label_logo.setIcon(
        new ImageIcon(InterfaceTrans.class.getResource("/FinalLaGestionTransport/mini-logo.png")));
    label_logo.setBounds(1058, 11, 207, 114);
    panel1.add(label_logo);
    getContentPane().add(separador); // sin esto no se veria nada, añadimos
    // al JFrame el JTabbedPane

    // ------------------------------------------------------------------------------------------------
    // --------------------------A partir de aquí el panel 2
    // ------------------------------------------
    // ------------------------------------------------------------------------------------------------
    panel2 = new JPanel();
    panel2.setBackground(Color.LIGHT_GRAY); // asi le damos color al panel1
    panel2.setLayout(null);

    separador.addTab("Conductores", null, panel2, "Separador1");

    btnAgregarCondutores = new JButton("MODIFICAR CONDUCTORES");
    btnAgregarCondutores.addActionListener(
        new ActionListener() {

          public void actionPerformed(ActionEvent arg0) {
            //				AddConductores verformulario2 = new AddConductores();
            //				verformulario2.setVisible(true);

            try {
              Runtime.getRuntime()
                  .exec("rundll32 url.dll,FileProtocolHandler C:\\LaGestion\\Conductores.xls");
            } catch (IOException e) {
              // TODO Auto-generated catch block
              e.printStackTrace();
            }
          }
        });

    tabla2 = new JTable();
    tabla21 = new DefaultTableModel();
    tabla2.setModel(tabla21);
    tabla2.setBorder(new BevelBorder(BevelBorder.LOWERED, null, null, null, null));
    tabla2.setBackground(Color.LIGHT_GRAY);
    tabla2.setBounds(601, 189, 648, 400);
    // No queremos ver las lineas verticales
    tabla2.setShowVerticalLines(true);
    // No queremos ver las lineas verticales
    tabla2.setShowHorizontalLines(true);
    panel2.add(tabla2);

    btnAgregarCondutores.setBounds(384, 216, 207, 103);
    panel2.add(btnAgregarCondutores);

    labelLogo = new JLabel("");
    labelLogo.setIcon(
        new ImageIcon(InterfaceTrans.class.getResource("/FinalLaGestionTransport/mini-logo.png")));
    labelLogo.setBounds(1042, 11, 207, 114);
    panel2.add(labelLogo);

    labelConductor = new JLabel("LISTADO CONDUCTORES");
    labelConductor.setFont(new Font("Tahoma", Font.BOLD | Font.ITALIC, 30));
    labelConductor.setBounds(100, 33, 402, 37);
    panel2.add(labelConductor);

    label_2 = new JLabel("");
    label_2.setIcon(
        new ImageIcon(InterfaceTrans.class.getResource("/FinalLaGestionTransport/truckmini.png")));
    label_2.setBounds(51, 16, 62, 54);
    panel2.add(label_2);

    separatorTitulo = new JSeparator();
    separatorTitulo.setBackground(Color.BLACK);
    separatorTitulo.setBounds(61, 72, 441, 10);
    panel2.add(separatorTitulo);

    // RELOJ
    hilo = new Thread(this);
    hilo.start();
    lblReloj = new JLabel("");
    lblReloj.setFont(new Font("Tahoma", Font.BOLD | Font.ITALIC, 22));
    lblReloj.setBounds(61, 189, 312, 201);
    panel2.add(lblReloj);

    // Label Turno
    lblTurno = new JLabel("HORARIO/TURNO");
    lblTurno.setFont(new Font("Tahoma", Font.BOLD | Font.ITALIC, 18));
    lblTurno.setBounds(61, 401, 186, 27);
    panel2.add(lblTurno);

    lblVerturno = new JLabel("");
    lblVerturno.setFont(new Font("Tahoma", Font.BOLD | Font.ITALIC, 24));
    lblVerturno.setForeground(Color.BLUE);
    lblVerturno.setBounds(61, 446, 233, 66);
    panel2.add(lblVerturno);

    btnVerConductores = new JButton("VER CONDUCTORES");
    btnVerConductores.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent arg0) {

            String ruta = "C:\\LaGestion\\Conductores.xls";
            JFileChooser excel = new JFileChooser();
            excel.setSelectedFile(new File(ruta));
            File archivoexcel = null;
            archivoexcel = excel.getSelectedFile().getAbsoluteFile();

            try {

              Workbook leerEx = Workbook.getWorkbook(archivoexcel);

              for (int hoja = 0; hoja < leerEx.getNumberOfSheets(); hoja++) {

                Sheet hojap = leerEx.getSheet(hoja);
                int colum2 = hojap.getColumns();
                int filas1 = hojap.getRows();
                Object data[] = new Object[colum2];

                for (int fila = 0; fila < filas1; fila++) {
                  for (int colum1 = 0; colum1 < colum2; colum1++) {
                    if (fila == 0) {
                      tabla21.addColumn(hojap.getCell(colum1, fila).getContents());
                    }
                    //										System.out.println(hojap.getCell(colum1, fila).getContents());
                    if (fila >= 1) data[colum1] = hojap.getCell(colum1, fila).getContents();
                  }
                  tabla21.addRow(data);
                }
              }

              // opcional
              tabla21.removeRow(0);
            } catch (Exception e) {

            }
            // FIN DE LEER EXCEL

            btnVerConductores.setEnabled(false);
          }
        });
    btnVerConductores.setBounds(601, 141, 153, 37);
    panel2.add(btnVerConductores);

    // Separador
    getContentPane().add(separador); // sin esto no se veria nada, añadimos
    // al JFrame el JTabbedPane

  }