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

📄 starpanel.java

📁 预测7星彩的一个GUI Java程序。 该程序只是根据历史7星彩的记录
💻 JAVA
字号:
package gui;

import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.net.URL;
import java.util.ArrayList;
import java.util.Collections;

import javax.swing.*;

import Tools.Element;

/**
 * <p>
 * Title:
 * </p>
 * <p>
 * Description:
 * </p>
 * <p>
 * Copyright: Copyright (c) 2008
 * </p>
 * <p>
 * Company:
 * </p>
 * 
 * @author not attributable
 * @version 1.0
 */

public class StarPanel extends JPanel implements ActionListener {
	JPanel jPanel1 = new JPanel();
	JLabel jLabel1 = new JLabel();
	JLabel jLabel2 = new JLabel();
	public static DefaultListModel sourceModel = new DefaultListModel();
	JList sourceList = new JList(sourceModel);
	JScrollPane sourceScrollPane = new JScrollPane(sourceList);
	public static DefaultListModel resultModel = new DefaultListModel();
	JList resultList = new JList(resultModel);
	JScrollPane resultScrollPane = new JScrollPane(resultList);
	GridBagLayout gridBagLayout1 = new GridBagLayout();
	JPanel jPanel2 = new JPanel();
	JLabel jLabel3 = new JLabel();
	JLabel jLabel4 = new JLabel();
	JLabel jLabel5 = new JLabel();
	JLabel jLabel6 = new JLabel();
	JLabel jLabel7 = new JLabel();
	JLabel jLabel8 = new JLabel();
	JLabel jLabel9 = new JLabel();
	JLabel jLabel10 = new JLabel();
	JLabel jLabel11 = new JLabel();
	JLabel jLabel12 = new JLabel();
	JComboBox jComboBox0 = new JComboBox();
	JComboBox jComboBox1 = new JComboBox();
	JComboBox jComboBox2 = new JComboBox();
	JComboBox decFucBox = new JComboBox();
	public static JComboBox jComboBox3 = new JComboBox();
	JButton jButton1 = new JButton();
	JButton jButton2 = new JButton();
	GridLayout gridLayout1 = new GridLayout();
	GridBagLayout gridBagLayout2 = new GridBagLayout();

	public StarPanel() {
		try {
			jbInit();
		} catch (Exception ex) {
			ex.printStackTrace();
		}
	}

	void jbInit() throws Exception {
		this.setLayout(gridBagLayout2);
		jPanel1.setBorder(BorderFactory.createEtchedBorder());
		jPanel1.setOpaque(true);
		jPanel1.setLayout(gridBagLayout1);
		jLabel1.setHorizontalAlignment(SwingConstants.CENTER);
		jLabel1.setText("Predicted Numbers");
		jLabel2.setHorizontalAlignment(SwingConstants.CENTER);
		jLabel2.setText("Source History Data");
		jPanel2.setBorder(BorderFactory.createEtchedBorder());
		jPanel2.setLayout(gridLayout1);
		jLabel3.setHorizontalAlignment(SwingConstants.CENTER);
		jLabel3.setText("");
		jLabel3.setVerticalAlignment(javax.swing.SwingConstants.CENTER);
		jLabel4.setHorizontalAlignment(SwingConstants.CENTER);
		jLabel4.setText("# of Layers");
		jLabel5.setHorizontalAlignment(SwingConstants.CENTER);
		jLabel5.setText("Algorithm");
		jLabel6.setHorizontalAlignment(SwingConstants.CENTER);
		jLabel6.setText("# of history records");
		jLabel7.setText("History Record NO.");
		jLabel7.setHorizontalAlignment(SwingConstants.CENTER);
		jLabel8.setHorizontalAlignment(SwingConstants.CENTER);
		jLabel8.setText("");
		jLabel9.setHorizontalAlignment(SwingConstants.CENTER);
		final URL decURL = StarPanel.class.getResource("arrow.gif");
		ImageIcon icon = new ImageIcon(decURL);
		jLabel9.setIcon(icon);
		jLabel9.setText("Function");
		jLabel10.setHorizontalAlignment(SwingConstants.CENTER);
		jLabel10.setText("");

		jLabel11.setHorizontalAlignment(SwingConstants.CENTER);
		jLabel11.setText("");
		jLabel12.setHorizontalAlignment(SwingConstants.CENTER);
		jLabel12.setText("Good Luck!");

		jButton1.setText("Predict");
		jButton2.setText("Get precision");
		gridLayout1.setColumns(4);
		gridLayout1.setHgap(1);
		gridLayout1.setRows(4);
		gridLayout1.setVgap(1);
		this.add(jPanel1, new GridBagConstraints(0, 0, 1, 1, 1.0, 1.0,
				GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(
						1, 1, 0, 1), -490, -80));
		jPanel1.add(jLabel2, new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0,
				GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(
						1, 1, 1, 1), 79, 2));
		jPanel1.add(sourceScrollPane, new GridBagConstraints(0, 1, 1, 1, 1.0,
				1.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH,
				new Insets(1, 1, 1, 4), 179, 134));
		jPanel1.add(resultScrollPane, new GridBagConstraints(1, 1, 1, 1, 1.0,
				1.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH,
				new Insets(1, 4, 1, 1), 179, 134));
		jPanel1.add(jLabel1, new GridBagConstraints(1, 0, 1, 1, 0.0, 0.0,
				GridBagConstraints.SOUTHWEST, GridBagConstraints.BOTH,
				new Insets(1, 1, 1, 1), 85, 2));
		this.add(jPanel2, new GridBagConstraints(0, 1, 1, 1, 0.0, 0.0,
				GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(
						1, 1, 1, 1), 3, -25));
		jPanel2.add(jLabel7);
		jPanel2.add(jLabel8);
		jPanel2.add(jLabel9);
		jPanel2.add(jLabel10);
		jPanel2.add(jComboBox3);
		jPanel2.add(jButton2);
		decFucBox.addItem("(n-x)");
		decFucBox.addItem("2(n-x)");
		jPanel2.add(decFucBox);
		jPanel2.add(jLabel12);
		jPanel2.add(jLabel6, null);
		jPanel2.add(jLabel5, null);
		jPanel2.add(jLabel4, null);
		jPanel2.add(jLabel3, null);
		jPanel2.add(jComboBox0, null);
		jComboBox0.addItem("10");
		jComboBox0.addItem("20");
		jComboBox0.addItem("30");
		jComboBox0.addItem("40");
		jComboBox0.addItem("50");
		jComboBox0.addItem("60");
		jComboBox0.addItem("70");
		jComboBox0.addItem("80");
		jPanel2.add(jComboBox1, null);
		jComboBox1.addItem("Abs. Approach");
		jComboBox1.addItem("MontoCarlo");
		jPanel2.add(jComboBox2, null);
		jComboBox2.addItem("10");
		jComboBox2.addItem("1");
		jComboBox2.addItem("2");
		jComboBox2.addItem("3");
		jComboBox2.addItem("4");		
		jComboBox2.addItem("5");
		jComboBox2.addItem("6");
		jComboBox2.addItem("7");
		jComboBox2.addItem("8");		
		jComboBox2.addItem("9");
		
