📄 serviceseditor.java
字号:
package jMaint;import java.util.*;import javax.swing.*;public class ServicesEditor extends javax.swing.JFrame { int id = -1; boolean serv = true; boolean toSave = false; String[] types = new String[0]; int[] amounts = new int[0]; ServListData ServListInfo = new ServListData(); public ServicesEditor() { initComponents(); } private void initComponents() {//GEN-BEGIN:initComponents MainScroll = new javax.swing.JScrollPane(); MainScrollList = new javax.swing.JList(); ButtonSave = new javax.swing.JButton(); ButtonCancel = new javax.swing.JButton(); SmallPane = new javax.swing.JPanel(); SmallPaneText = new javax.swing.JTextField(); SmallPaneCombo = new javax.swing.JComboBox(); SmallPaneButtonAdd = new javax.swing.JButton(); SmallPaneButtonModify = new javax.swing.JButton(); getContentPane().setLayout(null); setTitle("Services Editor"); setResizable(false); addWindowListener(new java.awt.event.WindowAdapter() { public void windowClosing(java.awt.event.WindowEvent evt) { exitForm(evt); } public void windowOpened(java.awt.event.WindowEvent evt) { formWindowOpened(evt); } }); MainScroll.setBorder(null); MainScrollList.addKeyListener(new java.awt.event.KeyAdapter() { public void keyReleased(java.awt.event.KeyEvent evt) { MainScrollListKeyReleased(evt); } }); MainScrollList.addMouseListener(new java.awt.event.MouseAdapter() { public void mouseReleased(java.awt.event.MouseEvent evt) { MainScrollListMouseReleased(evt); } }); MainScroll.setViewportView(MainScrollList); getContentPane().add(MainScroll); MainScroll.setBounds(10, 10, 250, 300); ButtonSave.setFont(new java.awt.Font("Dialog", 1, 18)); ButtonSave.setText("Save"); ButtonSave.setMargin(new java.awt.Insets(2, 2, 2, 2)); ButtonSave.setMaximumSize(new java.awt.Dimension(100, 30)); ButtonSave.setMinimumSize(new java.awt.Dimension(100, 30)); ButtonSave.setPreferredSize(new java.awt.Dimension(100, 30)); ButtonSave.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { ButtonSaveActionPerformed(evt); } }); getContentPane().add(ButtonSave); ButtonSave.setBounds(280, 270, 100, 30); ButtonCancel.setFont(new java.awt.Font("Dialog", 1, 18)); ButtonCancel.setText("Cancel"); ButtonCancel.setMargin(new java.awt.Insets(2, 2, 2, 2)); ButtonCancel.setMaximumSize(new java.awt.Dimension(100, 30)); ButtonCancel.setMinimumSize(new java.awt.Dimension(100, 30)); ButtonCancel.setPreferredSize(new java.awt.Dimension(100, 30)); ButtonCancel.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { ButtonCancelActionPerformed(evt); } }); getContentPane().add(ButtonCancel); ButtonCancel.setBounds(440, 270, 100, 30); SmallPane.setLayout(null); SmallPane.setBorder(new javax.swing.border.TitledBorder("Service Type")); SmallPaneText.setFont(new java.awt.Font("Dialog", 0, 14)); SmallPane.add(SmallPaneText); SmallPaneText.setBounds(10, 20, 260, 30); SmallPaneCombo.setEditable(true); SmallPane.add(SmallPaneCombo); SmallPaneCombo.setBounds(10, 60, 260, 24); SmallPaneButtonAdd.setText("Add"); SmallPaneButtonAdd.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { SmallPaneButtonAddActionPerformed(evt); } }); SmallPane.add(SmallPaneButtonAdd); SmallPaneButtonAdd.setBounds(20, 100, 88, 25); SmallPaneButtonModify.setText("Modify"); SmallPaneButtonModify.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { SmallPaneButtonModifyActionPerformed(evt); } }); SmallPane.add(SmallPaneButtonModify); SmallPaneButtonModify.setBounds(170, 100, 88, 25); getContentPane().add(SmallPane); SmallPane.setBounds(270, 30, 280, 140); pack(); }//GEN-END:initComponents private void ButtonCancelActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_ButtonCancelActionPerformed this.dispose(); }//GEN-LAST:event_ButtonCancelActionPerformed private void ButtonSaveActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_ButtonSaveActionPerformed toSave = true; this.dispose(); }//GEN-LAST:event_ButtonSaveActionPerformed private void SmallPaneButtonModifyActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_SmallPaneButtonModifyActionPerformed if (id > -1) { ServListInfo.deleteRecord(ServListInfo.indexOf(id)); if (SmallPaneCombo.getSelectedIndex() > -1) ServListInfo.insertRecord(id, SmallPaneText.getText(), types[SmallPaneCombo.getSelectedIndex()]); else ServListInfo.insertRecord(id, SmallPaneText.getText(), SmallPaneCombo.getSelectedItem().toString().trim()); } else if (id < -9) { ServListInfo.modifyType(types[-id-10], SmallPaneText.getText().trim()); types[-id-10] = SmallPaneText.getText().trim(); } updateList(); }//GEN-LAST:event_SmallPaneButtonModifyActionPerformed private void SmallPaneButtonAddActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_SmallPaneButtonAddActionPerformed if (SmallPaneCombo.getSelectedIndex() > -1) ServListInfo.insertRecord(-1, SmallPaneText.getText(), types[SmallPaneCombo.getSelectedIndex()]); else ServListInfo.insertRecord(-1, SmallPaneText.getText(), SmallPaneCombo.getSelectedItem().toString().trim()); updateList(); }//GEN-LAST:event_SmallPaneButtonAddActionPerformed private void MainScrollListMouseReleased(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_MainScrollListMouseReleased listChange(); }//GEN-LAST:event_MainScrollListMouseReleased private void MainScrollListKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_MainScrollListKeyReleased listChange(); }//GEN-LAST:event_MainScrollListKeyReleased private void formWindowOpened(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowOpened this.setSize(560,350); }//GEN-LAST:event_formWindowOpened private void exitForm(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_exitForm this.dispose(); }//GEN-LAST:event_exitForm public static void main(String args[]) { new ServicesEditor().show(); } public void editEntry(ServListData SL) { this.show(); ServListInfo = SL; updateList(); } public void updateList() { String s = ""; Vector v = new Vector(); Vector v1 = new Vector(); Vector v2 = new Vector(); int x = 0; for (int i=0; i<ServListInfo.size(); i++) { if (!ServListInfo.getType(i).equalsIgnoreCase(s)) { s = ServListInfo.getType(i).trim(); v.addElement(new String(s)); v1.addElement(new String(s)); if (x!=0) { v2.addElement(new String(Integer.toString(x))); x = 0; } } v.addElement(new String(" " + ServListInfo.getName(i))); x++; } v2.addElement(new String(Integer.toString(x))); types = new String[v1.size()]; for (int i=0; i<v1.size(); i++) types[i] = v1.get(i).toString(); amounts = new int[v2.size()]; for (int i=0; i<v2.size(); i++) amounts[i] = Integer.parseInt(v2.get(i).toString()); MainScrollList.setListData(v); MainScrollList.setSelectedIndex(1); SmallPaneCombo.setModel(new DefaultComboBoxModel(types)); listChange(); } public void listChange() { int r = MainScrollList.getSelectedIndex(); int y = -1; int x = 0; for (int i=0; i<amounts.length; i++) { y = y+amounts[i]+1; if (r>y) x = i+1; } y = 0; for (int i=0; i<x; i++) y = y+amounts[i]+1; if (r==y) { SmallPane.setBorder(new javax.swing.border.TitledBorder("Service Type")); id = -10 - x; SmallPaneText.setText(types[x]); SmallPaneCombo.setSelectedIndex(x); SmallPaneButtonAdd.setEnabled(false); SmallPaneCombo.setEnabled(false); } else { SmallPane.setBorder(new javax.swing.border.TitledBorder("Service")); id = ServListInfo.getID(r-x-1); SmallPaneText.setText(ServListInfo.getName(r-x-1)); SmallPaneCombo.setSelectedIndex(x); SmallPaneButtonAdd.setEnabled(true); SmallPaneCombo.setEnabled(true); } } // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.JButton ButtonCancel; private javax.swing.JButton ButtonSave; private javax.swing.JScrollPane MainScroll; private javax.swing.JList MainScrollList; private javax.swing.JPanel SmallPane; private javax.swing.JButton SmallPaneButtonAdd; private javax.swing.JButton SmallPaneButtonModify; private javax.swing.JComboBox SmallPaneCombo; private javax.swing.JTextField SmallPaneText; // End of variables declaration//GEN-END:variables}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -