è¿æ²¡åå®è¦ä¸çäºï¼ä¸è¿å·®ä¸å¤äºï¼èªå·±ä¿®æ¹ä¿®æ¹å§
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;
}
}