📄 votedisplaycontrol.java
字号:
/*VoteDisplayControlPanel controls what data the various GraphPanels displayCopyright (C) 2005-2006 Igor Partola, Michael J. Krikonis, Clark UniversityThis program is free software; you can redistribute it and/ormodify it under the terms of the GNU General Public Licenseas published by the Free Software Foundation; either version 2of the License, or (at your option) any later version.This program is distributed in the hope that it will be useful,but WITHOUT ANY WARRANTY; without even the implied warranty ofMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See theGNU General Public License for more details.You should have received a copy of the GNU General Public Licensealong with this program; if not, write to the Free SoftwareFoundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.*/package SharedClasses;import java.io.Serializable;import java.io.*;import javax.swing.*;import java.awt.*;import java.util.*;public class VoteDisplayControl extends javax.swing.JPanel implements Syncable, Serializable { public VoteDisplayControl() { initComponents(); } private void initComponents() {//GEN-BEGIN:initComponents QuestionComboBox = new javax.swing.JComboBox(); DataSetComboBox = new javax.swing.JComboBox(); jLabel1 = new javax.swing.JLabel(); jLabel2 = new javax.swing.JLabel(); DisplayPercentageCheckBox = new javax.swing.JCheckBox(); setLayout(null); setBorder(new javax.swing.border.BevelBorder(javax.swing.border.BevelBorder.RAISED)); QuestionComboBox.setFont(new java.awt.Font("Tahoma", 0, 11)); QuestionComboBox.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { QuestionComboBoxActionPerformed(evt); } }); add(QuestionComboBox); QuestionComboBox.setBounds(30, 40, 120, 20); DataSetComboBox.setFont(new java.awt.Font("Tahoma", 0, 11)); DataSetComboBox.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { DataSetComboBoxActionPerformed(evt); } }); add(DataSetComboBox); DataSetComboBox.setBounds(180, 40, 120, 20); jLabel1.setFont(new java.awt.Font("Tahoma", 0, 11)); jLabel1.setText("Question"); add(jLabel1); jLabel1.setBounds(20, 20, 70, 15); jLabel2.setFont(new java.awt.Font("Tahoma", 0, 11)); jLabel2.setText("Results"); add(jLabel2); jLabel2.setBounds(170, 20, 60, 14); DisplayPercentageCheckBox.setFont(new java.awt.Font("Tahoma", 0, 11)); DisplayPercentageCheckBox.setText("Display results as %"); DisplayPercentageCheckBox.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { DisplayPercentageCheckBoxActionPerformed(evt); } }); add(DisplayPercentageCheckBox); DisplayPercentageCheckBox.setBounds(20, 80, 130, 23); }//GEN-END:initComponents private void DisplayPercentageCheckBoxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_DisplayPercentageCheckBoxActionPerformed int i; GraphPanel gp; for (i = 0; i < GraphPanelVector.size(); i++) { gp = (GraphPanel) GraphPanelVector.elementAt(i); gp.setDisplayPercentage(DisplayPercentageCheckBox.isSelected()); } }//GEN-LAST:event_DisplayPercentageCheckBoxActionPerformed private void DataSetComboBoxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_DataSetComboBoxActionPerformed int i; GraphPanel gp; int qi = QuestionComboBox.getSelectedIndex(); int di = DataSetComboBox.getSelectedIndex(); if ((qi < 0) || (di < 0)) return; Question q = QuestionVector.getQuestionAt(qi); DataSet ds = q.getDataSetAt(di); for (i = 0; i < GraphPanelVector.size(); i++) { gp = (GraphPanel) GraphPanelVector.elementAt(i); gp.updateVotes(ds); } }//GEN-LAST:event_DataSetComboBoxActionPerformed private void QuestionComboBoxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_QuestionComboBoxActionPerformed if (QuestionComboBox.getSelectedIndex() < 0) return; Question q = (Question) QuestionVector.getQuestionAt(QuestionComboBox.getSelectedIndex()); GraphPanel gp; Vector w = q.getDataSetListing(); int i; String s; DataSetComboBox.removeAllItems(); for (i = 0; i < w.size(); i++) { s = (String) w.elementAt(i); DataSetComboBox.addItem(s); } DataSetComboBox.setSelectedIndex(DataSetComboBox.getItemCount() - 1); for (i = 0; i < GraphPanelVector.size(); i++) { gp = (GraphPanel) GraphPanelVector.elementAt(i); gp.setQuestion(q); } }//GEN-LAST:event_QuestionComboBoxActionPerformed public void syncComboBoxes() { Vector v = QuestionVector.getQuestionListing(); Vector w; if (v.size() < 1) return; Question q; String s; int i, j; int indx = QuestionComboBox.getSelectedIndex(); if (indx == v.size()) indx--; if (indx < 0) indx = 0; QuestionComboBox.removeAllItems(); for (i = 0; i < QuestionVector.size(); i++) { QuestionComboBox.addItem(v.elementAt(i)); } QuestionComboBox.setSelectedIndex(indx); } public void setBounds(int x, int y, int width, int height) { jLabel1.setBounds(width/9 - 10, 10, 70, 15); jLabel2.setBounds(2*width/9 + width/3 - 10, 10, 70, 15); QuestionComboBox.setBounds(width/9, 30, 3*width/9, 20); DataSetComboBox.setBounds(2*width/9 + width/3, 30, 3*width/9, 20); DisplayPercentageCheckBox.setBounds(width/11, 60, 8*width/9, 20); super.setBounds(x, y, width, height); } public void addGraphPanel(GraphPanel g) { GraphPanelVector.addElement(g); } public void removeGraphPanel(GraphPanel g) { GraphPanelVector.removeElement(g); } public void setJPQuestionVector(JPQuestionVector qv) { QuestionVector = qv; syncComboBoxes(); QuestionVector.addListener(this); } public void setQuestionIndex(int i) { QuestionComboBox.setSelectedIndex(i); } public void setDataSetIndex(int i) { DataSetComboBox.setSelectedIndex(i); } // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.JComboBox DataSetComboBox; private javax.swing.JCheckBox DisplayPercentageCheckBox; private javax.swing.JComboBox QuestionComboBox; private javax.swing.JLabel jLabel1; private javax.swing.JLabel jLabel2; // End of variables declaration//GEN-END:variables private JPQuestionVector QuestionVector; private Vector GraphPanelVector = new Vector();}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -