?? pollclient.java
字號:
/*This is the main class of the PollClient (called PollClient). Contains GUI and suchCopyright (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 PollClient;import java.io.*;import java.net.*;import javax.swing.*;import java.awt.*;import java.awt.event.*;public class PollClient extends javax.swing.JFrame implements Runnable{ public PollClient() { initComponents(); TimeoutTimer = new Timer(1000, new ActionListener() { public void actionPerformed(ActionEvent evt) { timeElapsed++; int tl = 0; if (currentQuestion != null) tl = currentQuestion.getTimeout() - timeElapsed; else tl = 0; if (tl < 0) tl = 0; TimeoutLabel.setText("Time left: " + Integer.toString(tl)); } }); disconnect(); } private void initComponents() {//GEN-BEGIN:initComponents RadioButtonGroup = new javax.swing.ButtonGroup(); AnswerRadioButtonA = new javax.swing.JRadioButton(); AnswerRadioButtonB = new javax.swing.JRadioButton(); AnswerRadioButtonC = new javax.swing.JRadioButton(); AnswerRadioButtonD = new javax.swing.JRadioButton(); AnswersLabel = new javax.swing.JLabel(); QuestionTextArea = new javax.swing.JTextArea(); QuestionNameLabel = new javax.swing.JLabel(); SendButton = new javax.swing.JButton(); ConnectButton = new javax.swing.JButton(); AddressTextField = new javax.swing.JTextField(); jLabel1 = new javax.swing.JLabel(); jSeparator1 = new javax.swing.JSeparator(); TimeoutLabel = new javax.swing.JLabel(); AnswerRadioButtonE = new javax.swing.JRadioButton(); AnswerRadioButtonF = new javax.swing.JRadioButton(); StatusLabel = new javax.swing.JLabel(); jButton1 = new javax.swing.JButton(); getContentPane().setLayout(null); setTitle("Just Poll Client"); setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR)); setFont(new java.awt.Font("Tahoma", 0, 10)); setName("PollClientMainFrame"); setResizable(false); addWindowListener(new java.awt.event.WindowAdapter() { public void windowClosing(java.awt.event.WindowEvent evt) { exitForm(evt); } }); AnswerRadioButtonA.setFont(new java.awt.Font("Tahoma", 0, 11)); AnswerRadioButtonA.setSelected(true); AnswerRadioButtonA.setText("A: Yes"); RadioButtonGroup.add(AnswerRadioButtonA); AnswerRadioButtonA.setEnabled(false); getContentPane().add(AnswerRadioButtonA); AnswerRadioButtonA.setBounds(30, 170, 170, 23); AnswerRadioButtonA.getAccessibleContext().setAccessibleName("RadioButtonA"); AnswerRadioButtonB.setFont(new java.awt.Font("Tahoma", 0, 11)); AnswerRadioButtonB.setText("B: No"); RadioButtonGroup.add(AnswerRadioButtonB); AnswerRadioButtonB.setEnabled(false); getContentPane().add(AnswerRadioButtonB); AnswerRadioButtonB.setBounds(200, 170, 180, 23); AnswerRadioButtonB.getAccessibleContext().setAccessibleName("RadioButtonB"); AnswerRadioButtonC.setFont(new java.awt.Font("Tahoma", 0, 11)); AnswerRadioButtonC.setText("C: I don't know"); RadioButtonGroup.add(AnswerRadioButtonC); AnswerRadioButtonC.setEnabled(false); getContentPane().add(AnswerRadioButtonC); AnswerRadioButtonC.setBounds(30, 200, 170, 23); AnswerRadioButtonC.getAccessibleContext().setAccessibleName("RadioButtonC"); AnswerRadioButtonD.setFont(new java.awt.Font("Tahoma", 0, 11)); AnswerRadioButtonD.setText("D: I need to ask my wife"); RadioButtonGroup.add(AnswerRadioButtonD); AnswerRadioButtonD.setEnabled(false); getContentPane().add(AnswerRadioButtonD); AnswerRadioButtonD.setBounds(200, 200, 190, 23); AnswerRadioButtonD.getAccessibleContext().setAccessibleName("RadioButtonD"); AnswersLabel.setFont(new java.awt.Font("Tahoma", 0, 11)); AnswersLabel.setText("Answers"); AnswersLabel.setEnabled(false); getContentPane().add(AnswersLabel); AnswersLabel.setBounds(30, 150, 80, 14); AnswersLabel.getAccessibleContext().setAccessibleName("AnswersLabel"); QuestionTextArea.setEditable(false); QuestionTextArea.setFont(new java.awt.Font("Tahoma", 0, 11)); QuestionTextArea.setLineWrap(true); QuestionTextArea.setWrapStyleWord(true); QuestionTextArea.setEnabled(false); getContentPane().add(QuestionTextArea); QuestionTextArea.setBounds(30, 50, 350, 80); QuestionNameLabel.setFont(new java.awt.Font("Tahoma", 0, 11)); QuestionNameLabel.setText("Waiting for next question..."); getContentPane().add(QuestionNameLabel); QuestionNameLabel.setBounds(10, 30, 160, 14); QuestionNameLabel.getAccessibleContext().setAccessibleName("QuestionLabel"); SendButton.setFont(new java.awt.Font("Tahoma", 0, 11)); SendButton.setText("Send"); SendButton.setActionCommand("SendButton"); SendButton.setEnabled(false); SendButton.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { SendButtonActionPerformed(evt); } }); getContentPane().add(SendButton); SendButton.setBounds(150, 270, 73, 25); SendButton.getAccessibleContext().setAccessibleName("SendButton"); ConnectButton.setFont(new java.awt.Font("Tahoma", 0, 11)); ConnectButton.setText("Connect"); ConnectButton.setActionCommand("ConnectButton"); ConnectButton.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { ConnectButtonActionPerformed(evt); } }); getContentPane().add(ConnectButton); ConnectButton.setBounds(280, 240, 90, 30); ConnectButton.getAccessibleContext().setAccessibleName("ConnectButton"); AddressTextField.setFont(new java.awt.Font("Tahoma", 0, 11)); AddressTextField.setText("140.232.*.*"); getContentPane().add(AddressTextField); AddressTextField.setBounds(240, 280, 140, 20); AddressTextField.getAccessibleContext().setAccessibleName("AddressTextField"); jLabel1.setFont(new java.awt.Font("Tahoma", 0, 11)); jLabel1.setText("Network Address"); getContentPane().add(jLabel1); jLabel1.setBounds(260, 270, 90, 14); getContentPane().add(jSeparator1); jSeparator1.setBounds(0, 309, 400, 10); TimeoutLabel.setFont(new java.awt.Font("Tahoma", 0, 11)); TimeoutLabel.setText("Time left: "); getContentPane().add(TimeoutLabel); TimeoutLabel.setBounds(270, 30, 90, 15); AnswerRadioButtonE.setFont(new java.awt.Font("Tahoma", 0, 11)); AnswerRadioButtonE.setText("E: I really don't know"); RadioButtonGroup.add(AnswerRadioButtonE); AnswerRadioButtonE.setEnabled(false); getContentPane().add(AnswerRadioButtonE); AnswerRadioButtonE.setBounds(30, 230, 170, 23); AnswerRadioButtonF.setFont(new java.awt.Font("Tahoma", 0, 11)); AnswerRadioButtonF.setText("F: N/A"); RadioButtonGroup.add(AnswerRadioButtonF); AnswerRadioButtonF.setEnabled(false); getContentPane().add(AnswerRadioButtonF); AnswerRadioButtonF.setBounds(200, 230, 190, 23); StatusLabel.setFont(new java.awt.Font("Tahoma", 0, 11)); StatusLabel.setIcon(new javax.swing.ImageIcon(getClass().getResource("/PollClient/disconnected-icon.gif"))); StatusLabel.setText("Connected to localhost"); StatusLabel.setFocusable(false); StatusLabel.setIconTextGap(8); StatusLabel.setHorizontalTextPosition(javax.swing.SwingConstants.LEADING); getContentPane().add(StatusLabel); StatusLabel.setBounds(10, 315, 230, 20); jButton1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/PollClient/info.gif"))); jButton1.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButton1ActionPerformed(evt); } }); getContentPane().add(jButton1); jButton1.setBounds(369, 313, 30, 28); java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize(); setBounds((screenSize.width-408)/2, (screenSize.height-412)/2, 408, 412); }//GEN-END:initComponents private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed SharedClasses.AboutDialog MyAboutFrame = new SharedClasses.AboutDialog(this, true); MyAboutFrame.show(); }//GEN-LAST:event_jButton1ActionPerformed private void SendButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_SendButtonActionPerformed answer = getAnswer(); QuestionNameLabel.setText("Waiting for the next question..."); controlsSetEnabled(false); SendButton.setEnabled(false); }//GEN-LAST:event_SendButtonActionPerformed private void ConnectButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_ConnectButtonActionPerformed connect(); }//GEN-LAST:event_ConnectButtonActionPerformed private void exitForm(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_exitForm System.exit(0); }//GEN-LAST:event_exitForm public static void main(String args[]) { new PollClient().setVisible(true); } public void showQuestion(Question q) { QuestionNameLabel.setText(q.getQuestionName()); QuestionTextArea.setText(q.getQuestion()); AnswerRadioButtonA.setText("A: " + q.getAnswerA()); AnswerRadioButtonB.setText("B: " + q.getAnswerB()); AnswerRadioButtonC.setText("C: " + q.getAnswerC());
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -