package Frame; import java.awt.BorderLayout; import java.awt.Color; import java.awt.Component; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.event.KeyEvent; import java.awt.event.KeyListener; import java.util.Iterator; import java.util.List; import java.util.Vector; import javax.swing.Box; import javax.swing.ImageIcon; import javax.swing.JPanel; import javax.swing.JProgressBar; import javax.swing.JScrollPane; import javax.swing.JTable; import javax.swing.JTextField; import javax.swing.table.DefaultTableModel; import javax.swing.table.TableCellRenderer; import javax.swing.table.TableColumn; import ColorAndFont.English; import ColorAndFont.UIColor; import ColorAndFont.buttonTitle; import Judge.JugeNumber; import PbuliClass.JButtonModel; import PbuliClass.OutButton; import PbuliClass.ShowMessage; import PbuliClass.Systems; import PbuliClass.greateTables; import PbuliClass.jinternalFrame; import person.Person; import person.person_Dell; import tag.Tag_Dell; @SuppressWarnings("rawtypes") public class TagPowerManage extends jinternalFrame { /** * */ private static final long serialVersionUID = 1L; JPanel inJpanel=null;//ÄÚ²¿Ãæ°å JPanel northJpanel=null;//±±²¿Ãæ°å JPanel centerJpanel=null;//Öв¿Ãæ°å JTextField searchFileld=null;//ËÑË÷Îı¾¿ò JButtonModel search=null;//ËÑË÷°´Å¥ JButtonModel shuaxin=null;//ˢа´Å¥ JButtonModel delete=null;//ɾ³ý°´Å¥ JButtonModel deleteAll=null;//È«²¿É¾³ý°´Å¥ JButtonModel outport=null;//µ¼³ö±í¸ñ°´Å¥ JTable table=null;//ÉêÃ÷±í¸ñ Vector rowData=null; DefaultTableModel tableModel;//±í¸ñÄ£ÐÍ List list; OutButton outbt=new OutButton(); JScrollPane gd; public TagPowerManage() { rowData=new Vector(); String title="ʵʱµçÁ¿"; if(Systems.sys().getLanguage().equals("English")) { title="Tag Real-time power"; } this.setTitle(title); this.setFrameIcon(new ImageIcon("image/icon/powericon.png"));//ÉèÖô°Ìåͼ±ê this.add(getInJpanel()); } /**»ñÈ¡ÄÚ²¿´°ÌåµÄÄÚ²¿Ãæ°å*/ public JPanel getInJpanel() { if(inJpanel==null) { inJpanel=new JPanel(); inJpanel.setLayout(new BorderLayout());//ÉèÖÃÃæ°åΪ±ß½ç²¼¾Ö inJpanel.setBackground(Color.WHITE);//ÉèÖÃÃæ°å±³¾°Îª°×É« inJpanel.add(getNorthJpanel(),BorderLayout.NORTH); inJpanel.add(getGd(),BorderLayout.CENTER); } return inJpanel; } /**»ñÈ¡±±²¿Ãæ°å*/ public JPanel getNorthJpanel() { if(northJpanel==null) { northJpanel=new JPanel(); Box topicBox = Box.createHorizontalBox();// ´´½¨Ò»¸öˮƽÏäÈÝÆ÷ topicBox.add(getSearchFileld());//Ìí¼ÓËÑË÷Îı¾¿ò topicBox.add(Box.createHorizontalStrut(3));// Ìí¼ÓÒ»¸ö3ÏñËØ¿íµÄˮƽ֧Öù topicBox.add(getSearch());//Ìí¼ÓËÑË÷°´Å¥ topicBox.add(Box.createHorizontalStrut(20));// Ìí¼ÓÒ»¸ö5ÏñËØ¿íµÄˮƽ֧Öù topicBox.add(getShuaxin());//Ìí¼Óˢа´Å¥ topicBox.add(Box.createHorizontalStrut(20));// Ìí¼ÓÒ»¸ö5ÏñËØ¿íµÄˮƽ֧Öù topicBox.add(getOutport());//Ìí¼Óµ¼³ö°´Å¥ northJpanel.add(topicBox ); } return northJpanel; } /**»ñÈ¡ËÑË÷Îı¾¿òµÄ·½·¨*/ public JTextField getSearchFileld() { if(searchFileld==null){ searchFileld=new JTextField(10); searchFileld.addKeyListener(new KeyListener() { //¼üÅÌʼþ¼àÌý public void keyTyped(KeyEvent e) { } public void keyReleased(KeyEvent e) { int keyCode=e.getKeyCode(); if(keyCode==KeyEvent.VK_ENTER) { getSearch().doClick();//ËÑË÷°´Å¥±»µã»÷ } } public void keyPressed(KeyEvent e) { } }); } return searchFileld; } /**»ñÈ¡ËÑË÷°´Å¥µÄ·½·¨*/ public JButtonModel getSearch() { if(search==null){ search=new JButtonModel(buttonTitle.getSerch()); search.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { updateSerch(getSearchFileld().getText()); } }); } return search; } /**»ñȡˢа´Å¥µÄ·½·¨*/ public JButtonModel getShuaxin() { if(shuaxin==null){ shuaxin=new JButtonModel(buttonTitle.getRefresh()); shuaxin.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { updateTable(); } }); } return shuaxin; } /**»ñȡɾ³ý°´Å¥µÄ·½·¨*/ public JButtonModel getDelete() { if(delete==null){ delete=new JButtonModel(buttonTitle.getDelete()); delete.setEnabled(false); delete.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { } }); } return delete; } /**»ñȡȫ²¿É¾³ý°´Å¥µÄ·½·¨*/ public JButtonModel getDeleteAll() { if(deleteAll==null){ deleteAll=new JButtonModel(buttonTitle.getDeleteall()); deleteAll.setEnabled(false); deleteAll.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { // //Ñ¡Ôñ¶Ô»°¿òÈçyes·µ»Ø0£¬NO·µ»Ø1£¬È¡Ïû·µ»Ø2 // WarningMessage warning=new WarningMessage(); // warning.setMessage("Ñ¡Ôñɾ³ýÈ«²¿½«»á°Ñ±í¸ñÊý¾ÝÈ«²¿É¾³ýÈ·¶¨Âð£¿"); // int warn=warning.getwarMss(getInJpanel() ); // int tagnum=table.getRowCount();//±í¸ñ×ÜÐÐÊý // if(tagnum!=0 && warn==0) { // String deleteSql="TRUNCATE TABLE tb_tagpower"; // DatabaseManagement.update(deleteSql);// ɾ³ýËùÓмǼ // JOptionPane.showMessageDialog(northJpanel, "È«²¿É¾³ý³É¹¦£¡", "ÌáʾÐÅÏ¢", // JOptionPane.INFORMATION_MESSAGE);// µ¯³öÌáʾ¿ò // } // updateTable();//ˢбí¸ñ } }); } return deleteAll; } /**»ñÈ¡µ¼³ö±í¸ñ°´Å¥µÄ·½·¨*/ public JButtonModel getOutport() { OutButton.setAddtime("addtime"); OutButton.setDataName("tb_tag"); return new OutButton().get_ouotport_button(); } /**»ñÈ¡¹ö¶¯Ãæ°åµÄ·½·¨*/ public JScrollPane getGd() { gd=new JScrollPane(getTable()); gd.getViewport().setBackground(UIColor.getNorth_color()); return gd; } /**Ìí¼Ó±í¸ñÐÐÏòÁ¿Êý¾Ý·½·¨*/ @SuppressWarnings("unchecked") public void getRowData(Vector list ) { Iterator iterator = list.iterator();//´´½¨µü´úÆ÷ while (iterator.hasNext()) {//µü´úÆ÷´æÔÚÔªËØ Person pr = iterator.next();//½«µü´úÆ÷ÀïÃæµÄÔªËØ¸øµ½info¼¯ºÏ Vector rowV = new Vector(); rowV.add(pr.getP_name());// ÐòºÅ rowV.add(pr.getP_tagid());// ±êÇ©ID rowV.add(pr.getHz());//±êǩƵÂÊ String pw=pr.getP_power(); int pwr=0; if(pw ==null) { pw="δ֪"; }else { if(JugeNumber.isDigit(pw)) { pwr=Integer.parseInt(pw); if(pwr>100) { pw="100"; pwr=100; } }else { pw="δ֪"; } } rowV.add(pw);// ±êÇ©µçÁ¿ rowV.add(pwr);// µçÁ¿×´Ì¬ rowV.add(pr.getP_addtiem());// ¸üÐÂʱ¼ä tableModel.addRow(rowV);// Ïò±í¸ñ¶ÔÏóÌí¼ÓÐÐÊý¾Ý } } /**»ñÈ¡±êÇ©µçÁ¿±í¸ñµÄ·½·¨*/ @SuppressWarnings("serial") public JTable getTable() { if(table==null) { String[] name1= {"ÐÕÃû","±êÇ©ID","±êǩƵÂÊ(Hz)","µçÁ¿(%)","µçÁ¿×´Ì¬","¸üÐÂʱ¼ä"};//±í¸ñÁÐÃû String[] name2= {"Name","ID","Hz","Battery (%)","Status","Time"};//±í¸ñÁÐÃû String[] columnNames=English.columnNames(name1, name2); //Ìí¼Ó±í¸ñÁÐÏòÁ¿ Vector columnName=new Vector<>(); for(int i=0;i0) { bar.setForeground(Color.red);//ÏÔʾ½ø¶ÈÌõµÄÑÕÉ« }else if(percent>15){ bar.setForeground(Color.green);//ÏÔʾ½ø¶ÈÌõµÄÑÕÉ« }else if(percent==-1){ bar.setForeground(Color.white);//ÏÔʾ½ø¶ÈÌõµÄÑÕÉ« } bar.setBackground(null); bar.setBorderPainted(false);//ÊÇ·ñÏÔʾ½ø¶ÈÌõ±ß¿ò if (row % 2 == 0) { bar.setBackground(UIColor.getTable_1()); } else { bar.setBackground(UIColor.getTable_2()); } if(isSelected) { bar.setBackground(Color.yellow); } return bar;// °Ñͼ±ê×÷ΪΪäÖȾ¿Ø¼þ } else { return null; } } }); } return table; } /**ˢбí¸ñ·½·¨*/ public void updateTable() { if(tableModel !=null) { tableModel.getDataVector().clear(); getRowData(person_Dell.getPerson_vector()); gd.validate(); } } /**ËÑË÷·½·¨*/ public void updateSerch(String serch) { if(Tag_Dell.serchtag(serch).size() ==0) { ShowMessage.zidingyi("ÄãËÑË÷µÄ"+serch+"²»´æÔÚ£¡"); return; } int tagnum=getTable().getRowCount();//±í¸ñ×ÜÐÐÊý if(tagnum !=0 ) { for (int i = 0; i < tagnum; i++) {//ɾ³ýËùÓÐÐÐ tableModel.removeRow(0); } getRowData(person_Dell.getPerson_vector()); } } }