		jPanel2.add(jButton1, null);
		jButton1.addActionListener(this);
		jButton2.addActionListener(this);
	}

	public void actionPerformed(ActionEvent e) {
		resultModel.clear();
		if (((JButton) e.getSource()).getText().equals("Predict")) {
			System.out.println("Predict");
			int noOfHisRecord = Integer.parseInt((String) jComboBox0
					.getSelectedItem());
			String algorithm = (String) jComboBox1.getSelectedItem();
			int no = Integer.parseInt((String) jComboBox2.getSelectedItem());
			if (algorithm.equals("Abs. Approach")) {
				String func = (String) decFucBox.getSelectedItem();
				String[] result = absPredict(func, no);
				for(int i = 0; i < result.length; i++)
				{
					resultModel.addElement(result[i]);	
				}
			} else // MontoCarlo
			{

			}
		} else // e.getSource().equals("Get precision")
		{
			System.out.println("Get precision");
		}
	}

	int[][] init(ArrayList<String> list) {
		int n = list.size();
		int[][] sourceArray = new int[n][7];
		for (int i = 0; i < n; i++) {
			String s = list.get(i);
			if(s.equals(""))
				continue;
			int number = Integer.parseInt(s);
			for (int j = 0; j < 7; j++) {
				sourceArray[i][6 - j] = number % 10;
				number /= 10;
			}
		}
		return sourceArray;
	}

	String[] absPredict(String decFunction, int no) {
		int[] tempArray = new int[10];
		int[][] tResult = new int[7][10];
		String[] result2 = null;
		int[][] sourceArray = init(main.Main.sourceList);
		int n = main.Main.sourceList.size();
		if (decFunction.equals("(n-x)")) {
			for (int j = 0; j < 7; j++) {
				for (int i = 0; i < 10; i++) {
					tempArray[i] = 0;
				}

				for (int i = 0; i < n; i++) {
					int k = sourceArray[i][j];
					tempArray[k] += (n - i);
				}

				// sort
				ArrayList<Element> list = new ArrayList<Element>(10);
				for (int i = 0; i < 10; i++) {
					list.add(new Element(i, tempArray[i]));
				}
				Collections.sort(list);
				tResult[j][0] = list.get(0).getIndex();
				tResult[j][1] = list.get(1).getIndex();
				tResult[j][2] = list.get(2).getIndex();
				tResult[j][3] = list.get(3).getIndex();
				tResult[j][4] = list.get(4).getIndex();
				tResult[j][5] = list.get(5).getIndex();
				tResult[j][6] = list.get(6).getIndex();
				tResult[j][7] = list.get(7).getIndex();
				tResult[j][8] = list.get(8).getIndex();
				tResult[j][9] = list.get(9).getIndex();
			}
			result2 = new String[no];

			for (int i = 0; i < no; i++) {
				result2[i] = "";
				for (int j = 0; j < 7; j++)
					result2[i] += " " + tResult[j][i];
				System.out.println("--"+result2[i]);
			}

		} else { //"2(n-x)"
			for (int j = 0; j < 7; j++) {
				for (int i = 0; i < 10; i++) {
					tempArray[i] = 0;
				}

				for (int i = 0; i < n; i++) {
					int k = sourceArray[i][j];
					tempArray[k] += 2*(n - i);
				}

				// sort
				ArrayList<Element> list = new ArrayList<Element>(10);
				for (int i = 0; i < 10; i++) {
					list.add(new Element(i, tempArray[i]));
				}
				Collections.sort(list);
				tResult[j][0] = list.get(0).getIndex();
				tResult[j][1] = list.get(1).getIndex();
				tResult[j][2] = list.get(2).getIndex();
				tResult[j][3] = list.get(3).getIndex();
				tResult[j][4] = list.get(4).getIndex();
				tResult[j][5] = list.get(5).getIndex();
				tResult[j][6] = list.get(6).getIndex();
				tResult[j][7] = list.get(7).getIndex();
				tResult[j][8] = list.get(8).getIndex();
				tResult[j][9] = list.get(9).getIndex();
			}
			result2 = new String[no];

			for (int i = 0; i < no; i++) {
				result2[i] = "";
				for (int j = 0; j < 7; j++)
					result2[i] += " " + tResult[j][i];
				System.out.println("--"+result2[i]);
			}
			
		}
		
		return result2;
	}
}

⌨️ 快捷键说明

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