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.ShowMessage; import PbuliClass.Systems; import PbuliClass.jinternalFrame; /**²é¿´ÊµÊ±±¨ÎÄ*/ public class LookUdpTxt extends jinternalFrame { /** * */ private static final long serialVersionUID = 1L; JButtonModel start=null;//¿ªÊ¼°´Å¥ JButtonModel stop=null;//Í£Ö¹°´Å¥ JButtonModel save=null;//±£´æ°´Å¥ JButtonModel clear=null;//Çå¿Õ±¨ÎÄ JButtonModel justDisplay=null;//Ö»¿´Î»Öñ¨ÎÄ JButtonModel justWaring=null;//Ö»¿´¸æ¾¯±¨ÎÄ JButtonModel lookAll=null;//²é¿´È«²¿±¨ÎÄ static JTextArea textArea=null; JPanel mb1=null; JScrollPane scrollPane=null; String message=null; static boolean st=false; static boolean just_look_display=false; static boolean just_look_warning=false; static boolean look_all=true; public LookUdpTxt() { String title="ʵʱ±¨ÎÄÐÅÏ¢²é¿´"; if(Systems.sys().getLanguage().equals("English")) { title="Real-time message information view"; } 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) { st=false; 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); this.setFrameIcon(new ImageIcon("image/icon/udpicon.png"));//ÉèÖô°Ìåͼ±ê } public static JTextArea getAreaTxt() { if(textArea==null) { textArea=new JTextArea(10,10);//Îı¾Óò¶ÔÏó } return textArea; } public static boolean getSt() { return st; } public static boolean getJust_look_display() { return just_look_display; } public static boolean getJust_look_warning() { return just_look_warning; } public static boolean getLook_all() { return look_all; } 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(getJustDisplay());// topicBox.add(Box.createHorizontalStrut(15));// Ìí¼ÓÒ»¸ö3ÏñËØ¿íµÄˮƽ֧Öù topicBox.add(getJustWaring());// topicBox.add(Box.createHorizontalStrut(15));// Ìí¼ÓÒ»¸ö3ÏñËØ¿íµÄˮƽ֧Öù topicBox.add(getJustDisplay());// topicBox.add(Box.createHorizontalStrut(15));// Ìí¼ÓÒ»¸ö3ÏñËØ¿íµÄˮƽ֧Öù topicBox.add(getLookAll());// topicBox.add(Box.createHorizontalStrut(15));// Ìí¼ÓÒ»¸ö3ÏñËØ¿íµÄˮƽ֧Öù topicBox.add(getSave());//Ìí¼ÓËÑË÷°´Å¥ mb1.add(topicBox); } return mb1; } /**»ñÈ¡¹ö¶¯Ãæ°å*/ public JScrollPane getGd() { if(scrollPane==null) { scrollPane=new JScrollPane(getAreaTxt()); } return scrollPane; } /**»ñÈ¡¿ªÊ¼°´Å¥*/ public JButtonModel getStart() { if(start==null) { start=new JButtonModel("¿ªÊ¼"); start.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { textArea.setText(" ÒÑÆô¶¯¼àÌý£¡\n"); st=true; } }); } return start; } /**»ñÈ¡ÔÝÍ£°´Å¥*/ public JButtonModel getStop() { if(stop==null) { stop=new JButtonModel("ÔÝÍ£"); stop.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { st=false; } }); } return stop; } /**»ñÈ¡ÔÝÍ£°´Å¥*/ public JButtonModel getSave() { if(save==null) { save=new JButtonModel(buttonTitle.getSave()); save.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { st=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(); st=true; } 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; } /**Ö»¿´Î»Öñ¨ÎÄÊý¾Ý*/ public JButtonModel getJustDisplay() { if(justDisplay==null) { justDisplay=new JButtonModel("λÖñ¨ÎÄ"); justDisplay.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { textArea.setText(""); just_look_warning=false; look_all=false; just_look_display=true; } }); } return justDisplay; } /**Ö»¿´¸æ¾¯±¨ÎÄÊý¾Ý*/ public JButtonModel getJustWaring() { if(justWaring==null) { justWaring=new JButtonModel("¸æ¾¯±¨ÎÄ"); justWaring.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { textArea.setText(""); look_all=false; just_look_display=false; just_look_warning=true; } }); } return justWaring; } /**²é¿´È«²¿±¨ÎÄÊý¾Ý*/ public JButtonModel getLookAll() { if(lookAll==null) { lookAll=new JButtonModel("È«²¿±¨ÎÄ"); lookAll.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { textArea.setText(""); just_look_warning=false; just_look_display=false; look_all=true; } }); } return lookAll; } }