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

📄 pollserver.java

📁 自己写的轮询提问的小程序 新手刚学 多多指教 合乎哈
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/*
PollServer is the control panel that drives it all.
Copyright (C) 2005-2006  Igor Partola, Michael J. Krikonis, Clark University

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of 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 of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
*/

package PollServer;

import java.net.*;
import java.io.*;
import java.util.*;
import javax.swing.*;
import java.awt.*;
import SharedClasses.*;
import org.netbeans.examples.lib.timerbean.*;
import java.awt.event.*;

public class PollServer extends javax.swing.JFrame {
    
    public PollServer(boolean UseProjectorReporting) {
        initComponents();
        
        MyGraphFrame = new GraphFrame();
        if (UseProjectorReporting) {
            MyGraphFrame.setBounds(Toolkit.getDefaultToolkit().getScreenSize().width + 10, 0, 200, 200);
            MyGraphFrame.setExtendedState(MAXIMIZED_BOTH);
            VoteDisplayControlPanel.addGraphPanel(MyGraphFrame.getGraphPanel());
            MyGraphFrame.setVisible(true);
        }
        

        startServer();
        
        TimeoutTimer = new javax.swing.Timer(1000, new ActionListener() {
            public void actionPerformed(ActionEvent evt) {
                int timeout = currentQuestion.getTimeout();
                time++;
                int timeleft = timeout - time;
                if (timeleft < 0) timeleft = 0;
                TimeoutLabel.setText("Time left: " + Integer.toString(timeleft));

                if ((time >= timeout) && (time < timeout + 1)) {
                    TalkThread t;

                    for (int i = 0; i < talkThreadVector.size(); i++) {
                        t = (TalkThread) talkThreadVector.get(i);
                        t.closeQuestion();
                    }
                }

                if (time >= timeout + 1) {
                    resetQuestion(true);
                    updateVoteLabels();
                    time = 0;
                    TimeoutTimer.stop();
                }

                }
        });        
    }
    
