双色球软件设计思路及初步源码

软件功能:

一.双色球共1107568注二等奖,这些注里可以过滤掉的垃圾号如下:

1.六连号、五连号、四连号、三连号、甚至二连号

2.全偶数、全气数奇数

3.已经开过的奖号

4.已经开过的奖号的五重号、四重号、三重号

所谓垃圾号很多,可以逐步增加,但双色球开奖正常的号码我们假设以三奇三偶、大小均匀为主。

 

二.一旦过滤掉很多垃圾号之后,你就可以豪赌一把!

三.基本开奖号码查询

1.可以按位查询,点击后可以排序

2.选定一些注数后让选定的行为红色,可以再排序,但红色行不变。

3.可以查询当前开了多少期,过滤后还剩余多少注。

以上为本人对此软件的基本思路,有兴趣的朋友可以增加思路、增加功能(当然,我写的源码会公开),中奖事儿小,学习java的事儿也不大,娱乐,娱乐!

A.主运行程序:

 

import java.awt.BorderLayout;  
  1. import java.awt.Color;  
  2. import java.awt.Container;  
  3. import java.awt.Font;  
  4. import java.awt.Image;  
  5. import java.awt.Toolkit;  
  6. import java.awt.event.ActionEvent;  
  7. import java.awt.event.ActionListener;  
  8.   
  9. import javax.swing.AbstractButton;  
  10. import javax.swing.ImageIcon;  
  11. import javax.swing.JButton;  
  12. import javax.swing.JFrame;  
  13. import javax.swing.JLabel;  
  14. import javax.swing.JMenu;  
  15. import javax.swing.JMenuBar;  
  16. import javax.swing.JMenuItem;  
  17. import javax.swing.JOptionPane;  
  18. import javax.swing.JPanel;  
  19. import javax.swing.JToolBar;  
  20. import javax.swing.SwingConstants;  
  21. import javax.swing.border.LineBorder;  
  22. import javax.swing.border.TitledBorder;  
  23.   
  24.   
  25. public class SSQ {  
  26.     JFrame frame;  
  27.     JPanel KJpanel,GLpanel,JGpanel;  
  28.     ImageIcon icon01;  
  29.   
  30.     public SSQ(){  
  31.         frame = new JFrame("大话双色球");  
  32.         Image image = Toolkit.getDefaultToolkit().createImage("");  
  33.         frame.setIconImage(image);  
  34.         frame.setJMenuBar(createMenuBar());  
  35.         frame.setContentPane(createContentPane());  
  36.         frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);  
  37.         frame.setLocation(50,50);  
  38.         frame.setSize(800,500);  
  39.         frame.setVisible(true);  
  40.     }  
  41.   
  42.     private Container createContentPane() {  
  43.         Container contentPane = frame.getContentPane();  
  44.         JToolBar toolBar = new JToolBar();  
  45.         JLabel KT = new JLabel("开头:");  
  46.         KT.setFont(new Font("微软雅黑",Font.BOLD, 14));  
  47.           
  48.         KJpanel = new JPanel();  
  49.         KJpanel.setSize(100100);  
  50.         KJpanel.setBorder(new TitledBorder("开奖"));  
  51.         KJpanel.add(new ReadKj());  
  52.         GLpanel = new JPanel();  
  53.         GLpanel.setBorder(new TitledBorder("过滤"));  
  54.         JGpanel = new JPanel();  
  55.         JGpanel.setBorder(new TitledBorder("结果"));        
  56.           
  57.         JButton button01 = new JButton("01",icon01);  
  58.         button01.setHorizontalTextPosition(AbstractButton.CENTER);  
  59.         button01.addActionListener(new ActionListener(){  
  60.             public void actionPerformed(ActionEvent e) {  
  61.                 GLpanel.removeAll();  
  62.                 GLpanel.add(new Read01());  
  63.                 GLpanel.updateUI();  
  64.             }  
  65.         });  
  66.         System.gc();  
  67.         JButton button02 = new JButton("02",icon01);  
  68.         button02.setHorizontalTextPosition(AbstractButton.CENTER);  
  69.         button02.addActionListener(new ActionListener(){  
  70.             public void actionPerformed(ActionEvent e) {  
  71.                 GLpanel.removeAll();  
  72.                 GLpanel.add(new Read02());  
  73.                 GLpanel.updateUI();  
  74.             }  
  75.         });  
  76.         System.gc();  
  77.         JButton button03 = new JButton("03",icon01);  
  78.         button03.setHorizontalTextPosition(AbstractButton.CENTER);  
  79.         JButton button04 = new JButton("04",icon01);  
  80.         button04.setHorizontalTextPosition(AbstractButton.CENTER);  
  81.         JButton button05 = new JButton("05",icon01);  
  82.         button05.setHorizontalTextPosition(AbstractButton.CENTER);  
  83.         JButton button06 = new JButton("06",icon01);  
  84.         button06.setHorizontalTextPosition(AbstractButton.CENTER);  
  85.         JButton button07 = new JButton("07",icon01);  
  86.         button07.setHorizontalTextPosition(AbstractButton.CENTER);  
  87.         JButton button08 = new JButton("08",icon01);  
  88.         button08.setHorizontalTextPosition(AbstractButton.CENTER);  
  89.         JButton button09 = new JButton("09",icon01);  
  90.         button09.setHorizontalTextPosition(AbstractButton.CENTER);  
  91.         JButton button10 = new JButton("10-28",icon01);  
  92.         button10.setHorizontalTextPosition(AbstractButton.CENTER);  
  93.         toolBar.add(KT);  
  94.         toolBar.add(button01);  
  95.         toolBar.add(button02);  
  96.         toolBar.add(button03);  
  97.         toolBar.add(button04);  
  98.         toolBar.add(button05);  
  99.         toolBar.add(button06);  
  100.         toolBar.add(button07);  
  101.         toolBar.add(button08);  
  102.         toolBar.add(button09);  
  103.         toolBar.add(button10);  
  104.           
  105.         contentPane.add(toolBar,BorderLayout.NORTH);  
  106.         contentPane.add(GLpanel,BorderLayout.CENTER);  
  107.         contentPane.add(JGpanel,BorderLayout.EAST);  
  108.         contentPane.add(KJpanel,BorderLayout.WEST);  
  109.         return contentPane;  
  110.     }  
  111.   
  112.     private JMenuBar createMenuBar() {  
  113.         JMenuBar menuBar = new JMenuBar();  
  114.         JMenu menu = new JMenu("关于(a)");  
  115.         JMenuItem menuItem1 = new JMenuItem("关于(a)");  
  116.         JMenuItem menuItem2 = new JMenuItem("退出(F4)");  
  117.         menuItem2.addActionListener(new ActionListener(){  
  118.             public void actionPerformed(ActionEvent e) {  
  119.                 String message = "确实要退出系统吗?";  
  120.                 String title = "确认对话框";  
  121.                 int messageType = JOptionPane.INFORMATION_MESSAGE;  
  122.                 int optionType = JOptionPane.YES_NO_OPTION;  
  123.                 int option = JOptionPane.showConfirmDialog(frame, message,title,optionType,messageType);  
  124.                 if(option == JOptionPane.YES_OPTION){  
  125.                     System.exit(0);  
  126.                 }  
  127.             }  
  128.         });  
  129.           
  130.         icon01= new ImageIcon("icon/021.png");  
  131.           
  132.         menuBar.add(menu);  
  133.         menu.add(menuItem1);  
  134.         menu.add(menuItem2);  
  135.         return menuBar;  
  136.     }  
  137.   
  138.     public static void main(String[] args) {  
  139.         new SSQ();  
  140.     }  
  141. }  

import java.awt.BorderLayout; import java.awt.Color; import java.awt.Container; import java.awt.Font; import java.awt.Image; import java.awt.Toolkit; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.AbstractButton; import javax.swing.ImageIcon; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JMenu; import javax.swing.JMenuBar; import javax.swing.JMenuItem; import javax.swing.JOptionPane; import javax.swing.JPanel; import javax.swing.JToolBar; import javax.swing.SwingConstants; import javax.swing.border.LineBorder; import javax.swing.border.TitledBorder; public class SSQ { JFrame frame; JPanel KJpanel,GLpanel,JGpanel; ImageIcon icon01; public SSQ(){ frame = new JFrame("大话双色球"); Image image = Toolkit.getDefaultToolkit().createImage(""); frame.setIconImage(image); frame.setJMenuBar(createMenuBar()); frame.setContentPane(createContentPane()); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setLocation(50,50); frame.setSize(800,500); frame.setVisible(true); } private Container createContentPane() { Container contentPane = frame.getContentPane(); JToolBar toolBar = new JToolBar(); JLabel KT = new JLabel("开头:"); KT.setFont(new Font("微软雅黑",Font.BOLD, 14)); KJpanel = new JPanel(); KJpanel.setSize(100, 100); KJpanel.setBorder(new TitledBorder("开奖")); KJpanel.add(new ReadKj()); GLpanel = new JPanel(); GLpanel.setBorder(new TitledBorder("过滤")); JGpanel = new JPanel(); JGpanel.setBorder(new TitledBorder("结果")); JButton button01 = new JButton("01",icon01); button01.setHorizontalTextPosition(AbstractButton.CENTER); button01.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e) { GLpanel.removeAll(); GLpanel.add(new Read01()); GLpanel.updateUI(); } }); System.gc(); JButton button02 = new JButton("02",icon01); button02.setHorizontalTextPosition(AbstractButton.CENTER); button02.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e) { GLpanel.removeAll(); GLpanel.add(new Read02()); GLpanel.updateUI(); } }); System.gc(); JButton button03 = new JButton("03",icon01); button03.setHorizontalTextPosition(AbstractButton.CENTER); JButton button04 = new JButton("04",icon01); button04.setHorizontalTextPosition(AbstractButton.CENTER); JButton button05 = new JButton("05",icon01); button05.setHorizontalTextPosition(AbstractButton.CENTER); JButton button06 = new JButton("06",icon01); button06.setHorizontalTextPosition(AbstractButton.CENTER); JButton button07 = new JButton("07",icon01); button07.setHorizontalTextPosition(AbstractButton.CENTER); JButton button08 = new JButton("08",icon01); button08.setHorizontalTextPosition(AbstractButton.CENTER); JButton button09 = new JButton("09",icon01); button09.setHorizontalTextPosition(AbstractButton.CENTER); JButton button10 = new JButton("10-28",icon01); button10.setHorizontalTextPosition(AbstractButton.CENTER); toolBar.add(KT); toolBar.add(button01); toolBar.add(button02); toolBar.add(button03); toolBar.add(button04); toolBar.add(button05); toolBar.add(button06); toolBar.add(button07); toolBar.add(button08); toolBar.add(button09); toolBar.add(button10); contentPane.add(toolBar,BorderLayout.NORTH); contentPane.add(GLpanel,BorderLayout.CENTER); contentPane.add(JGpanel,BorderLayout.EAST); contentPane.add(KJpanel,BorderLayout.WEST); return contentPane; } private JMenuBar createMenuBar() { JMenuBar menuBar = new JMenuBar(); JMenu menu = new JMenu("关于(a)"); JMenuItem menuItem1 = new JMenuItem("关于(a)"); JMenuItem menuItem2 = new JMenuItem("退出(F4)"); menuItem2.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e) { String message = "确实要退出系统吗?"; String title = "确认对话框"; int messageType = JOptionPane.INFORMATION_MESSAGE; int optionType = JOptionPane.YES_NO_OPTION; int option = JOptionPane.showConfirmDialog(frame, message,title,optionType,messageType); if(option == JOptionPane.YES_OPTION){ System.exit(0); } } }); icon01= new ImageIcon("icon/021.png"); menuBar.add(menu); menu.add(menuItem1); menu.add(menuItem2); return menuBar; } public static void main(String[] args) { new SSQ(); } }
B.设置表格颜色类:

 

 

  1. import java.awt.Color;  
  2. import java.awt.Component;  
  3.   
  4. import javax.swing.JTable;  
  5. import javax.swing.table.DefaultTableCellRenderer;  
  6.   
  7. public class RowRenderer extends DefaultTableCellRenderer   
  8. {  
  9.     public Component getTableCellRendererComponent(JTable t, Object value,  
  10.                 boolean isSelected, boolean hasFocus, int row, int column)   
  11.     {  
  12.         //设置奇偶行的背景色,可在此根据需要进行修改   
  13.         if (row == 0){  
  14.             setForeground(Color.BLUE);  
  15.         }  
  16.         if(row == 7){  
  17.             setForeground(Color.BLUE);  
  18.         }  
  19.         return super.getTableCellRendererComponent(t, value, isSelected,  
  20.                 hasFocus, row, column);  
  21.     }  
  22. }  

import java.awt.Color; import java.awt.Component; import javax.swing.JTable; import javax.swing.table.DefaultTableCellRenderer; public class RowRenderer extends DefaultTableCellRenderer { public Component getTableCellRendererComponent(JTable t, Object value, boolean isSelected, boolean hasFocus, int row, int column) { //设置奇偶行的背景色,可在此根据需要进行修改 if (row == 0){ setForeground(Color.BLUE); } if(row == 7){ setForeground(Color.BLUE); } return super.getTableCellRendererComponent(t, value, isSelected, hasFocus, row, column); } }
C.读入开奖数据类

 

 

  1. import java.awt.BorderLayout;  
  2. import java.awt.Color;  
  3. import java.awt.Component;  
  4. import java.awt.Dimension;  
  5. import java.awt.Point;  
  6. import java.awt.event.ActionEvent;  
  7. import java.awt.event.ActionListener;  
  8. import java.io.BufferedReader;  
  9. import java.io.FileNotFoundException;  
  10. import java.io.FileReader;  
  11. import java.io.IOException;  
  12. import java.util.Vector;  
  13.   
  14. import javax.swing.JButton;  
  15. import javax.swing.JLabel;  
  16. import javax.swing.JOptionPane;  
  17. import javax.swing.JPanel;  
  18. import javax.swing.JTable;  
  19. import javax.swing.JFrame;  
  20. import javax.swing.JScrollPane;  
  21. import javax.swing.JTextField;  
  22. import javax.swing.RowFilter;  
  23. import javax.swing.table.DefaultTableCellRenderer;  
  24. import javax.swing.table.DefaultTableModel;  
  25. import javax.swing.table.TableColumn;  
  26. import javax.swing.table.TableModel;  
  27. import javax.swing.table.TableRowSorter;  
  28.   
  29. public class ReadKj extends JPanel{  
  30.     JLabel labelZhu;  
  31.     JTable table;  
  32.     FileReader reader = null;  
  33.     BufferedReader br = null;  
  34.     Vector<Vector> rowData = null;  
  35.     public ReadKj(){  
  36.         Vector<String> col = new Vector<String>();  
  37.         col.addElement("期号");  
  38.         col.addElement("1");  
  39.         col.addElement("2");  
  40.         col.addElement("3");  
  41.         col.addElement("4");  
  42.         col.addElement("5");  
  43.         col.addElement("6");  
  44.         col.addElement("蓝球");  
  45.   
  46.         try{  
  47.             String txt = "kj.txt";  
  48.             reader = new FileReader(txt);  
  49.             br = new BufferedReader(reader);  
  50.   
  51.             String eachLine = null;  
  52.             rowData = new Vector<Vector>();  
  53.             while((eachLine = br.readLine()) != null){  
  54.                 String[] temp = eachLine.split(" ");  
  55.                 Vector<String> row = new Vector<String>();  
  56.                 for(int i = 0; i < temp.length; i++){  
  57.                     row.add(temp[i]);  
  58.                 }  
  59.                 rowData.add(row);//再把每一个row的数据给rowData   
  60.             }  
  61.             reader.close();  
  62.             br.close();  
  63.         }catch(FileNotFoundException e){  
  64.             String message = "读取01开关文件未找到!";  
  65.             String title = "文件错误";  
  66.             int messageType = JOptionPane.ERROR_MESSAGE;  
  67.             JOptionPane.showMessageDialog(this, message,title,messageType);  
  68.         }catch(IOException e){  
  69.             String message = "读取错误,你是否打开多个文件?";  
  70.             String title = "读取错误";  
  71.             int messageType = JOptionPane.ERROR_MESSAGE;  
  72.             JOptionPane.showMessageDialog(this, message,title,messageType);  
  73.         }catch(OutOfMemoryError e){  
  74.             String message = "读取错误,你是否打开多个文件?";  
  75.             String title = "读取错误";  
  76.             int messageType = JOptionPane.ERROR_MESSAGE;  
  77.             JOptionPane.showMessageDialog(this, message,title,messageType);  
  78.         }finally{  
  79.             try{  
  80.                 reader.close();  
  81.                 br.close();  
  82.             }catch(FileNotFoundException e){  
  83.                 String message = "读取01开关文件未找到!";  
  84.                 String title = "文件错误";  
  85.                 int messageType = JOptionPane.ERROR_MESSAGE;  
  86.                 JOptionPane.showMessageDialog(this, message,title,messageType);  
  87.             }catch(IOException e){  
  88.                 String message = "读取错误,你是否打开多个文件?";  
  89.                 String title = "读取错误";  
  90.                 int messageType = JOptionPane.ERROR_MESSAGE;  
  91.                 JOptionPane.showMessageDialog(this, message,title,messageType);  
  92.             }catch(OutOfMemoryError e){  
  93.                 String message = "读取错误,你是否打开多个文件?";  
  94.                 String title = "读取错误";  
  95.                 int messageType = JOptionPane.ERROR_MESSAGE;  
  96.                 JOptionPane.showMessageDialog(this, message,title,messageType);  
  97.             }  
  98.         }  
  99.           
  100.         DefaultTableModel model = new DefaultTableModel(rowData,col){  
  101.             public Class getColumnClass(int column) {     
  102.                 Class returnValue;     
  103.                 if ((column >= 0) && (column < getColumnCount())) {     
  104.                   returnValue = getValueAt(0, column).getClass();     
  105.                 } else {     
  106.                   returnValue = Object.class;     
  107.                 }     
  108.                 return returnValue;   
  109.               }  
  110.         };    
  111.         table = new JTable(model);  
  112.           
  113.         final TableRowSorter<TableModel> sorter = new TableRowSorter<TableModel>(model);  
  114.         table.setRowSorter(sorter);//设置排序   
  115.           
  116.         TableColumn col0 = table.getColumnModel().getColumn(0);//第一列   
  117.         col0.setPreferredWidth(150);  
  118.         col0.setCellRenderer(new RowRenderer());  
  119.         TableColumn col7 = table.getColumnModel().getColumn(7);//最后一列   
  120.         col7.setCellRenderer(new RowRenderer());  
  121.         table.setSelectionForeground(Color.red);//选择时的颜色   
  122.         table.setPreferredScrollableViewportSize(new Dimension(300,400));  
  123.         JScrollPane scrollPane = new JScrollPane(table);  
  124.           
  125.         this.setLayout(new BorderLayout());  
  126.           
  127.         JPanel panelTable = new JPanel();  
  128.         panelTable.add(scrollPane);  
  129.           
  130.         JPanel panelLabel = new JPanel();  
  131.         JLabel labelZhushu = new JLabel("至今开奖期数:");  
  132.         labelZhu = new JLabel();  
  133.         labelZhu.setText(""+(table.getRowCount()));  
  134.         panelLabel.add(labelZhushu);  
  135.         panelLabel.add(labelZhu);  
  136.           
  137.         JPanel panelBianji = new JPanel();  
  138.         final JTextField text1 = new JTextField(10);  
  139.         JButton buttonGL = new JButton("查询");  
  140.           
  141.         buttonGL.addActionListener(new ActionListener() {  
  142.               public void actionPerformed(ActionEvent e) {  
  143.                 String text = text1.getText();  
  144.                 if (text.length() == 0) {  
  145.                   sorter.setRowFilter(null);  
  146.                   labelZhu.setText(""+(table.getRowCount()));  
  147.                 } else {  
  148.                   sorter.setRowFilter(RowFilter.regexFilter(text));  
  149.                   labelZhu.setText(""+(table.getRowCount()));  
  150.                 }  
  151.               }  
  152.             });  
  153.           
  154.         panelBianji.add(text1);  
  155.         panelBianji.add(buttonGL);  
  156.         panelLabel.add(panelBianji);  
  157.           
  158.         this.add(panelTable,BorderLayout.NORTH);  
  159.         this.add(panelLabel,BorderLayout.SOUTH);  
  160.         //this.add(panelBianji,panelLabel.BOTTOM_ALIGNMENT);   
  161.     }  
  162. }  

import java.awt.BorderLayout; import java.awt.Color; import java.awt.Component; import java.awt.Dimension; import java.awt.Point; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.io.BufferedReader; import java.io.FileNotFoundException; import java.io.FileReader; import java.io.IOException; import java.util.Vector; import javax.swing.JButton; import javax.swing.JLabel; import javax.swing.JOptionPane; import javax.swing.JPanel; import javax.swing.JTable; import javax.swing.JFrame; import javax.swing.JScrollPane; import javax.swing.JTextField; import javax.swing.RowFilter; import javax.swing.table.DefaultTableCellRenderer; import javax.swing.table.DefaultTableModel; import javax.swing.table.TableColumn; import javax.swing.table.TableModel; import javax.swing.table.TableRowSorter; public class ReadKj extends JPanel{ JLabel labelZhu; JTable table; FileReader reader = null; BufferedReader br = null; Vector<Vector> rowData = null; public ReadKj(){ Vector<String> col = new Vector<String>(); col.addElement("期号"); col.addElement("1"); col.addElement("2"); col.addElement("3"); col.addElement("4"); col.addElement("5"); col.addElement("6"); col.addElement("蓝球"); try{ String txt = "kj.txt"; reader = new FileReader(txt); br = new BufferedReader(reader); String eachLine = null; rowData = new Vector<Vector>(); while((eachLine = br.readLine()) != null){ String[] temp = eachLine.split(" "); Vector<String> row = new Vector<String>(); for(int i = 0; i < temp.length; i++){ row.add(temp[i]); } rowData.add(row);//再把每一个row的数据给rowData } reader.close(); br.close(); }catch(FileNotFoundException e){ String message = "读取01开关文件未找到!"; String title = "文件错误"; int messageType = JOptionPane.ERROR_MESSAGE; JOptionPane.showMessageDialog(this, message,title,messageType); }catch(IOException e){ String message = "读取错误,你是否打开多个文件?"; String title = "读取错误"; int messageType = JOptionPane.ERROR_MESSAGE; JOptionPane.showMessageDialog(this, message,title,messageType); }catch(OutOfMemoryError e){ String message = "读取错误,你是否打开多个文件?"; String title = "读取错误"; int messageType = JOptionPane.ERROR_MESSAGE; JOptionPane.showMessageDialog(this, message,title,messageType); }finally{ try{ reader.close(); br.close(); }catch(FileNotFoundException e){ String message = "读取01开关文件未找到!"; String title = "文件错误"; int messageType = JOptionPane.ERROR_MESSAGE; JOptionPane.showMessageDialog(this, message,title,messageType); }catch(IOException e){ String message = "读取错误,你是否打开多个文件?"; String title = "读取错误"; int messageType = JOptionPane.ERROR_MESSAGE; JOptionPane.showMessageDialog(this, message,title,messageType); }catch(OutOfMemoryError e){ String message = "读取错误,你是否打开多个文件?"; String title = "读取错误"; int messageType = JOptionPane.ERROR_MESSAGE; JOptionPane.showMessageDialog(this, message,title,messageType); } } DefaultTableModel model = new DefaultTableModel(rowData,col){ public Class getColumnClass(int column) { Class returnValue; if ((column >= 0) && (column < getColumnCount())) { returnValue = getValueAt(0, column).getClass(); } else { returnValue = Object.class; } return returnValue; } }; table = new JTable(model); final TableRowSorter<TableModel> sorter = new TableRowSorter<TableModel>(model); table.setRowSorter(sorter);//设置排序 TableColumn col0 = table.getColumnModel().getColumn(0);//第一列 col0.setPreferredWidth(150); col0.setCellRenderer(new RowRenderer()); TableColumn col7 = table.getColumnModel().getColumn(7);//最后一列 col7.setCellRenderer(new RowRenderer()); table.setSelectionForeground(Color.red);//选择时的颜色 table.setPreferredScrollableViewportSize(new Dimension(300,400)); JScrollPane scrollPane = new JScrollPane(table); this.setLayout(new BorderLayout()); JPanel panelTable = new JPanel(); panelTable.add(scrollPane); JPanel panelLabel = new JPanel(); JLabel labelZhushu = new JLabel("至今开奖期数:"); labelZhu = new JLabel(); labelZhu.setText(""+(table.getRowCount())); panelLabel.add(labelZhushu); panelLabel.add(labelZhu); JPanel panelBianji = new JPanel(); final JTextField text1 = new JTextField(10); JButton buttonGL = new JButton("查询"); buttonGL.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { String text = text1.getText(); if (text.length() == 0) { sorter.setRowFilter(null); labelZhu.setText(""+(table.getRowCount())); } else { sorter.setRowFilter(RowFilter.regexFilter(text)); labelZhu.setText(""+(table.getRowCount())); } } }); panelBianji.add(text1); panelBianji.add(buttonGL); panelLabel.add(panelBianji); this.add(panelTable,BorderLayout.NORTH); this.add(panelLabel,BorderLayout.SOUTH); //this.add(panelBianji,panelLabel.BOTTOM_ALIGNMENT); } }
D.读入01开奖号码类

 

 

  1. import java.awt.BorderLayout;  
  2. import java.awt.Color;  
  3. import java.awt.Dimension;  
  4. import java.awt.GridLayout;  
  5. import java.awt.Point;  
  6. import java.awt.event.ActionEvent;  
  7. import java.awt.event.ActionListener;  
  8. import java.io.BufferedReader;  
  9. import java.io.FileNotFoundException;  
  10. import java.io.FileReader;  
  11. import java.io.IOException;  
  12. import java.util.Vector;  
  13.   
  14. import javax.swing.JCheckBox;  
  15. import javax.swing.JLabel;  
  16. import javax.swing.JOptionPane;  
  17. import javax.swing.JPanel;  
  18. import javax.swing.JTable;  
  19. import javax.swing.JFrame;  
  20. import javax.swing.JScrollPane;  
  21. import javax.swing.border.Border;  
  22. import javax.swing.border.TitledBorder;  
  23. import javax.swing.table.DefaultTableModel;  
  24. import javax.swing.table.TableColumn;  
  25. import javax.swing.table.TableModel;  
  26. import javax.swing.table.TableRowSorter;  
  27.   
  28. public class Read01 extends JPanel{  
  29.     FileReader reader = null;  
  30.     BufferedReader br = null;  
  31.     Vector<Vector> rowData = null;  
  32.     JTable table ;  
  33.     public Read01(){  
  34.         Vector<String> col = new Vector<String>();  
  35.         col.addElement("1");  
  36.         col.addElement("2");  
  37.         col.addElement("3");  
  38.         col.addElement("4");  
  39.         col.addElement("5");  
  40.         col.addElement("6");  
  41.   
  42.         try{  
  43.             String txt = "01.txt";  
  44.             reader = new FileReader(txt);  
  45.             br = new BufferedReader(reader);  
  46.   
  47.             String eachLine = null;  
  48.             rowData = new Vector<Vector>();  
  49.             while((eachLine = br.readLine()) != null){  
  50.                 String[] temp = eachLine.split(" ");  
  51.                 Vector<String> row = new Vector<String>();  
  52.                 for(int i = 0; i < temp.length; i++){  
  53.                     row.add(temp[i]);  
  54.                 }  
  55.                 rowData.add(row);//再把每一个row的数据给rowData   
  56.             }  
  57.             reader.close();  
  58.             br.close();  
  59.         }catch(FileNotFoundException e){  
  60.             String message = "读取01数据文件未找到!";  
  61.             String title = "文件错误";  
  62.             int messageType = JOptionPane.ERROR_MESSAGE;  
  63.             JOptionPane.showMessageDialog(this, message,title,messageType);  
  64.         }catch(IOException e){  
  65.             String message = "读取错误,你是否打开多个文件?";  
  66.             String title = "读取错误";  
  67.             int messageType = JOptionPane.ERROR_MESSAGE;  
  68.             JOptionPane.showMessageDialog(this, message,title,messageType);  
  69.         }catch(OutOfMemoryError e){  
  70.             String message = "读取错误,你是否打开多个文件?";  
  71.             String title = "读取错误";  
  72.             int messageType = JOptionPane.ERROR_MESSAGE;  
  73.             JOptionPane.showMessageDialog(this, message,title,messageType);  
  74.         }finally{  
  75.             try{  
  76.                 reader.close();  
  77.                 br.close();  
  78.             }catch(FileNotFoundException e){  
  79.                 String message = "读取01开关文件未找到!";  
  80.                 String title = "文件错误";  
  81.                 int messageType = JOptionPane.ERROR_MESSAGE;  
  82.                 JOptionPane.showMessageDialog(this, message,title,messageType);  
  83.             }catch(IOException e){  
  84.                 String message = "读取错误,你是否打开多个文件?";  
  85.                 String title = "读取错误";  
  86.                 int messageType = JOptionPane.ERROR_MESSAGE;  
  87.                 JOptionPane.showMessageDialog(this, message,title,messageType);  
  88.             }catch(OutOfMemoryError e){  
  89.                 String message = "读取错误,你是否打开多个文件?";  
  90.                 String title = "读取错误";  
  91.                 int messageType = JOptionPane.ERROR_MESSAGE;  
  92.                 JOptionPane.showMessageDialog(this, message,title,messageType);  
  93.             }  
  94.         }  
  95.         DefaultTableModel model = new DefaultTableModel(rowData,col);  
  96.         table = new JTable(model);  
  97.           
  98.         TableColumn col0 = table.getColumnModel().getColumn(0);//第一列   
  99.           
  100.         TableRowSorter<TableModel> sorter = new TableRowSorter<TableModel>(model);  
  101.         table.setRowSorter(sorter);//设置排序   
  102.         table.setSelectionBackground(Color.green);//选择时的颜色   
  103.           
  104.         table.setPreferredScrollableViewportSize(new Dimension(200,400));  
  105.         JScrollPane scrollPane = new JScrollPane(table);  
  106.           
  107.         this.setLayout(new BorderLayout());  
  108.         JPanel panel = new JPanel();//整体panel   
  109.         panel.setLayout(new BorderLayout());  
  110.           
  111.           
  112.         JPanel panelTable = new JPanel();//表格panel   
  113.         panelTable.add(scrollPane);  
  114.           
  115.         JPanel panelCheckBox = new JPanel();//选择器panel   
  116.         panelCheckBox.setBorder(new TitledBorder("去掉"));  
  117.         panelCheckBox.setLayout(new GridLayout(0,1));     
  118.         JCheckBox check6 = new JCheckBox("6连号");  
  119.         JCheckBox check5 = new JCheckBox("5连号");  
  120.         JCheckBox check4 = new JCheckBox("4连号");  
  121.         JCheckBox check3 = new JCheckBox("3连号");  
  122.         JCheckBox check2 = new JCheckBox("2连号");  
  123.   
  124.         panelCheckBox.add(check6);  
  125.         panelCheckBox.add(check5);  
  126.         panelCheckBox.add(check4);  
  127.         panelCheckBox.add(check3);  
  128.         panelCheckBox.add(check2);  
  129.           
  130.         JPanel panelLabel = new JPanel();  
  131.         JLabel labelZhu = new JLabel();  
  132.         labelZhu.setText(""+(table.getRowCount()+1));  
  133.         JLabel labelZhushu = new JLabel("总计注数:" );  
  134.         panelLabel.add(labelZhushu);  
  135.         panelLabel.add(labelZhu);  
  136.   
  137.         panel.add(panelTable,BorderLayout.WEST);  
  138.         panel.add(panelCheckBox,BorderLayout.EAST);  
  139.         panel.add(panelLabel,BorderLayout.SOUTH);  
  140.         this.add(panel);  
  141.     }  
  142. }  
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值