JAVA s=m!+(m+1)!+(m+2)!+……+n!(m<n),求s、(m!+n!)/3。编写图形界面程序,完成项目任务。 在线 急 等

JAVA的编程题目s=m!+(m+1)!+(m+2)!+……+n!(m<n),求s、(m!+n!)/3。编写图形界面程序,完成项目任务。 在线 急 等

还没写完要下班了,不过差不多了,自己修改修改吧

package com.mdsd.dip.sdk.javatest;

import java.awt.Color;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JOptionPane;
import javax.swing.JTextArea;
import javax.swing.JTextField;
import javax.swing.JTextPane;
import javax.swing.SwingUtilities;
import javax.swing.WindowConstants;
import javax.swing.text.SimpleAttributeSet;
import javax.swing.text.StyleConstants;
import javax.swing.text.StyledDocument;


/**
 * è°ƒç”¨ç¨‹åº
 * @author LiConghui

 * @version 1.0
 * @describeg界面
 * 
 * */
public class SdkTestMain extends javax.swing.JFrame {

    
    /** 
    * @Fields serialVersionUID
    */ 
    private static final long serialVersionUID = 1L;

    private JTextPane issue;
    
    private JTextPane keyM;
    private JTextField keyMVal;
    
    private JTextPane keyN;
    private JTextField keyNVal;
    
    private JTextArea result;
    private JButton jButton0;
    
    private int mVal=0;
    private int nVal=0;


    /**
     * ç¨‹åºå…¥å£
     */
    public static void main(String[] args) {

        SwingUtilities.invokeLater(new Runnable() {
            public void run() {
                SdkTestMain inst = new SdkTestMain();
                inst.setLocationRelativeTo(null);
                inst.setVisible(true);
            }
        });
    }

    /**
    * @Title: 
    * @Description: Init
    * @param     è®¾å®šæ–‡ä»¶ 
    * @return     è¿”回类型 
    * @throws
     */
    public SdkTestMain() {
        super();
        
        initGUI();
        setResizable(false);
        
    }

    /**
    * @Title: initGUI 
    * @Description: åˆå§‹åŒ–界面 
    * @return void    è¿”回类型 
    * @throws
     */
    private void initGUI() {
        try {
            setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
            getContentPane().setLayout(null);
            {
                //初始化 æ–‡æœ¬æ¡†
                issue = new JTextPane();
                StyledDocument doc = issue.getStyledDocument();
                SimpleAttributeSet center = new SimpleAttributeSet();
                StyleConstants.setAlignment(center, StyleConstants.ALIGN_CENTER);
                doc.setParagraphAttributes(0, doc.getLength(), center, false);
                issue.setStyledDocument(doc);
                getContentPane().add(issue);
                issue.setEditable(false);
                issue.setText("s=m!+(m+1)!+(m+2)!+……+n!(m<n),求s、(m!+n!)/3");
                issue.setBounds(100, 30, 400, 25);
                
                
                //初始化 æ–‡æœ¬æ¡†
                keyM = new JTextPane();
                StyledDocument doc1 = keyM.getStyledDocument();
                SimpleAttributeSet center1 = new SimpleAttributeSet();
                StyleConstants.setAlignment(center1, StyleConstants.ALIGN_CENTER);
                doc1.setParagraphAttributes(0, doc1.getLength(), center1, false);
                keyM.setStyledDocument(doc1);
                getContentPane().add(keyM);
                keyM.setEditable(false);
                keyM.setText("m(3-8)");
                keyM.setBounds(50, 85, 85, 25);
                
                keyMVal = new JTextField();
                getContentPane().add(keyMVal);
                keyMVal.setHorizontalAlignment(JTextField.CENTER);
                keyMVal.setBounds(155, 85, 50, 25);
                keyMVal.setBorder(BorderFactory.createLineBorder(Color.pink,1));
                keyMVal.setOpaque(false);
                
                //初始化 æ–‡æœ¬æ¡†
                keyN = new JTextPane();
                StyledDocument docN = keyN.getStyledDocument();
                SimpleAttributeSet centerN = new SimpleAttributeSet();
                StyleConstants.setAlignment(centerN, StyleConstants.ALIGN_CENTER);
                docN.setParagraphAttributes(0, docN.getLength(), centerN, false);
                keyN.setStyledDocument(docN);
                getContentPane().add(keyN);
                keyN.setEditable(false);
                keyN.setText("n(10-15)");
                keyN.setBounds(280, 85, 85, 25);
                
                keyNVal = new JTextField();
                getContentPane().add(keyNVal);
                keyNVal.setHorizontalAlignment(JTextField.CENTER);
                keyNVal.setBounds(385, 85, 50, 25);
                keyNVal.setBorder(BorderFactory.createLineBorder(Color.pink,1));
                keyNVal.setOpaque(false);
            
                
            }
            {
                jButton0 = new JButton();
                getContentPane().add(jButton0);
                jButton0.setText("求阶乘的和与(m!+n!)/3");
                jButton0.setBounds(50, 135, 200, 25);
                jButton0.setOpaque(false);
                jButton0.addActionListener(new ActionListener() {
                    public void actionPerformed(java.awt.event.ActionEvent evt) {
                        
                        if(check()){
                            cals(nVal,mVal);
                        }
                        
                    }
                });
            }
            pack();
            setSize(600, 300);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    

    public  boolean check(){
        if(keyMVal.getText().toString().equals("")){
            JOptionPane.showMessageDialog(null, "这是内容", "这是标题",JOptionPane.WARNING_MESSAGE);
            return false;
        }
        if(keyNVal.getText().toString().equals("")){
            JOptionPane.showMessageDialog(null, "这是内容", "这是标题",JOptionPane.WARNING_MESSAGE);
            return false;
        }
        mVal =Integer.parseInt( keyMVal.getText().toString());
        nVal =Integer.parseInt( keyNVal.getText().toString());
        return true;
    }
    
    public void cals(int n,int m){
        long s = 0;
        s = calVal(n)-calVal(m-1);
        System.out.println( "m=" + m);
        System.out.println( "n=" + n);
        System.out.println( "s=" + s);
    }
    

    public void requestService(String s) {
        
        
    }
    
    @Override
    public void setDefaultCloseOperation(int operation) {
        addWindowListener(new WindowAdapter() {
            public void windowClosing(WindowEvent e) {
            System.exit(0);
        }
        });
    }

    
    private static long calVal(int index){
        long a, u, b;
        u = 1;
        b = 0;
        String str = "";
        for (a = 1; a <= index; a++) {
            u = u * a;
            b = b + u;
            if (a == 1) {
                str = a + "!";
            } else {
                str = str + "+" + a + "!";
            }
        }
        System.out.println(str + "=" + b);
        return b;
        
    }
}
温馨提示:答案为网友推荐,仅供参考
第1个回答  2016-12-09
项目发我。我给你改剩下的。。。。。。