⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 graphpanel.java

📁 自己写的轮询提问的小程序 新手刚学 多多指教 合乎哈
💻 JAVA
字号:
/*GraphPanel is the component responsible for drawing those nifty bar graphsCopyright (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 SharedClasses.*;import java.util.*;import java.awt.Font;public class GraphPanel extends javax.swing.JPanel {        public GraphPanel() {        initComponents();        setBlank(true);        QuestionLabel.setBackground(this.getBackground());    }        private void initComponents() {//GEN-BEGIN:initComponents        BarB = new SharedClasses.Bar();        BarC = new SharedClasses.Bar();        BarD = new SharedClasses.Bar();        ParticipationBar = new javax.swing.JProgressBar();        jLabel1 = new javax.swing.JLabel();        BarA = new SharedClasses.Bar();        NoDataAvailableLabel = new javax.swing.JLabel();        BarF = new SharedClasses.Bar();        BarE = new SharedClasses.Bar();        QuestionLabel = new javax.swing.JTextArea();        setLayout(null);        BarB.setColor(new java.awt.Color(0, 0, 153));        BarB.setLabel("");        add(BarB);        BarB.setBounds(110, 140, 50, 190);        BarC.setColor(new java.awt.Color(0, 153, 153));        BarC.setLabel("");        add(BarC);        BarC.setBounds(180, 140, 50, 190);        BarD.setColor(new java.awt.Color(102, 153, 255));        BarD.setLabel("");        add(BarD);        BarD.setBounds(260, 140, 50, 190);        ParticipationBar.setStringPainted(true);        add(ParticipationBar);        ParticipationBar.setBounds(160, 350, 150, 22);        jLabel1.setFont(new java.awt.Font("Tahoma", 0, 11));        jLabel1.setText("Participation rate");        add(jLabel1);        jLabel1.setBounds(90, 330, 90, 12);        add(BarA);        BarA.setBounds(30, 140, 50, 190);        NoDataAvailableLabel.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);        NoDataAvailableLabel.setText("No data is available for this question");        add(NoDataAvailableLabel);        NoDataAvailableLabel.setBounds(130, 100, 250, 15);        BarF.setColor(new java.awt.Color(204, 0, 204));        BarF.setLabel("");        add(BarF);        BarF.setBounds(410, 140, 50, 190);        BarE.setColor(new java.awt.Color(255, 255, 0));        BarE.setLabel("");        add(BarE);        BarE.setBounds(330, 140, 50, 190);        QuestionLabel.setBackground(new java.awt.Color(212, 208, 200));        QuestionLabel.setEditable(false);        QuestionLabel.setLineWrap(true);        QuestionLabel.setWrapStyleWord(true);        add(QuestionLabel);        QuestionLabel.setBounds(20, 20, 460, 20);    }//GEN-END:initComponents    public void updateVotes(DataSet ds) {        int gv = ds.getGreatesVote();                BarA.setVoteCount(ds.getVoteCountA(), gv, ds.getVoterCount());        BarB.setVoteCount(ds.getVoteCountB(), gv, ds.getVoterCount());        BarC.setVoteCount(ds.getVoteCountC(), gv, ds.getVoterCount());        BarD.setVoteCount(ds.getVoteCountD(), gv, ds.getVoterCount());        BarE.setVoteCount(ds.getVoteCountE(), gv, ds.getVoterCount());        BarF.setVoteCount(ds.getVoteCountF(), gv, ds.getVoterCount());        ParticipationBar.setMaximum(ds.getVoterCount());        ParticipationBar.setValue(ds.getVoteCountA() + ds.getVoteCountB() +             ds.getVoteCountC() + ds.getVoteCountD());        repaint();    }        public void setBounds(int x, int y, int width, int height) {        int MaxHeight = 3 * height / 5;        int SpacerWidth = width / 30;        int BarWidth = (width - 5*SpacerWidth) / 7;        int BarPosition = 3 * height / 10;        int ParticipationBarHeight = height/12;        if (width*height > 202000) {            QuestionLabel.setFont(new Font("Tahoma", Font.PLAIN, 20));            BarA.setFont(new Font("Tahoma", Font.PLAIN, 16));            BarB.setFont(new Font("Tahoma", Font.PLAIN, 16));            BarC.setFont(new Font("Tahoma", Font.PLAIN, 16));            BarD.setFont(new Font("Tahoma", Font.PLAIN, 16));            BarE.setFont(new Font("Tahoma", Font.PLAIN, 16));            BarF.setFont(new Font("Tahoma", Font.PLAIN, 16));        }        if (currentQuestion != null) {            if (currentQuestion.getNumOfAnswers() == 6) {                BarA.setBounds(2 * SpacerWidth + 0 * BarWidth, BarPosition, BarWidth, MaxHeight);                BarB.setBounds(3 * SpacerWidth + 1 * BarWidth, BarPosition, BarWidth, MaxHeight);                BarC.setBounds(4 * SpacerWidth + 2 * BarWidth, BarPosition, BarWidth, MaxHeight);                BarD.setBounds(5 * SpacerWidth + 3 * BarWidth, BarPosition, BarWidth, MaxHeight);                BarE.setBounds(6 * SpacerWidth + 4 * BarWidth, BarPosition, BarWidth, MaxHeight);                BarF.setBounds(7 * SpacerWidth + 5 * BarWidth, BarPosition, BarWidth, MaxHeight);            }                        if (currentQuestion.getNumOfAnswers() == 5) {                BarA.setBounds((int) (2.5 * SpacerWidth + 0.5 * BarWidth), BarPosition, BarWidth, MaxHeight);                BarB.setBounds((int) (3.5 * SpacerWidth + 1.5 * BarWidth), BarPosition, BarWidth, MaxHeight);                BarC.setBounds((int) (4.5 * SpacerWidth + 2.5 * BarWidth), BarPosition, BarWidth, MaxHeight);                BarD.setBounds((int) (5.5 * SpacerWidth + 3.5 * BarWidth), BarPosition, BarWidth, MaxHeight);                BarE.setBounds((int) (6.5 * SpacerWidth + 4.5 * BarWidth), BarPosition, BarWidth, MaxHeight);            }            if (currentQuestion.getNumOfAnswers() == 4) {                BarA.setBounds(3 * SpacerWidth + 1 * BarWidth, BarPosition, BarWidth, MaxHeight);                BarB.setBounds(4 * SpacerWidth + 2 * BarWidth, BarPosition, BarWidth, MaxHeight);                BarC.setBounds(5 * SpacerWidth + 3 * BarWidth, BarPosition, BarWidth, MaxHeight);                BarD.setBounds(6 * SpacerWidth + 4 * BarWidth, BarPosition, BarWidth, MaxHeight);            }            if (currentQuestion.getNumOfAnswers() == 3) {                BarA.setBounds((int) (3.5 * SpacerWidth + 1.5 * BarWidth), BarPosition, BarWidth, MaxHeight);                BarB.setBounds((int) (4.5 * SpacerWidth + 2.5 * BarWidth), BarPosition, BarWidth, MaxHeight);                BarC.setBounds((int) (5.5 * SpacerWidth + 3.5 * BarWidth), BarPosition, BarWidth, MaxHeight);            }            if (currentQuestion.getNumOfAnswers() == 2) {                BarA.setBounds(4 * SpacerWidth + 2 * BarWidth, BarPosition, BarWidth, MaxHeight);                BarB.setBounds(5 * SpacerWidth + 3 * BarWidth, BarPosition, BarWidth, MaxHeight);            }        }        else {                BarA.setBounds(2 * SpacerWidth + 0 * BarWidth, BarPosition, BarWidth, MaxHeight);                BarB.setBounds(3 * SpacerWidth + 1 * BarWidth, BarPosition, BarWidth, MaxHeight);                BarC.setBounds(4 * SpacerWidth + 2 * BarWidth, BarPosition, BarWidth, MaxHeight);                BarD.setBounds(5 * SpacerWidth + 3 * BarWidth, BarPosition, BarWidth, MaxHeight);                BarE.setBounds(6 * SpacerWidth + 4 * BarWidth, BarPosition, BarWidth, MaxHeight);                BarF.setBounds(7 * SpacerWidth + 5 * BarWidth, BarPosition, BarWidth, MaxHeight);                   }        ParticipationBar.setBounds(SpacerWidth + BarWidth/2, MaxHeight + BarPosition + ParticipationBarHeight, 3 * SpacerWidth + 3 * BarWidth, ParticipationBarHeight);        jLabel1.setBounds(SpacerWidth, MaxHeight + BarPosition + 8, 90, 14);                int QuestionLabelHeight = (int) ((BarPosition - 30));                       QuestionLabel.setBounds(SpacerWidth, 16, width - 2*SpacerWidth, QuestionLabelHeight);                 NoDataAvailableLabel.setBounds((width - 250)/2, height/2 - 8, 250, 15);                super.setBounds(x, y, width, height);    }         public void setQuestion(Question q) {        currentQuestion = q;        QuestionLabel.setText(q.getQuestion());        setBounds(this.getX(), this.getY(), this.getWidth(), this.getHeight());        BarA.setLabel(q.getAnswerA());        BarB.setLabel(q.getAnswerB());        BarC.setLabel(q.getAnswerC());        BarD.setLabel(q.getAnswerD());        BarE.setLabel(q.getAnswerE());        BarF.setLabel(q.getAnswerF());        if (currentQuestion.getNumOfAnswers() <= 3) BarC.setVisible(false);        if (currentQuestion.getNumOfAnswers() <= 4) BarD.setVisible(false);        if (currentQuestion.getNumOfAnswers() <= 5) BarE.setVisible(false);        if (currentQuestion.getNumOfAnswers() <= 6) BarF.setVisible(false);                if (currentQuestion.getDataSetListing().size() <= 0) setBlank(true);        else setBlank(false);    }        public void setBlank(boolean b) {        if (b) {            BarA.setVisible(false);            BarB.setVisible(false);            BarC.setVisible(false);            BarD.setVisible(false);            BarE.setVisible(false);            BarF.setVisible(false);            jLabel1.setVisible(false);            ParticipationBar.setVisible(false);            QuestionLabel.setVisible(false);                        NoDataAvailableLabel.setVisible(true);        }        else {            BarA.setVisible(true);            BarB.setVisible(true);            if (currentQuestion.getNumOfAnswers() >= 3) BarC.setVisible(true);            if (currentQuestion.getNumOfAnswers() >= 4) BarD.setVisible(true);            if (currentQuestion.getNumOfAnswers() >= 5) BarE.setVisible(true);            if (currentQuestion.getNumOfAnswers() >= 6) BarF.setVisible(true);            jLabel1.setVisible(false);            ParticipationBar.setVisible(false);            QuestionLabel.setVisible(true);                        NoDataAvailableLabel.setVisible(false);                    }                    }        public void setDisplayPercentage(boolean b) {        BarA.setDisplayPercentage(b);        BarB.setDisplayPercentage(b);        BarC.setDisplayPercentage(b);        BarD.setDisplayPercentage(b);        BarE.setDisplayPercentage(b);        BarF.setDisplayPercentage(b);    }        // Variables declaration - do not modify//GEN-BEGIN:variables    private SharedClasses.Bar BarA;    private SharedClasses.Bar BarB;    private SharedClasses.Bar BarC;    private SharedClasses.Bar BarD;    private SharedClasses.Bar BarE;    private SharedClasses.Bar BarF;    private javax.swing.JLabel NoDataAvailableLabel;    private javax.swing.JProgressBar ParticipationBar;    private javax.swing.JTextArea QuestionLabel;    private javax.swing.JLabel jLabel1;    // End of variables declaration//GEN-END:variables     Question currentQuestion;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -