java300例中的,我想把这个投票系统显示在JSP页面!怎样写啊?

package second;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.EventQueue;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JProgressBar;
import javax.swing.UIManager;
import javax.swing.border.EmptyBorder;
import javax.swing.border.LineBorder;
import javax.swing.border.TitledBorder;

public class VoteCount extends JFrame {
private JPanel comtentPane;
private JCheckBox checkbox1;
private JCheckBox checkbox2;
private JCheckBox checkbox3;
private JCheckBox checkbox4;
private JLabel labell;
private JLabel label2;
private JLabel label3;
private JLabel label4;
private JProgressBar progressBar1;
private JProgressBar progressBar2;
private JProgressBar progressBar3;
private JProgressBar progressBar4;

public static void main(String[] args) {
    try {
        UIManager.setLookAndFeel("com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel");
    } catch (Exception e) {
        e.printStackTrace();
    }
    EventQueue.invokeLater(new Runnable(){

public void run() {
    try {
        VoteCount frame = new VoteCount();
        frame.setVisible(true);
    } catch (Exception e) {
        e.printStackTrace();
    }
}

});
}

public VoteCount() {
    setTitle("投票系統");
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    setBounds(100,100,450,300);
    comtentPane = new JPanel();
    comtentPane.setBorder(new EmptyBorder(5,5,5,5));
    setContentPane(comtentPane);
    comtentPane.setLayout(new BorderLayout(0,0));
    JPanel buttonPanel  = new JPanel();
    comtentPane.add(buttonPanel,BorderLayout.SOUTH);
    JButton submitButton  = new JButton("提交");
    submitButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            do_submitButton_actionPerformed(e);
        }
    });
    buttonPanel.add(submitButton);
    JButton refreshButton = new JButton("刷新");
    refreshButton.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {

        }
    });
    buttonPanel.add(refreshButton);
    JPanel panel = new JPanel();
    panel.setBorder(new TitledBorder(new LineBorder(new Color(0,0,0)),"你最喜爱的城市",TitledBorder.LEADING,TitledBorder.TOP,null,new Color(59, 59, 59)));
    comtentPane.add(panel,BorderLayout.CENTER);
    panel.setLayout(new GridLayout(4,1,15,15));
    JPanel  panel1  = new JPanel();
    panel.add(panel1);
    panel1.setLayout(new BorderLayout(0,0));
    checkbox1 = new JCheckBox("长春\uFF1A");
    panel1.add(checkbox1, BorderLayout.WEST);
    labell = new JLabel("0\u7968");
    panel1.add(labell, BorderLayout.EAST);

    JPanel  panel2  = new JPanel();
    panel.add(panel2);
    panel2.setLayout(new BorderLayout(0,0));
    checkbox2 = new JCheckBox("北京\uFF1A");
    panel2.add(checkbox2, BorderLayout.WEST);
    label2 = new JLabel("0\u7968");
    panel2.add(label2, BorderLayout.EAST);

    JPanel  panel3  = new JPanel();
    panel.add(panel3);
    panel3.setLayout(new BorderLayout(0,0));
    checkbox3 = new JCheckBox("三亚\uFF1A");  
    panel3.add(checkbox3, BorderLayout.WEST);
    label3 = new JLabel("0\u7968");
    panel3.add(label3, BorderLayout.EAST);

    JPanel  panel4  = new JPanel();
    panel.add(panel4);
    panel4.setLayout(new BorderLayout(0,0));
    checkbox4 = new JCheckBox("大连\uFF1A");
    panel4.add(checkbox4, BorderLayout.WEST);
    label4 = new JLabel("0\u7968");
    panel4.add(label4, BorderLayout.EAST);



progressBar1=new JProgressBar();
progressBar1.setStringPainted(true);
panel1.add(progressBar1,BorderLayout.CENTER);

progressBar2=new JProgressBar();
progressBar2.setStringPainted(true);
panel2.add(progressBar2,BorderLayout.CENTER);

progressBar3=new JProgressBar();
progressBar3.setStringPainted(true);
panel3.add(progressBar3,BorderLayout.CENTER);

progressBar4=new JProgressBar();
progressBar4.setStringPainted(true);
panel4.add(progressBar4,BorderLayout.CENTER);

JPanel panel21 = new JPanel();
panel.add(panel21);
panel21.setLayout(new BorderLayout(0,0));

JPanel panel31 = new JPanel();
panel.add(panel31);
panel31.setLayout(new BorderLayout(0,0));

JPanel panel41 = new JPanel();
panel.add(panel41);
panel41.setLayout(new BorderLayout(0,0));

JPanel panel51 = new JPanel();
panel.add(panel51);
panel51.setLayout(new BorderLayout(0,0));

}

protected void do_submitButton_actionPerformed(ActionEvent e) {
    String text1 = labell.getText();
    int number1 = Integer.parseInt(text1.substring(0, text1.length() - 1));
    String text2 = label2.getText();
    int number2 = Integer.parseInt(text2.substring(0, text2.length() - 1));
    String text3 = label3.getText();
    int number3 = Integer.parseInt(text3.substring(0, text3.length() - 1));
    String text4 = label4.getText();
    int number4 = Integer.parseInt(text3.substring(0, text4.length() - 1));
    if (checkbox1.isSelected()) {
        number1++;
        labell.setText(number1 + "票");
    }
    if (checkbox2.isSelected()) {
        number2++;
        label2.setText(number1 + "票");
    }
    if (checkbox3.isSelected()) {
        number3++;
        label3.setText(number1 + "票");
    }
    if (checkbox4.isSelected()) {
        number4++;
        label4.setText(number1 + "票");
    }
    double total = number1 + number2 + number3 + number4;
    progressBar1.setString(number1 * 100 / total + "%");
    progressBar1.setValue(number1);
    progressBar2.setString(number2 * 100 / total + "%");
    progressBar2.setValue(number2);
    progressBar3.setString(number3 * 100 / total + "%");
    progressBar3.setValue(number3);
    progressBar4.setString(number4 * 100 / total + "%");
    progressBar4.setValue(number4);
}

protected void do_refreshButton_actionperformed(ActionEvent e) {
    checkbox1.setSelected(false);
    checkbox2.setSelected(false);
    checkbox3.setSelected(false);
    checkbox4.setSelected(false);
}

}

3个回答

那swing就不能用了,要全部推倒重来

把整个移植到jsp页面中,用块包起来

swing编程用在jsp页面可能比较麻烦,jsp有它自己的内置函数可以调用,直接用jsp+javabban简单一点

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问