    private void initComponents() {//GEN-BEGIN:initComponents
        ClientCountLabel = new javax.swing.JLabel();
        ServerStatusLabel = new javax.swing.JLabel();
        PostQuestionButton = new javax.swing.JButton();
        jSeparator1 = new javax.swing.JSeparator();
        IPAddressLabel = new javax.swing.JLabel();
        jSeparator4 = new javax.swing.JSeparator();
        jSeparator5 = new javax.swing.JSeparator();
        jSeparator6 = new javax.swing.JSeparator();
        jSeparator3 = new javax.swing.JSeparator();
        TimeoutLabel = new javax.swing.JLabel();
        QuestionEditor = new SharedClasses.QuestionEditorPanel();
        VoteDisplayControlPanel = new SharedClasses.VoteDisplayControl();
        VoteGraphPanel = new SharedClasses.GraphPanel();
        MenuBar = new javax.swing.JMenuBar();
        FileMenu = new javax.swing.JMenu();
        QuestionListSaveMenuItem = new javax.swing.JMenuItem();
        QuestionListLoadMenuItem = new javax.swing.JMenuItem();
        jSeparator2 = new javax.swing.JSeparator();
        StartServerMenuItem = new javax.swing.JMenuItem();
        StopServerMenuItem = new javax.swing.JMenuItem();
        jSeparator7 = new javax.swing.JSeparator();
        ExitMenuItem = new javax.swing.JMenuItem();
        HelpMenu = new javax.swing.JMenu();
        AboutMenuItem = new javax.swing.JMenuItem();

        getContentPane().setLayout(null);

        setTitle("Just Poll Server Panel");
        setName("PollServerMainThread");
        setResizable(false);
        addWindowListener(new java.awt.event.WindowAdapter() {
            public void windowClosing(java.awt.event.WindowEvent evt) {
                exitForm(evt);
            }
        });

        ClientCountLabel.setFont(new java.awt.Font("Tahoma", 0, 11));
        ClientCountLabel.setText("Client Connected: 0");
        getContentPane().add(ClientCountLabel);
        ClientCountLabel.setBounds(10, 500, 130, 14);
        ClientCountLabel.getAccessibleContext().setAccessibleName("ClientCountLabel");

        ServerStatusLabel.setFont(new java.awt.Font("Tahoma", 0, 11));
        ServerStatusLabel.setText("Server not running");
        getContentPane().add(ServerStatusLabel);
        ServerStatusLabel.setBounds(130, 500, 110, 14);

        PostQuestionButton.setFont(new java.awt.Font("Tahoma", 0, 11));
        PostQuestionButton.setText("Post Question");
        PostQuestionButton.setEnabled(false);
        PostQuestionButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                PostQuestionButtonActionPerformed(evt);
            }
        });

        getContentPane().add(PostQuestionButton);
        PostQuestionButton.setBounds(30, 440, 350, 30);

        jSeparator1.setOrientation(javax.swing.SwingConstants.VERTICAL);
        getContentPane().add(jSeparator1);
        jSeparator1.setBounds(420, 10, 10, 480);

        IPAddressLabel.setFont(new java.awt.Font("Tahoma", 0, 11));
        IPAddressLabel.setText("Network Address: Unknown");
        try { IPAddressLabel.setText("IP Address: " + InetAddress.getLocalHost().getHostAddress()); } catch (UnknownHostException e) { }
        getContentPane().add(IPAddressLabel);
        IPAddressLabel.setBounds(240, 500, 180, 14);

        getContentPane().add(jSeparator4);
        jSeparator4.setBounds(0, 490, 830, 10);

        jSeparator5.setOrientation(javax.swing.SwingConstants.VERTICAL);
        getContentPane().add(jSeparator5);
        jSeparator5.setBounds(120, 490, 10, 30);

        jSeparator6.setOrientation(javax.swing.SwingConstants.VERTICAL);
        getContentPane().add(jSeparator6);
        jSeparator6.setBounds(230, 490, 10, 30);

        jSeparator3.setOrientation(javax.swing.SwingConstants.VERTICAL);
        getContentPane().add(jSeparator3);
        jSeparator3.setBounds(420, 490, 10, 30);

        TimeoutLabel.setFont(new java.awt.Font("Tahoma", 0, 11));
        TimeoutLabel.setText("Time left: 0");
        getContentPane().add(TimeoutLabel);
        TimeoutLabel.setBounds(440, 500, 60, 14);

        QuestionEditor.setBorder(new javax.swing.border.BevelBorder(javax.swing.border.BevelBorder.RAISED));
        QuestionEditor.setJPQuestionVector(QuestionVector);
        getContentPane().add(QuestionEditor);
        QuestionEditor.setBounds(10, 10, 390, 410);

        VoteDisplayControlPanel.setBorder(new javax.swing.border.BevelBorder(javax.swing.border.BevelBorder.RAISED));
        VoteDisplayControlPanel.setJPQuestionVector(QuestionVector);
        getContentPane().add(VoteDisplayControlPanel);
        VoteDisplayControlPanel.setBounds(440, 10, 340, 100);

        VoteGraphPanel.setBorder(new javax.swing.border.BevelBorder(javax.swing.border.BevelBorder.RAISED));
        VoteDisplayControlPanel.addGraphPanel(VoteGraphPanel);
        getContentPane().add(VoteGraphPanel);
        VoteGraphPanel.setBounds(440, 130, 340, 290);

        FileMenu.setText("File");
        QuestionListSaveMenuItem.setIcon(new javax.swing.ImageIcon(getClass().getResource("/SharedClasses/graphics/Save16.gif")));
        QuestionListSaveMenuItem.setText("Save");
        QuestionListSaveMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                QuestionListSaveMenuItemActionPerformed(evt);
            }
        });

        FileMenu.add(QuestionListSaveMenuItem);

        QuestionListLoadMenuItem.setIcon(new javax.swing.ImageIcon(getClass().getResource("/SharedClasses/graphics/Open16.gif")));
        QuestionListLoadMenuItem.setText("Open...");
        QuestionListLoadMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                QuestionListLoadMenuItemActionPerformed(evt);
            }
        });

        FileMenu.add(QuestionListLoadMenuItem);

        FileMenu.add(jSeparator2);

        StartServerMenuItem.setText("Start Server");
        StartServerMenuItem.setEnabled(false);
        StartServerMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                StartServerMenuItemActionPerformed(evt);
            }
        });

        FileMenu.add(StartServerMenuItem);

        StopServerMenuItem.setText("Stop Server");
        StopServerMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                StopServerMenuItemActionPerformed(evt);
            }
        });

        FileMenu.add(StopServerMenuItem);

        FileMenu.add(jSeparator7);

        ExitMenuItem.setText("Exit");
        ExitMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                ExitMenuItemActionPerformed(evt);
            }
        });

        FileMenu.add(ExitMenuItem);

        MenuBar.add(FileMenu);

        HelpMenu.setText("Help");
        AboutMenuItem.setText("About");
        AboutMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                AboutMenuItemActionPerformed(evt);
            }
        });

        HelpMenu.add(AboutMenuItem);

⌨️ 快捷键说明

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