zoukankan      html  css  js  c++  java
  • 界面

    import java.awt.Font;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import java.awt.event.KeyEvent;
    
    import javax.swing.ButtonGroup;
    import javax.swing.JButton;
    import javax.swing.JFrame;
    import javax.swing.JLabel;
    import javax.swing.JOptionPane;
    import javax.swing.JPanel;
    import javax.swing.JRadioButton;
    
    class TestFrame implements ActionListener
    {
    
        JButton savebutton = null;
        JRadioButton dnYesButton = null;
        JRadioButton dnNoBUtton = null;
    
        private PlmnSwitchFileManager plmnSwitchFileManager = PlmnSwitchFileManager.getInstance();
    
        private void init()
        {
    
    	JFrame jf = new JFrame("dn parameter config");
    	jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    	dnYesButton = new JRadioButton("yes");
    	dnNoBUtton = new JRadioButton("no");
    	dnYesButton.setActionCommand("JRadioButtonStatus");
    	dnYesButton.setMnemonic(KeyEvent.VK_A);
    	dnNoBUtton.setActionCommand("JRadioButtonStatus");
    	dnNoBUtton.setMnemonic(KeyEvent.VK_B);
    	dnYesButton.addActionListener(this);
    	dnNoBUtton.addActionListener(this);
    
    	ButtonGroup bg = new ButtonGroup();
    	bg.add(dnYesButton);
    	bg.add(dnNoBUtton);
    	initDnButtonSelectStatus();
    
    	savebutton = new JButton("save");
    	savebutton.addActionListener(this);
    	savebutton.setEnabled(false);
    
    	JLabel jLabel = new JLabel("hahahha");
    	jLabel.setFont(new Font("", Font.PLAIN, 25));
    
    	JPanel pan1 = new JPanel();
    	pan1.add(savebutton);
    	pan1.add(dnYesButton);
    	pan1.add(dnNoBUtton);
    	pan1.add(jLabel);
    	pan1.setVisible(true);
    	pan1.setSize(300, 300);
    
    	jf.getContentPane().add(pan1);
    
    	jf.setVisible(true);
    	jf.setSize(500, 500);
    	jf.setResizable(true);
    
        }
    
        private void initDnButtonSelectStatus()
        {
    	dnNoBUtton.setSelected(!plmnSwitchFileManager.getStatus());
    	dnYesButton.setSelected(plmnSwitchFileManager.getStatus());
        }
    
        public static void main(String args[])
        {
    
    	TestFrame testFrame = new TestFrame();
    	testFrame.init();
        }
    
        @Override
        public void actionPerformed(ActionEvent e)
        {
    	if (e.getSource() == savebutton)
    	{
    	    processFiles();
    	    JOptionPane.showMessageDialog(null, "保存成功");
    	    savebutton.setEnabled(false);
    	}
    	if (e.getActionCommand().equals("JRadioButtonStatus"))
    	{
    	    processSaveButtonEnabledStatus();
    	}
    
        }
    
        private void processSaveButtonEnabledStatus()
        {
    	if (isButtonAndFileStatusConsistent())
    	{
    	    savebutton.setEnabled(false);
    
    	}
    	else
    	    savebutton.setEnabled(true);
        }
    
        private void processFiles()
        {
    	if (dnYesButton.isSelected() != plmnSwitchFileManager.getStatus())
    	{
    	    processDnContainPlmn();
    	}
    
        }
    
        private boolean isButtonAndFileStatusConsistent()
        {
    	// TODO 返回条件或上另外一个不一致的状态
    	return dnYesButton.isSelected() == plmnSwitchFileManager.getStatus();
    
        }
    
        private void processDnContainPlmn()
        {
    	plmnSwitchFileManager.processDnContainPlmnFile(dnYesButton.isSelected());
        }
    
    }
    

      

     文件解析类

    import java.io.BufferedInputStream;
    import java.io.File;
    import java.io.FileInputStream;
    import java.io.FileOutputStream;
    import java.io.IOException;
    import java.io.InputStream;
    import java.util.Properties;
    
    public class PlmnSwitchFileManager
    {
        private static PlmnSwitchFileManager plmnSwitchFileManager = new PlmnSwitchFileManager();
        // 开关状态,和配置文件保持一致
        private boolean status = false;
    
        private String filePath = System.getProperty("user.dir") + File.separator + "conf" + File.separator
    	    + "a.properties";
    
        public static PlmnSwitchFileManager getInstance()
        {
    	return plmnSwitchFileManager;
        }
    
        private PlmnSwitchFileManager()
        {
    	try
    	{
    	    status = getStatusFromFile();
    	}
    	catch (IOException e)
    	{
    	    // TODO Auto-generated catch block
    	    e.printStackTrace();
    	}
        }
    
        public boolean getStatus()
        {
    	return status;
        }
    
        private void setStatus(Boolean content)
        {
    	status = content;
        }
    
        public void writeStatusToFile(Boolean content)
        {
    	Properties prop = new Properties();
    	try
    	{
    	    FileOutputStream oFile = new FileOutputStream(filePath);
    	    prop.setProperty("switch", String.valueOf(content));
    	    prop.store(oFile, "");
    	    oFile.close();
    	}
    	catch (Exception e)
    	{
    	    e.printStackTrace();
    	}
    
        }
    
        private boolean getStatusFromFile() throws IOException
        {
    	String value = "";
    	Properties prop = new Properties();
    	InputStream in = new BufferedInputStream(new FileInputStream(filePath));
    	prop.load(in);
    	value = prop.getProperty("switch");
    	in.close();
    	return Boolean.valueOf(value);
        }
    
        public void processDnContainPlmnFile(boolean newStatus)
        {
    	setStatus(newStatus);
    	writeStatusToFile(newStatus);
    	synFileToSlave();
        }
    
        private void synFileToSlave()
        {
    	File fine = new File("");
    
        }
    
    }
    

      

  • 相关阅读:
    SpringBoot:实现定时任务
    Spring Boot: 配置文件详解
    Git 实用技巧:git stash
    nodejs oj在线笔试应对方案(讲几种输入处理方法)
    scrollWidth,offsetWidth,clientWidth,width;scrollHeight,offsetHeight,clientHeight,height;offsetTop,scrollTop,top;offsetLeft,scrollLeft,left还有谁
    CSS3选择器~一看吓一跳,这么多不会
    CSS3伪类和伪元素的特性和区别
    AngularJS1.X学习笔记6-控制器和作用域
    AngularJS1.X学习笔记5-加强版的表单
    AngularJS1.X学习笔记4-内置事件指令及其他
  • 原文地址:https://www.cnblogs.com/mu-tou-man/p/6174272.html
Copyright © 2011-2022 走看看