• 界面


    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("");
    
        }
    
    }
    

      

  • 相关阅读:
    三个心态做人做学问 沧海
    成功走职场要找准自己的"快捷键" 沧海
    免费离线下载 拂晓风起
    Hibernate 获取某个表全部记录时 奇怪现象 (重复出现某个记录) 拂晓风起
    无法读取mdb 如果连接不了ACCESS mdb文件,就尝试安装MDAC 拂晓风起
    Netbeans 使用 Hibernate 逆向工程 生成hbm和pojo 拂晓风起
    如何点击单选框 radio 后面的文字,选中单选框 拂晓风起
    Java 连接access 使用access文件 不用配置 拂晓风起
    mysql下如何执行sql脚本 拂晓风起
    Hibernate配置access Hibernate 连接 access 拂晓风起
  • 原文地址:https://www.cnblogs.com/mu-tou-man/p/6174272.html
Copyright © 2020-2023  润新知