package Frame; import java.awt.BorderLayout; import java.awt.Color; import java.awt.Container; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.io.File; import java.io.FileWriter; import java.io.IOException; import javax.swing.Box; import javax.swing.ImageIcon; import javax.swing.JFileChooser; import javax.swing.JPanel; import javax.swing.JScrollPane; import javax.swing.JTextArea; import javax.swing.event.InternalFrameEvent; import javax.swing.event.InternalFrameListener; import ColorAndFont.buttonTitle; import PbuliClass.JButtonModel; import PbuliClass.JCheckBoxModel; import PbuliClass.JlableModel; import PbuliClass.ShowMessage; import PbuliClass.Systems; import PbuliClass.jinternalFrame; /**²é¿´ÊµÊ±±¨ÎÄ*/ public class ModBusManage extends jinternalFrame { /** * */ private static final long serialVersionUID = 1L; static JTextArea textArea=null; JButtonModel start=null;//¿ªÊ¼°´Å¥ JButtonModel stop=null;//Í£Ö¹°´Å¥ JButtonModel save=null;//±£´æ°´Å¥ JButtonModel clear=null;//Çå¿Õ±¨ÎÄ JCheckBoxModel mod_start=null; JlableModel mod_port=new JlableModel("¼àÌý¶Ë¿Ú:"); JlableModel mod_adress=new JlableModel("ÆðʼµØÖ·:"); JlableModel mod_lenth=new JlableModel("Êý¾Ý³¤¶È:"); JlableModel mod_id=new JlableModel("µ¥ÔªID:"); JPanel mb1=null; JPanel mb2=null; JScrollPane scrollPane=null; String message=null; static boolean star=false; static boolean ceshi=true; public ModBusManage() { String title="ÆøÌå¼ì²â±¨ÎÄ"; if(Systems.sys().getLanguage().equals("English")) { title="Gas detection message"; } this.setTitle(title); this.addInternalFrameListener(new InternalFrameListener() { public void internalFrameOpened(InternalFrameEvent e) { } public void internalFrameIconified(InternalFrameEvent e) { } public void internalFrameDeiconified(InternalFrameEvent e) { } public void internalFrameDeactivated(InternalFrameEvent e) { } public void internalFrameClosing(InternalFrameEvent e) { } public void internalFrameClosed(InternalFrameEvent e) { star=false; ceshi=true; textArea=null; } public void internalFrameActivated(InternalFrameEvent e) { } }); Container rq=getContentPane();//»ñÈ¡ÈÝÆ÷ rq.setLayout(new BorderLayout()); rq.setBackground(Color.white); rq.add(getMb1(),BorderLayout.NORTH); rq.add(getGd(),BorderLayout.CENTER); // rq.add(getMb2(),BorderLayout.SOUTH); this.setFrameIcon(new ImageIcon("image/icon/TCP.png"));//ÉèÖô°Ìåͼ±ê } public static JTextArea get_text_area() { if(textArea==null) { textArea=new JTextArea(10,10); } return textArea; } public static boolean getStar() { return star; } public static boolean get_ceshi() { return ceshi; } public JPanel getMb1() { if(mb1==null) { mb1=new JPanel(); mb1.setBackground(Color.white); Box topicBox = Box.createHorizontalBox();// ´´½¨Ò»¸öˮƽÏäÈÝÆ÷ topicBox.add(getStart()); topicBox.add(Box.createHorizontalStrut(15));// Ìí¼ÓÒ»¸ö3ÏñËØ¿íµÄˮƽ֧Öù topicBox.add(getStop()); topicBox.add(Box.createHorizontalStrut(15));// Ìí¼ÓÒ»¸ö3ÏñËØ¿íµÄˮƽ֧Öù topicBox.add(getClear()); topicBox.add(Box.createHorizontalStrut(15));// Ìí¼ÓÒ»¸ö3ÏñËØ¿íµÄˮƽ֧Öù topicBox.add(getSave()); mb1.add(topicBox); } return mb1; } public JPanel getMb2() { if(mb2==null) { mb2=new JPanel(); mb2.setBackground(Color.white); Box topicBox = Box.createHorizontalBox();// ´´½¨Ò»¸öˮƽÏäÈÝÆ÷ topicBox.add(mod_port); topicBox.add(Box.createHorizontalStrut(15));// Ìí¼ÓÒ»¸ö3ÏñËØ¿íµÄˮƽ֧Öù topicBox.add(mod_adress); topicBox.add(Box.createHorizontalStrut(15));// Ìí¼ÓÒ»¸ö3ÏñËØ¿íµÄˮƽ֧Öù topicBox.add(mod_lenth); topicBox.add(Box.createHorizontalStrut(15));// Ìí¼ÓÒ»¸ö3ÏñËØ¿íµÄˮƽ֧Öù topicBox.add(mod_id); mb2.add(topicBox); } return mb2; } /**»ñÈ¡¹ö¶¯Ãæ°å*/ public JScrollPane getGd() { if(scrollPane==null) { scrollPane=new JScrollPane(get_text_area()); } return scrollPane; } /**»ñÈ¡¿ªÊ¼°´Å¥*/ public JButtonModel getStart() { if(start==null) { start=new JButtonModel("¿ªÊ¼"); start.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { textArea.setText("Æô¶¯¼àÌý£¡\n"); star=true; } }); } return start; } /**»ñÈ¡ÔÝÍ£°´Å¥*/ public JButtonModel getStop() { if(stop==null) { stop=new JButtonModel("ÔÝÍ£"); stop.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { star=false; textArea.setText("ÒÑÔÝÍ£¼àÌý£¡\n"); } }); } return stop; } /**»ñÈ¡±£´æ°´Å¥*/ public JButtonModel getSave() { if(save==null) { save=new JButtonModel(buttonTitle.getSave()); save.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { star=false; JFileChooser chooser = new JFileChooser( "./savefile/");// °Ñ¡°./backup/¡±×÷Ϊ·¾¶´´½¨ÎļþÑ¡ÔñÆ÷ int option=chooser.showSaveDialog(getMb1()); //Èç¹ûÈ·¶¨Ôò·µ»Ø0£¬È¡Ïû»ò¹Ø±Õ·µ»Ø1 String path=chooser.getSelectedFile()+".txt";//Îļþ±£´æÂ·¾¶ File file=new File(path); //Èç¹ûÑ¡ÔñµÄÊÇÈ·¶¨Ö´ÐÐÈçϱ£´æ²Ù×÷ if(option==JFileChooser.APPROVE_OPTION) {//Ñ¡ÔñÈ·ÈÏ£¨yes¡¢ok£©ºó·µ»Ø¸ÃÖµ try { file.createNewFile(); FileWriter out=new FileWriter(file);//ÎļþÊä³ö×Ö·ûÁ÷ out.write(textArea.getText()); out.close(); ShowMessage.saveSuccess(); } catch (IOException e1) { e1.printStackTrace(); } } } }); } return save; } public JButtonModel getClear() { if(clear==null) { clear=new JButtonModel("Çå ¿Õ"); clear.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { textArea.setText(""); } }); } return clear; } }