//
// Core Program for TETDM 
// ExpData.java Version 1.00
// Copyright(C) 2015-2018 TETDM CORE MEMBER ALL RIGHTS RESERVED.
// This program is provided under the license.
//

package source.GameMode;

import source.*;
import source.TextData.*;
import source.Utility.*;
import source.GameMode.*;
import java.io.*;
import java.util.*;

import javax.swing.UIManager;
import java.awt.Font;
import java.awt.*;
import java.util.Date;
import java.util.Calendar;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;


//public class ExpData
public class ExpData implements Runnable
{
	TextData text;
	ItemPanel itempanel;
	CharacterPanel characterpanel;
	ShopPanel shoppanel;
	MissionPanel missionpanel;
	PopUpForKnowledgeCreation knowledge;
	Control control;
	DataPanel datapanel;
	PopUpForInterpretation interpretation;
	ExpPanel exppanel;
	
	public int rank;
	public int rank2;
	public int exp;
	public int exp2;
	public int coin;
	
	public static int expcollect;
	//public int expformat;
	public static int expchoice;
	public static int expuse;
	public static int expinter;
	public static int expknow;
	public static int expknow2;
	public static int expother;
	
	public int control2 = 0;
	int control3[] = {0,0,0,0,0,0,0,0,0,0,  // should consider controlButtonNumber below
						0,0,0,0,0,0,0,0,0,0,
						0,0,0,0,0,0,0,0};
	int controlcount = 0;
	
	public int select2 = 0;
	int select3[] = {0,0,0,0};
	int selectcount = 0;
	
	public int mining2 = 0;
	int mining3[] ={0,0,0,0,0,0,0,0};
	int miningcount = 0;
	
	public int assist2 = 0;
	int assist3[] ={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
	int assistcount = 0;
	int assist4 = 0;
	
	public int mode2 = 0;
	int mode3[] ={0,0,0,0};
	int modecount = 0;
	
	public int setting2 = 0;
	int setting3[] ={0,0,0,0};
	int settingcount = 0;
	
	public int knowledge2 = 0;
	int knowledge3[] ={0,0,0,0,0};
	int knowledgecount = 0;
	
	public int setmodule2 = 0;
	int setmodule3[] ={0,0,0,0};
	int setmodulecount = 0;
	


	public int miningmodule2 = 0;
	int miningmodule3[];
	int miningmodulecount = 0;
	int miningmodule4 = 0;
	static int miningmodule5 = 0;
	
	public int visualmodule2 = 0;
	int visualmodule3[];
	int visualmodulecount = 0;
	int visualmodule4 = 0;
	static int visualmodule5 = 0;
	
	public int miningmoduleoperation2 = 0;
	int miningmoduleoperation3[];
	int miningmoduleoperationcount = 0;
	int miningmoduleoperation4 = 0;
	
	static int miningmoduleoperation5 = 0;
	
	public int visualmoduleoperation2 = 0;
	int visualmoduleoperation3[];
	int visualmoduleoperationcount = 0;
	int visualmoduleoperation4 = 0;
	
	static int visualmoduleoperation5 = 0;
	
	//public int stamina;
	public static double stamina = 100;
	public static int stamina2 = 0;
	public static int stamina3 = 0;
	
	public static double amari = 0;
	
	public static int startingnumber = 0;
	public static int loginnumber = 0;
	public static int renzokuloginnumber = 1;
	public static int dayyear = 0;
	public static int daymonth = 0;
	public static int daymonthnumber = 1;
	
	static int controlButtonCount[];

	int controlButtonNumber = 28;		// should consider control3[] above
	int controlButtonExp[] = {10,10,10,10,10,10,10,10,10,10,
								10,10,10,10,10,10,10,10,10,10,
								10,10,10,10,10,10,10,10};
	static int knowledgenumber = 0;
	//int controlButtonExp[] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
	
	static int selectButtonCount[];
	int selectButtonNumber = 4;			// should consider select3[] above
	int selectButtonExp[] = {10,10,10,10};
	
	static int miningButtonCount[];
	int miningButtonNumber = 8;			// should consider mining3[] above
	int miningButtonExp[] = {10,10,10,10,10,10,10,10};

	static int selectionAssistButtonCount[];
	int selectionAssistButtonNumber = 20;		// should consider assist3[] above
	int selectionAssistButtonExp[] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};	
	//int selectionAssistButtonExp[] = {10,10,10,10,20,30,30,30,30,30,
	//									30,20,40,40,40,20,40,20,20,20};
	//int selectionAssistButtonExp[] = {1,1,1,1,2,3,3,3,3,3,3,2,4,4,4,2,4,2,0,2};	
	
	int settingButtonCount[];
	int settingButtonNumber = 4;
	int settingButtonExp[] = {10,10,10,10};
	
	int modeButtonCount[];
	int modeButtonNumber = 4;
	int modeButtonExp[] = {10,10,10,10};
	
	int knowledgeButtonCount[];
	int knowledgeButtonNumber = 5;
	int knowledgeButtonExp[] = {10,10,10,10,10};
	
	int setmoduleButtonCount[];
	int setmoduleButtonNumber = 4;
	int setmoduleButtonExp[] = {10,10,10,10};
	
	

		

	
	File file2;	
	
	int maxMiningModuleNumber = 100;
	int maxVisualizationModuleNumber = 100;	
	
	int miningModuleID[];	
	static int miningModuleSelectionCount[];
	static int miningModuleOperationCount[];	
	static int miningModuleNumber;
	
	int visualizationModuleID[];	
	static int visualizationModuleSelectionCount[];
	static int visualizationModuleOperationCount[];
	static int visualizationModuleNumber;		
	
	String expFileName;	// with absolutePath
	//String absolutePath;	
	String speechtext;
	int time1 = 0;
	int time2 = 0;
	
	int selection = 0;
	
	//Date date = new Date();
	//String str = date.toString();
	Calendar cal = Calendar.getInstance();
	public int year = cal.get(Calendar.YEAR);
	public int month = cal.get(Calendar.MONTH) + 1;
	public int day = cal.get(Calendar.DATE);
	public int hour = cal.get(Calendar.HOUR);
	public int min = cal.get(Calendar.MINUTE);
	public int sec = cal.get(Calendar.SECOND);
	int day_of_year = cal.get(Calendar.DAY_OF_YEAR);
	
	int check = 0;
	
	long startTime, endTime;
	
	String time;
	String timetext[];
	String timetext2[];
	int second = 0;
	
	static int tutorialexp;
	
	int number2 = -1;
	int miningID2 = -1;
	int visualizationID2 = -1;
	
	int knowcount = 0;
	static int inputnumber = 0;
	
	SettingData settingData;
	Thread myth;
	public static int totaltimeint = 0;
	public static int totaltimeint2 = 0;
	static int timeint2 = 0;
	
	public static int lognumber = 0;
	
	static int collectbutton = 0;
	
	public ExpData(String expFileName)
	{
		
		this.expFileName = expFileName;
		
		controlButtonCount = new int[controlButtonNumber];
		selectButtonCount = new int[selectButtonNumber];
		miningButtonCount = new int[miningButtonNumber];
		selectionAssistButtonCount = new int[selectionAssistButtonNumber];
		
		miningModuleID = new int[maxMiningModuleNumber];
		miningModuleSelectionCount = new int[maxMiningModuleNumber];
		miningModuleOperationCount = new int[maxMiningModuleNumber];		
		
		visualizationModuleID = new int[maxVisualizationModuleNumber];	
		visualizationModuleSelectionCount = new int[maxVisualizationModuleNumber];
		visualizationModuleOperationCount = new int[maxVisualizationModuleNumber];		

		miningmodule3 = new int[maxMiningModuleNumber];
		visualmodule3 = new int[maxVisualizationModuleNumber];
		miningmoduleoperation3 = new int[maxMiningModuleNumber];
		visualmoduleoperation3 = new int[maxVisualizationModuleNumber];
		
		modeButtonCount = new int[modeButtonNumber];
		settingButtonCount = new int[settingButtonNumber];
		knowledgeButtonCount = new int[knowledgeButtonNumber];
		setmoduleButtonCount = new int[modeButtonNumber];
	
		
		timetext = new String[100];
		
		readExpFile(new File(expFileName));
		
		//SettingData settingD;
		//settingData = settingD;

		//timetext = FILEIO.TextFileAllReadCodeArray(new File(settingData.absolutePath + "tetdm.exp"));
		
		startTime = System.nanoTime();
		startArrangement();
	
	startingnumber++;
	if(rank >= 1000){
	if(stamina == 100) stamina2 = 100;
	
	stamina3 = 100;
	}
	
	if(rank <1000 && rank >= 100) {
	if(stamina == 100) stamina2 = rank/10;
	stamina3 = rank/10;
	}
	
	if(rank < 100){
	if(stamina == 100) stamina2 = 10;
	stamina3 = 10;
	}
	}
	
	public void readExpFile(File expFile)
	{
		String speechtext = FILEIO.TextFileAllReadCode(expFile);		
		readTexts(speechtext);		
	}
	
	public void readOriginalExpFile()
	{
		readExpFile(new File(expFileName+".original"));
		saveExpFile();
	}	

	public void readTexts(String speechtext)
	{
		String ss;
		String tempString[];
		String tempStringPair[];
		String tempStringmis[];
		String tempStringshop[];
		String tempStringcos[]; 

		try
		{
			BufferedReader br1 = new BufferedReader(new StringReader(speechtext));

			ss = br1.readLine();
			rank = Integer.parseInt(ss);
			//rank2 = Integer.parseInt(ss);
			
			ss = br1.readLine();
			exp = Integer.parseInt(ss);
			
			ss = br1.readLine();
			coin = Integer.parseInt(ss);
			
			ss = br1.readLine();
			//stamina = Integer.parseInt(ss);
			stamina = Double.parseDouble(ss);
			
			ss = br1.readLine();
			stamina2 = Integer.parseInt(ss);
			
			ss = br1.readLine();
			startingnumber = Integer.parseInt(ss);
			
			ss = br1.readLine();
			tempString  = ss.split(" ");
			for(int i=0;i<tempString.length;i++)
				controlButtonCount[i] = Integer.parseInt(tempString[i]);
			//strdata[i] = String.valueOf(controlButtonCount[i]);
			
			ss = br1.readLine();
			tempString  = ss.split(" ");
			for(int i=0;i<tempString.length;i++)
				selectButtonCount[i] = Integer.parseInt(tempString[i]);	
			
			ss = br1.readLine();
			tempString  = ss.split(" ");
			for(int i=0;i<tempString.length;i++)
				miningButtonCount[i] = Integer.parseInt(tempString[i]);				
			
			ss = br1.readLine();
			tempString  = ss.split(" ");
			for(int i=0;i<tempString.length;i++)
				selectionAssistButtonCount[i] = Integer.parseInt(tempString[i]);
			
			
			ss = br1.readLine();
			tempString  = ss.split(" ");
			for(int i=0;i<tempString.length;i++)
				settingButtonCount[i] = Integer.parseInt(tempString[i]);	
			
			ss = br1.readLine();
			tempString  = ss.split(" ");
			for(int i=0;i<tempString.length;i++)
				modeButtonCount[i] = Integer.parseInt(tempString[i]);
				
			ss = br1.readLine();
			tempString  = ss.split(" ");
			for(int i=0;i<tempString.length;i++)
				knowledgeButtonCount[i] = Integer.parseInt(tempString[i]);		
			
			ss = br1.readLine();
			tempString  = ss.split(" ");
			for(int i=0;i<tempString.length;i++)
				setmoduleButtonCount[i] = Integer.parseInt(tempString[i]);
			
			
			//SELECTION
			//miningModule
			ss = br1.readLine();
			tempString  = ss.split(",");
			miningModuleNumber = tempString.length;
			
			for(int i=0;i<miningModuleNumber;i++)
			{
				tempStringPair = tempString[i].split(" ");
				miningModuleID[i] = Integer.parseInt(tempStringPair[0]);
				miningModuleSelectionCount[i] = Integer.parseInt(tempStringPair[1]);
			}
							
			//visualizationModule
			ss = br1.readLine();
			tempString  = ss.split(",");
			visualizationModuleNumber = tempString.length;
			
			for(int i=0;i<visualizationModuleNumber;i++)
			{
				tempStringPair = tempString[i].split(" ");
				visualizationModuleID[i] = Integer.parseInt(tempStringPair[0]);
				visualizationModuleSelectionCount[i] = Integer.parseInt(tempStringPair[1]);
			}
			
			//OPERATION
			//miningModule
			ss = br1.readLine();
			tempString  = ss.split(",");
			miningModuleNumber = tempString.length;
			
			for(int i=0;i<miningModuleNumber;i++)
			{
				tempStringPair = tempString[i].split(" ");
//				miningModuleID[i] = Integer.parseInt(tempStringPair[0]);
				miningModuleOperationCount[i] = Integer.parseInt(tempStringPair[1]);
			}
			
			//visualizationModule
			ss = br1.readLine();
			tempString  = ss.split(",");
			visualizationModuleNumber = tempString.length;
			
			for(int i=0;i<visualizationModuleNumber;i++)
			{
				tempStringPair = tempString[i].split(" ");
//				
				visualizationModuleOperationCount[i] = Integer.parseInt(tempStringPair[1]);
			}			
			
			
			
			
			
			ss = br1.readLine();
			inputnumber = Integer.parseInt(ss);
			
			ss = br1.readLine();
			itempanel.mpnumber = Integer.parseInt(ss);
			
			ss = br1.readLine();
			tempStringshop  = ss.split(" ");
			for(int i=0;i<CharacterData.CharacterNumber;i++){
			CharacterData.buycharacternumber[i] = Integer.parseInt(tempStringshop[i]);
			}
			
			ss = br1.readLine();
			tempStringcos  = ss.split(" ");
			
			for(int i=0;i<CharacterData.CostumeNumber;i++){
			CharacterData.cosnumber[i] = Integer.parseInt(tempStringcos[i]);
			}
			
			ss = br1.readLine();
			CharacterData.nowcharacternumber = Integer.parseInt(ss);
			
			
			
			ss = br1.readLine();
			tempStringmis  = ss.split(" ");
			for(int i=0;i<MissionPanel.MISSIONNUMBER;i++){
			missionpanel.missionnumber[i] = Integer.parseInt(tempStringmis[i]);
			}
			
			ss = br1.readLine();
			knowledgenumber = Integer.parseInt(ss);
			
			ss = br1.readLine();
			expknow2 = Integer.parseInt(ss);
			
			time = br1.readLine();
			
			ss = br1.readLine();
			dayyear = Integer.parseInt(ss);
			
			ss = br1.readLine();
			loginnumber = Integer.parseInt(ss);
			
			ss = br1.readLine();
			renzokuloginnumber = Integer.parseInt(ss);
			
			ss = br1.readLine();
			daymonth = Integer.parseInt(ss);
			
			ss = br1.readLine();
			daymonthnumber = Integer.parseInt(ss);
			
			ss = br1.readLine();
			timeint2 = Integer.parseInt(ss);
			
			ss = br1.readLine();
			expcollect = Integer.parseInt(ss);
			
			ss = br1.readLine();
			expchoice = Integer.parseInt(ss);
			
			ss = br1.readLine();
			expuse = Integer.parseInt(ss);
			
			ss = br1.readLine();
			expinter = Integer.parseInt(ss);
			
			ss = br1.readLine();
			expknow = Integer.parseInt(ss);
			
			ss = br1.readLine();
			tutorialexp = Integer.parseInt(ss);
			
			ss = br1.readLine();
			expother = Integer.parseInt(ss);
			
			ss = br1.readLine();
			TitlePanel.skillrank = Integer.parseInt(ss);
			
			//ss = br1.readLine();
			//lognumber = Integer.parseInt(ss);
			
			ss = br1.readLine();
			collectbutton = Integer.parseInt(ss);
			
			/*
			ss = br1.readLine();
			tempString  = ss.split(" ");
			for(int i=0;i<tempString.length;i++)
				missionpanel.missionnumber[][i] = Integer.parseInt(tempString[i]);
			*/
		}
		catch(Exception e){
			System.out.println("Text Reading ERROR EXPtext2");
		}
	
	
	if(day_of_year-1 == dayyear || (day_of_year == 1 && dayyear ==365) || (day_of_year == 1 && dayyear ==366)){
	renzokuloginnumber++;
	
	
	
	}
	else if(day_of_year == dayyear){
	
	}
	else{
	renzokuloginnumber = 1;
	}
	
	if(month == daymonth && day_of_year != dayyear){
	daymonthnumber++;
	}
	
	if(month != daymonth){
	
	for(int i=0;i<miningModuleNumber;i++){
	//miningModuleSelectionCount[i] = 0;
	}
	
	daymonthnumber = 1;
	}
	
	if(day_of_year != dayyear){
	loginnumber++;
	
	
	
	stamina = 100;
	
	if(renzokuloginnumber == 1){
	addCoin(100);
	
	}
	
	if(renzokuloginnumber == 2){
	addCoin(150);
	itempanel.mpnumber +=  1;
	}
	
	if(renzokuloginnumber == 3){
	addCoin(200);
	itempanel.mpnumber +=  1;
	}
	if(renzokuloginnumber == 4){
	addCoin(250);
	itempanel.mpnumber +=  1;
	}
	if(renzokuloginnumber == 5){
	addCoin(300);
	itempanel.mpnumber +=  1;
	}
	
	if(renzokuloginnumber == 6){
	addCoin(350);
	itempanel.mpnumber +=  1;
	}
	
	if(renzokuloginnumber >= 7){
	addCoin(400);
	itempanel.mpnumber +=  5;
	}
	}
	
	rank = (int)(exp/100) + 1;
	exp2 = (int)(exp%100);
	
	
	}
	
	//WITH SAVE
	
	/*
	public void addRank(int number){
	rank+=number;
	saveExpFile();
	}
	*/
	
	public void addExp(int number)
	{
	exp += number;
	
	//addExpByCountWithoutSave();
	Rank();
	
	saveExpFile();
	
	}
	
	
	public void addCoin(int number)
	{
		coin += number;
		saveExpFile();
	}
	
	public void addMp(int number)
	{
		itempanel.mpnumber += number;
		saveExpFile();
	}
	
	
	public void save()
	{
		saveExpFile();
	}
	
	/*
	public void date()
	{
	 date = new Date();
	str = date.toString();
	int year = cal.get(Calendar.YEAR);
	int month = cal.get(Calendar.MONTH);
	int day = cal.get(Calendar.DATE);
		saveExpFile();
	}
	*/
	public void takeStamina(int number)
	{
	if(rank >= 1000){
	stamina = stamina - number;
	stamina2 -= number;
	}
	
	if(rank <1000 && rank >= 100) {
	amari = 100/(double)(rank/10);
	stamina  = stamina - (amari*number);
	
	stamina2 -= number;
	}
	
	if(rank < 100){
	stamina  = stamina - (number*10);
	stamina2 -= number;
	}
	
	if(stamina < 0) stamina = 0;
	if(stamina2 < 0) stamina2 = 0;
	if(stamina2 == 0) stamina = 0;
	//saveExpFile();
	}
	
	
	public void addExpByCount(int max, int count)
	{
		int tempExp;
		
		tempExp = max;
		
		for(int i=1;i<count && tempExp >= 1;i++)
			tempExp /= 2;
		
		if(tempExp < 1)
			tempExp = 1;
		
		addExp(tempExp);
	}
	
	
	
	//WITHOUT SAVE
	public void addExpWithoutSave(int number)
	{
		exp += number;
		rank = (int)(exp/100) + 1;
		if(rank >=1000){
		stamina3 = 100;
		if(stamina == 100) stamina2 = 100;
		}
		
		if(rank <1000 && rank >= 100){
		 stamina3 = rank/10;
		if(stamina == 100) stamina2 = rank/10;
		 }
		if(rank<100) stamina3 = 10;
		
	}
	
	public void Rank()
	{
		rank = (int)(exp/100) + 1;
		if(rank >=1000){
		stamina3 = 100;
		if(stamina == 100) stamina2 = 100;
		}
		
		if(rank <1000 && rank >= 100){
		 stamina3 = rank/10;
		if(stamina == 100) stamina2 = rank/10;
		 }
		 
		if(rank<100) stamina3 = 10;
		
	}
	
	
	public void addExpByCountWithoutSave(int max, int count)
	{
		int tempExp;
		
		tempExp = max;
		
		for(int i=1;i<count && tempExp >= 1;i++)
			tempExp /= 2;
		
		if(tempExp < 1)
			tempExp = 1;
		
		addExpWithoutSave(tempExp);
	}	
	
	//ADD EXP
	public void addExpByControlButton(int number)
	{
		if(number2 != number) controlButtonCount[number]++;
		
		if(number2 != number && number != 13 && number != 14 && number != 19) addExpByCount(controlButtonExp[number], controlButtonCount[number]);
		if(number2 != number && number != 13 && number != 14 && number != 19) addCoin(1);
		
	
		
		if(number2 != number && CharacterPanel2.magiccount[0] != 0 && (number == 3 || number == 4 || number == 7 || number == 8 || number == 9 || number == 10)){
		addCoin(10);
		CharacterPanel2.magiccount[0] = CharacterPanel2.magiccount[0] - 1;
		}
		
		
		if(number2 != number && CharacterPanel2.magiccount[2]!= 0 && (number == 0 || number == 1 || number == 17)){
		addCoin(10);
		CharacterPanel2.magiccount[2] = CharacterPanel2.magiccount[2] - 1;
		}
		
		if(number2 != number && CharacterPanel2.magiccount[3]!= 0 && (number == 5 || number == 11 || number == 12)){
		addCoin(10);
		CharacterPanel2.magiccount[3] = CharacterPanel2.magiccount[3] - 1;
		}
		
		if(number2 != number && CharacterPanel2.magiccount[4]!= 0 && (number == 15 || number == 16)){
		addCoin(10);
		CharacterPanel2.magiccount[4] = CharacterPanel2.magiccount[4] - 1;
		}
		
		if(number == 16) knowcount = 0;
		
		number2 = number;
		
		saveExpFile();
		
	}
	
	public void addExpBySelectButton(int number)
	{
		if(number2 != number) selectButtonCount[number]++;
		if(number2 != number) addExpByCount(selectButtonExp[number], selectButtonCount[number]);
		if(number2 != number) addCoin(1);
		
				
		if(number2 != number && CharacterPanel2.magiccount[0] != 0 && (number == 0 || number == 1)){
		addCoin(10);
		CharacterPanel2.magiccount[0] = CharacterPanel2.magiccount[0] - 1;
		}
		
		
		if(number2 != number && CharacterPanel2.magiccount[3]!= 0 && (number == 3)){
		addCoin(10);
		CharacterPanel2.magiccount[3] = CharacterPanel2.magiccount[3] - 1;
		}
		
		number2 = number;

		
		saveExpFile();
		
	}	
	
	public void addExpByMiningButton(int number)
	{
		if(number2 != number) miningButtonCount[number]++;
		if(number2 != number) addExpByCount(miningButtonExp[number], miningButtonCount[number]);
		if(number2 != number) addCoin(1);
		
		
		if(number2 != number && CharacterPanel2.magiccount[0] != 0 && (number == 0 || number == 1 || number == 2 || number == 3)){
			addCoin(10);
			CharacterPanel2.magiccount[0] = CharacterPanel2.magiccount[0] - 1;
			}
		
		if(number2 != number && CharacterPanel2.magiccount[1]!= 0 && (number == 5)){
		addCoin(10);
		CharacterPanel2.magiccount[1] = CharacterPanel2.magiccount[1] - 1;
		}
		
		
		
		number2 = number;
		saveExpFile();
	}
	
	public void addExpBySelectionAssistButton(int number)
	{
		if(number2 != number) selectionAssistButtonCount[number]++;
		
		if(number2 != number) addExpByCount(selectionAssistButtonExp[number], selectionAssistButtonCount[number]);
		if(number2 != number) addCoin(1);
		
		if(number2 != number && CharacterPanel2.magiccount[0] != 0){
		addCoin(10);
		CharacterPanel2.magiccount[0] = CharacterPanel2.magiccount[0] - 1;
		}
		
		number2 = number;
		saveExpFile();
		
	}
	
	
		public void addExpByModeButton(int number)
	{
		if(number2 != number) modeButtonCount[number]++;
		if(number2 != number) addExpByCount(modeButtonExp[number], modeButtonCount[number]);
		if(number2 != number) addCoin(1);
		
		number2 = number;
 
		saveExpFile();
		
	}	
	
		public void addExpByKnowledgeButton(int number)
	{
		if(number2 != number || number == 0) knowledgeButtonCount[number]++;
		if(number2 != number || number == 0) addExpByCount(knowledgeButtonExp[number], knowledgeButtonCount[number]);
		if(number2 != number || number == 0) addCoin(1);
		number2 = number;
 		
		//knowledgeButtonCount[number]++;
		//addExpByCount(knowledgeButtonExp[number], knowledgeButtonCount[number]);
		//addCoin(1);
		
		saveExpFile();
		
	}
	
	public void addExpBySettingButton(int number)
	{
		if(number2 != number) settingButtonCount[number]++;
		if(number2 != number) addExpByCount(settingButtonExp[number], settingButtonCount[number]);
		if(number2 != number) addCoin(1);
		
		number2 = number;
		saveExpFile();
		
	}	
	
	public void addExpBySetModuleButton(int number)
	{
		if(number2 != number) setmoduleButtonCount[number]++;
		if(number2 != number) addExpByCount(setmoduleButtonExp[number], setmoduleButtonCount[number]);
		if(number2 != number) addCoin(1);
		
		number2 = number;
 
		saveExpFile();
		
	}
	
	//Selection
	public void addExpBySelectedModule(int miningID, int visualizationID)
	{
		int i;
		
		
		for(i=0;i<miningModuleNumber;i++)
			if(miningModuleID[i] == miningID)
			{
				if(miningID2 != miningID) miningModuleSelectionCount[i]++;
				if(miningID2 != miningID) addExpByCountWithoutSave(10, miningModuleSelectionCount[i]);
				if(miningID2 != miningID) addCoin(1);
				
				miningID2 = miningID;
				//visualizationID2 = visualizationID;
				
				//text.control.expPanel.repaint();
				
				/*
				if(CharacterPanel2.magiccount[1]!= 0){
				text.control.ex1.addCoin(10);
				CharacterPanel2.magiccount[1] = CharacterPanel2.magiccount[1] - 1;
				}
				*/
				
				//if(text.control.expPanel != null) 
				//	text.control.expPanel.repaint();
				
				
				break;
			}
		
		if(i == miningModuleNumber)	// add new moduleID
		{
			miningModuleID[i] = miningID;
			miningModuleSelectionCount[miningModuleNumber++] = 1;
			addExpByCountWithoutSave(10, miningModuleSelectionCount[i]);
			addCoin(1);
		}
		
		for(i=0;i<visualizationModuleNumber;i++)
			if(visualizationModuleID[i] == visualizationID)
			{
				if(visualizationID2 != visualizationID) visualizationModuleSelectionCount[i]++;
				if(visualizationID2 != visualizationID) addExpByCountWithoutSave(10, visualizationModuleSelectionCount[i]);
				//if(visualizationID2 != visualizationID) addCoin(1);
				visualizationID2 = visualizationID;
				/*
				if(CharacterPanel2.magiccount[1]!= 0){
				text.control.ex1.addCoin(10);
				CharacterPanel2.magiccount[1] = CharacterPanel2.magiccount[1] - 1;
				}
				*/
				
				
				break;
			}
		
		if(i == visualizationModuleNumber)	// add new moduleID
		{
			visualizationModuleID[i] = visualizationID;
			visualizationModuleSelectionCount[visualizationModuleNumber++] = 1;
			addExpByCountWithoutSave(10, visualizationModuleSelectionCount[i]);
			addCoin(1);
			
			
			
		}		
		
		//exppanel.repaint();	
		saveExpFile();		
	}
	
	public void addExpByknowledge(int number)
	{
	if(knowcount == 0){
			addExp(number);
			addCoin(number);
			addExpknow(number);
					
			knowledgenumber++;
			knowcount++;
					
			if(CharacterPanel2.magiccount[4]!= 0){
			addCoin(100);
			CharacterPanel2.magiccount[4] = CharacterPanel2.magiccount[4] - 1;
			}
					
					
	}
			saveExpFile();
	
	}
	
	public void addExpByinterpretation()
	{
			inputnumber++;
			addExp(5); 
			addCoin(5); 
					
			if(CharacterPanel2.magiccount[3]!= 0){
			addCoin(20);
			CharacterPanel2.magiccount[3] = CharacterPanel2.magiccount[3] - 1;
			}
					
					
			saveExpFile();
	
	}
	
	
	public void addExpcollect(int number)
	{
	expcollect += number;
	saveExpFile();
	}
	/*
	public void addExpByChoice(int max, int count)
	{
		int tempExp;
		
		tempExp = max;
		
		for(int i=1;i<count && tempExp >= 1;i++)
			tempExp /= 2;
		
		if(tempExp < 1)
			tempExp = 1;
		
		addExpChoice(tempExp);
	}
	*/
	public void addExpChoice(int number)
	{
	expcollect += number;
	saveExpFile();
	}
	/*
	public void addExpChoice2(int number)
	{
		addExpByChoice(10, controlButtonCount[number]);
	}
	*/
	
	/*
	public void addExpByCollect(int max, int count)
	{
		int tempExp;
		
		tempExp = max;
		
		for(int i=1;i<count && tempExp >= 1;i++)
			tempExp /= 2;
		
		if(tempExp < 1)
			tempExp = 1;
		
		addExpcollect(tempExp);
	}
	
	public void addExpcollect2(int number)
	{
		addExpByCollect(10, controlButtonCount[number]);
	}
	*/
	/*
	public void addExpchoice(int number)
	{
	expchoice += number;
	saveExpFile();
	}
	
	public void addExpuse(int number)
	{
	expuse += number;
	saveExpFile();
	}
	
	public void addExpinter(int number)
	{
	expinter += number;
	saveExpFile();
	}
	*/
	
	public void addExpknow(int number)
	{
	expknow2 += number;
	saveExpFile();
	}
	
	public void ExpchangeControl(int number)
	{
	if(number == 0){
	control2 = 0;
	} 
	
	if(number == 1){
	control2 = 10;
	}
	if(number == 2){
	control2 = 15;
	}
	if(number >= 3){
	control2 = 14 + number;
	}
	
	//control3[controlcount] = control2;
	//controlcount++;
	
	//saveExpFile();
	}
	
	
	public void ExpchangeSelect(int number)
	{
	if(number == 0){
	select2 = 0;
	} 
	
	if(number == 1){
	select2 = 10;
	}
	if(number == 2){
	select2 = 15;
	}
	if(number >= 3){
	select2 = 14 + number;
	}
	//select3[selectcount] = select2;
	//selectcount++;
	//saveExpFile();

	}
	
	public void ExpchangeMining(int number)
	{
	if(number == 0){
	mining2 = 0;
	} 
	
	if(number == 1){
	mining2 = 10;
	}
	if(number == 2){
	mining2 = 15;
	}
	if(number >= 3){
	mining2 = 14 + number;
	}
	//mining3[miningcount] = mining2;
	//miningcount++;
	
	//saveExpFile();

	}
	
	public void ExpchangeAssist(int number)
	{
	if(number == 0){
	assist2 = 0;
	} 
	
	if(number == 1){
	assist2 = 10;
	}
	if(number == 2){
	assist2 = 15;
	}
	if(number >= 3){
	assist2 = 14 + number;
	}
	}
	
	public void ExpchangeMode(int number)
	{
	if(number == 0){
	mode2 = 0;
	} 
	
	if(number == 1){
	mode2 = 10;
	}
	if(number == 2){
	mode2 = 15;
	}
	if(number >= 3){
	mode2 = 14 + number;
	}
	//saveExpFile();
	}
	
	public void ExpchangeSetting(int number)
	{
	if(number == 0){
	setting2 = 0;
	} 
	
	if(number == 1){
	setting2 = 10;
	}
	if(number == 2){
	setting2 = 15;
	}
	if(number >= 3){
	setting2 = 14 + number;
	}
	//saveExpFile();
	}
	
	public void ExpchangeKnowledge(int number)
	{
	if(number == 0){
	knowledge2 = 0;
	} 
	
	if(number == 1){
	knowledge2 = 10;
	}
	if(number == 2){
	knowledge2 = 15;
	}
	if(number >= 3){
	knowledge2 = 14 + number;
	}
	//saveExpFile();
	}
	
	public void ExpchangeSetModule(int number)
	{
	if(number == 0){
	setmodule2 = 0;
	} 
	
	if(number == 1){
	setmodule2 = 10;
	}
	if(number == 2){
	setmodule2 = 15;
	}
	if(number >= 3){
	setmodule2 = 14 + number;
	}
	//saveExpFile();
	}
	
	public void ExpchangeMiningmodule(int number)
	{
	if(number == 0){
	miningmodule2 = 0;
	} 
	
	if(number == 1){
	miningmodule2 = 10;
	}
	if(number == 2){
	miningmodule2 = 15;
	}
	if(number >= 3){
	miningmodule2 = 14 + number;
	}
	
	//miningmodule3[miningmodulecount] = miningmodule2;
	//miningmodulecount++;
	
	//saveExpFile();
	}
	
	public void ExpchangeVisualmodule(int number)
	{
	if(number == 0){
	visualmodule2 = 0;
	} 
	
	if(number == 1){
	visualmodule2 = 10;
	}
	if(number == 2){
	visualmodule2 = 15;
	}
	if(number >= 3){
	visualmodule2 = 14 + number;
	}
	
	//visualmodule3[visualmodulecount] = visualmodule2;
	//visualmodulecount++;
	
	//saveExpFile();
	}
	
	public void ExpchangeMiningmoduleOperation(int number)
	{
	if(number == 0){
	miningmoduleoperation2 = 0;
	} 
	
	if(number == 1){
	miningmoduleoperation2 = 10;
	}
	if(number == 2){
	miningmoduleoperation2 = 15;
	}
	if(number >= 3){
	miningmoduleoperation2 = 14 + number;
	}
	
	//miningmoduleoperation3[miningmoduleoperationcount] = miningmoduleoperation2;
	//miningmoduleoperationcount++;
	
	//saveExpFile();
	}
	
	public void ExpchangeVisualmoduleOperation(int number)
	{
	if(number == 0){
	visualmoduleoperation2 = 0;
	} 
	
	if(number == 1){
	visualmoduleoperation2 = 10;
	}
	if(number == 2){
	visualmoduleoperation2 = 15;
	}
	if(number >= 3){
	visualmoduleoperation2 = 14 + number;
	}
	
	//visualmoduleoperation3[visualmoduleoperationcount] = visualmoduleoperation2;
	//visualmoduleoperationcount++;
	
	//saveExpFile();
	}
	
	public void Exp(){
	for(int i = 0;i<controlButtonNumber;i++){
	ExpchangeControl(controlButtonCount[i]);
	control3[i] = control2;
	}
	
	for(int i = 0;i<selectButtonNumber;i++){
	ExpchangeSelect(selectButtonCount[i]);
	select3[i] = select2;
	}
	
	for(int i = 0;i<miningButtonNumber;i++){
	ExpchangeMining(miningButtonCount[i]);
	mining3[i] = mining2;
	}
	
	for(int i = 0;i<selectionAssistButtonNumber;i++){
	ExpchangeAssist(selectionAssistButtonCount[i]);
	assist3[i] = assist2;
	}
	
	for(int i = 0;i<modeButtonNumber;i++){
	ExpchangeMode(modeButtonCount[i]);
	mode3[i] = mode2;
	}
	
	for(int i = 0;i<knowledgeButtonNumber;i++){
	ExpchangeKnowledge(knowledgeButtonCount[i]);
	knowledge3[i] = knowledge2;
	}
	
	for(int i = 0;i<settingButtonNumber;i++){
	ExpchangeSetting(settingButtonCount[i]);
	setting3[i] = setting2;
	}
	
	for(int i = 0;i<setmoduleButtonNumber;i++){
	ExpchangeSetModule(setmoduleButtonCount[i]);
	setmodule3[i] = setmodule2;
	}
	
	assist4 = 0;
	
	for(int i=0;i<selectionAssistButtonNumber;i++){
	assist4 += assist3[i];
	}
	
	
	for(int i=0;i<miningModuleNumber;i++){
	ExpchangeMiningmodule(miningModuleSelectionCount[i]);
	miningmodule3[i] = miningmodule2;
	}
	
	miningmodule4 = 0;
	for(int i=0;i<miningModuleNumber;i++){
	miningmodule4 += miningmodule3[i];
	}
	
	for(int i=0;i<visualizationModuleNumber;i++){
	ExpchangeVisualmodule(visualizationModuleSelectionCount[i]);
	visualmodule3[i] = visualmodule2;
	}
	
	visualmodule4 = 0;
	for(int i=0;i<visualizationModuleNumber;i++){
	visualmodule4 += visualmodule3[i];
	}
	
	for(int i=0;i<miningModuleNumber;i++){
	ExpchangeMiningmoduleOperation(miningModuleOperationCount[i]);
	miningmoduleoperation3[i] = miningmoduleoperation2;
	}
	
	miningmoduleoperation4 = 0;
	for(int i=0;i<miningModuleNumber;i++){
	miningmoduleoperation4 += miningmoduleoperation3[i];
	}
	
	for(int i=0;i<visualizationModuleNumber;i++){
	ExpchangeVisualmoduleOperation(visualizationModuleOperationCount[i]);
	visualmoduleoperation3[i] = visualmoduleoperation2;
	}
	
	visualmoduleoperation4 = 0;
	for(int i=0;i<visualizationModuleNumber;i++){
	visualmoduleoperation4 += visualmoduleoperation3[i];
	}
	
	//miningmodule5 = 0
	//for(int i=0;i<miningModuleNumber;i++){
	//miningmodule5 += miningModuleSelectionCount[i];
	//}
	
	expcollect = control3[0] + control3[1] + control3[17] + setting3[0] + setting3[1] + setting3[2] + setting3[0] + collectbutton;
	//+ miningmoduleoperation3[1]
	
	if(missionpanel.missionnumber[20] == 1) expcollect = expcollect + 100;
	
	expchoice = control3[3] + control3[4] + control3[7] + control3[8] + control3[9] + control3[10]
			+ select3[0] + select3[1] + mining3[0] + mining3[1] + mining3[2] + mining3[3]
			+ assist4 +miningmodule4 + visualmodule4 + setmodule3[0] + setmodule3[1] + setmodule3[2] + setmodule3[3];
	if(missionpanel.missionnumber[13] == 1) expchoice = expchoice+50;
	if(missionpanel.missionnumber[14] == 1) expchoice = expchoice+50;
	if(missionpanel.missionnumber[15] == 1) expchoice = expchoice + 100;
	
	expuse = mining3[5] + miningmoduleoperation4 + visualmoduleoperation4;
	if(missionpanel.missionnumber[16] == 1) expuse = expuse+100;
	if(missionpanel.missionnumber[17] == 1) expuse = expuse+100;
	
	//if(expuse >= 25000) expuse == 25000
	
	expinter = control3[5] + control3[11] +control3[12] + select3[3] + (inputnumber*5);
	if(missionpanel.missionnumber[10] == 1) expinter = expinter+50;
	if(missionpanel.missionnumber[11] == 1) expinter = expinter+100;
	
	expknow = control3[15] + control3[16] + expknow2 + knowledge3[0] + knowledge3[1]  + knowledge3[2]  + knowledge3[3]  + knowledge3[4];
	if(missionpanel.missionnumber[4] == 1) expknow = expknow+50;
	if(missionpanel.missionnumber[5] == 1) expknow = expknow+100;
	
	expother = control3[2] + control3[6] + mining3[4] + mining3[6] + mining3[7] + mode3[0] + mode3[1] + mode3[2] + mode3[3];
	
	//saveExpFile();
	}
	/*
	public void Expchange(int number)
	{
	if(number == 0){
	expcollect2 = 0;
	} 
	
	if(number == 1){
	expcollect2 = 10;
	}
	if(number == 2){
	expcollect2 = 15;
	}
	if(number >= 3){
	expcollect2 = 14 + number;
	}
	expcollect3[collectcount] = expcollect2;
	collectcount++;
	}
	}*/
	
	public void addExptutorial(int number)
	{
	tutorialexp += number;
	saveExpFile();
	
	}
	
	//Operation: must be executed after selection
	public void addExpByOperatedMiningModule(int miningID)
	{
		int i;
		
		for(i=0;i<miningModuleNumber;i++)
			if(miningModuleID[i] == miningID)
			{
				miningModuleOperationCount[i]++;
				addExpByCountWithoutSave(10, miningModuleOperationCount[i]);
				addCoin(1);
				if(miningID == 1) collectbutton = miningModuleOperationCount[i];
				break;
			}
		
		if(CharacterPanel2.magiccount[1] != 0){
			addCoin(10);
			CharacterPanel2.magiccount[1] = CharacterPanel2.magiccount[1] - 1;
			}
		
		
		
		if(CharacterPanel2.magiccount[3] != 0 && miningID == 1){ //1 == editer
			addCoin(10);
			CharacterPanel2.magiccount[3] = CharacterPanel2.magiccount[3] - 1;
			}
		
		
		
		//if(visualizationModuleID[number] == 38 || visualizationModuleID[number] == 39 || visualizationModuleID[number] == 40 || visualizationModuleID[number] == 41) CharacterPanel2.magiccount[0] = CharacterPanel2.magiccount[0] - 1;
		if(CharacterPanel2.magiccount[0] != 0 && (miningID == 38 || miningID == 39 || miningID == 40 || miningID == 41 || miningID == 20003)){
		addCoin(10);
		CharacterPanel2.magiccount[0] = CharacterPanel2.magiccount[0] - 1;
		} 
		
		
		//if(miningID == 38 || miningID == 39 || miningID == 40 || miningID == 41 || miningID == 20003) expuse++;
		
		saveExpFile();		
	}
	
	//Operation: must be executed after selection	
	public void addExpByOperatedVisualizationModule(int visualizationID)
	{
		int i;
		
		for(i=0;i<visualizationModuleNumber;i++)
			if(visualizationModuleID[i] == visualizationID)
			{
			visualizationModuleOperationCount[i]++;
			addExpByCountWithoutSave(10, visualizationModuleOperationCount[i]);
			addCoin(1);
				break;
			}
		
		
		if(CharacterPanel2.magiccount[1]!= 0){
		addCoin(10);
		CharacterPanel2.magiccount[1] = CharacterPanel2.magiccount[1] - 1;
		}	
	
		//visualizationID2 = visualizationID;
		
		saveExpFile();		
	}	

	public void writeToWriter(BufferedWriter bw1, String words)
	{
		try
		{		
			bw1.write(words);
			bw1.newLine();
		}
		catch(Exception e){
			System.out.println("Text Writing ERROR saveSettingTexts1");
		}		
	}
	
	  public double getDiffTime()
    {
        endTime = System.nanoTime();

		/*		
		 System.out.println("Start = "+startTime);
		 System.out.println("End = "+endTime);	
		 System.out.println("DIFF = "+(endTime - startTime));
		 */			
		
		if(startTime == 0)
			return 0.0;
		else
			return (double)(endTime - startTime)/1000000000.0;
    }	
	/*
	public void Jikken(int number){
	try
	{
	
	File file = new File(control.absolutePath +  "LogData.txt");
	FileWriter filewriter = new FileWriter(file, true);
	filewriter.write(lognumber +":"+totaltimeint +"\n");
	filewriter.close();
	
	
	}catch(IOException ae){
     	System.out.println(ae);
 	}
	 
	lognumber++; 
	
	}
	*/
	
	public void saveExpFile()
	{
		String saveExpTexts = "";
		
		
		String timeInformation = String.format("%.0f",getDiffTime());
		 totaltimeint = timeint2 + Integer.parseInt(timeInformation);
		//if(check == 1) totaltimeint = time1;
		
		try
		{
			StringWriter sw1 = new StringWriter();
			BufferedWriter bw1 = new BufferedWriter(sw1);
			//FileWriter filewriter = new FileWriter(sw1,true);
			
			
			writeToWriter(bw1, ""+rank);
			writeToWriter(bw1, ""+exp);
			writeToWriter(bw1, ""+coin);
			writeToWriter(bw1, ""+ stamina);
			writeToWriter(bw1, ""+ stamina2);
			writeToWriter(bw1, ""+ startingnumber);
			
			for(int i=0;i<controlButtonNumber;i++)
				if(i<controlButtonNumber-1)
					bw1.write(controlButtonCount[i]+" ");
				else
					writeToWriter(bw1,controlButtonCount[i]+"");
			
//			System.out.println("SSSSS");
			
			for(int i=0;i<selectButtonNumber;i++)
				if(i<selectButtonNumber-1)
					bw1.write(selectButtonCount[i]+" ");
				else
					writeToWriter(bw1,selectButtonCount[i]+"");	
			
			for(int i=0;i<miningButtonNumber;i++)
				if(i<miningButtonNumber-1)
					bw1.write(miningButtonCount[i]+" ");
				else
					writeToWriter(bw1,miningButtonCount[i]+"");			
			
			for(int i=0;i<selectionAssistButtonNumber;i++)
				if(i<selectionAssistButtonNumber-1)
					bw1.write(selectionAssistButtonCount[i]+" ");
				else
					writeToWriter(bw1,selectionAssistButtonCount[i]+"");
			
			for(int i=0;i<settingButtonNumber;i++)
				if(i<settingButtonNumber - 1)
					bw1.write(settingButtonCount[i]+" ");
				else
					writeToWriter(bw1,settingButtonCount[i]+"");
			
			for(int i=0;i<modeButtonNumber;i++)
				if(i<modeButtonNumber - 1)
					bw1.write(modeButtonCount[i]+" ");
				else
					writeToWriter(bw1,modeButtonCount[i]+"");
					
			for(int i=0;i<knowledgeButtonNumber;i++)
				if(i<knowledgeButtonNumber - 1)
					bw1.write(knowledgeButtonCount[i]+" ");
				else
					writeToWriter(bw1,knowledgeButtonCount[i]+"");	
			
			for(int i=0;i<setmoduleButtonNumber;i++)
				if(i<setmoduleButtonNumber - 1)
					bw1.write(setmoduleButtonCount[i]+" ");
				else
					writeToWriter(bw1,setmoduleButtonCount[i]+"");
			
//			System.out.println("SSSS");			

			//SELECTION
			//miningModule	8		
			for(int i=0;i<miningModuleNumber;i++)
				if(i<miningModuleNumber-1)
					bw1.write(miningModuleID[i]+" "+miningModuleSelectionCount[i]+",");
				else
					writeToWriter(bw1,miningModuleID[i]+" "+miningModuleSelectionCount[i]);
					
			
			//visualizationModule
			for(int i=0;i<visualizationModuleNumber;i++)
				if(i<visualizationModuleNumber-1)
					bw1.write(visualizationModuleID[i]+" "+visualizationModuleSelectionCount[i]+",");
				else
					writeToWriter(bw1,visualizationModuleID[i]+" "+visualizationModuleSelectionCount[i]);		
			
			//OPERATION
			//miningModule			
			for(int i=0;i<miningModuleNumber;i++)
				if(i<miningModuleNumber-1)
					bw1.write(miningModuleID[i]+" "+miningModuleOperationCount[i]+",");
				else
					writeToWriter(bw1,miningModuleID[i]+" "+miningModuleOperationCount[i]);
			
			
			//visualizationModule
			for(int i=0;i<visualizationModuleNumber;i++)
				if(i<visualizationModuleNumber-1)
					bw1.write(visualizationModuleID[i]+" "+visualizationModuleOperationCount[i]+",");
				else
					writeToWriter(bw1,visualizationModuleID[i]+" "+visualizationModuleOperationCount[i]);			
			
			writeToWriter(bw1, ""+ inputnumber);
			writeToWriter(bw1, ""+ itempanel.mpnumber);
			
			//writeToWriter(bw1, ""+ CharacterData.buycharacternumber[0]);
			//writeToWriter(bw1, ""+ CharacterData.buycharacternumber[0] + " " + CharacterData.buycharacternumber[1] + " " +CharacterData.buycharacternumber[2] + " " + CharacterData.buycharacternumber[3] + " " + CharacterData.buycharacternumber[4] + " " + CharacterData.buycharacternumber[5]);
			
			for(int i=0;i< CharacterData.CharacterNumber;i++)
				if(i<CharacterData.CharacterNumber - 1)
					bw1.write(CharacterData.buycharacternumber[i]+" ");
				else
					writeToWriter(bw1,CharacterData.buycharacternumber[i]+"");	
			
			
			for(int i=0;i< CharacterData.CostumeNumber;i++)
				if(i<CharacterData.CostumeNumber - 1)
					bw1.write(CharacterData.cosnumber[i]+" ");
				else
					writeToWriter(bw1,CharacterData.cosnumber[i]+"");	
			
			writeToWriter(bw1, ""+ CharacterData.nowcharacternumber);
			
			
			for(int i=0;i< MissionPanel.MISSIONNUMBER;i++)
				if(i<MissionPanel.MISSIONNUMBER - 1)
					bw1.write(missionpanel.missionnumber[i]+" ");
				else
					writeToWriter(bw1,missionpanel.missionnumber[i]+"");	
			
//			System.out.println("SSS");				
			
			writeToWriter(bw1, ""+ knowledgenumber);
			writeToWriter(bw1, ""+ expknow2);
			
			
			//if(controlButtonCount[19] == 0 || controlButtonCount[19] == 1){
			if(startingnumber == 0 || startingnumber == 1){
			
			//if(controlButtonCount[19] == 0){
			bw1.write(""+ year + "/" + month + "/" + day);
			}
			else{
			bw1.write("" + time);
			}
			//}
			//else{
			//}
			
			
			bw1.write("\n" + day_of_year);
			
			
			bw1.write("\n" + loginnumber);
			
			bw1.write("\n" + renzokuloginnumber);
			
			bw1.write("\n" + month);
			bw1.write("\n" + daymonthnumber);
			
			//second = Integer.parseInt(String.format("%.0f",control.getDiffTime()));
			//bw1.write("\n" + timeInformation);
			if(check== 0) bw1.write("\n" + totaltimeint);
			else if(check >=1) bw1.write("\n" + (totaltimeint - 5*check));
			
//			System.out.println("SS");			
			
			Exp();
			
			bw1.write("\n" + expcollect);
			//bw1.write("\n" + expformat);
			
			bw1.write("\n" + expchoice);
			
			bw1.write("\n" + expuse);
			bw1.write("\n" + expinter);
			bw1.write("\n" + expknow);
			bw1.write("\n" + tutorialexp);
			bw1.write("\n" + expother);
			
			bw1.write("\n" + TitlePanel.skillrank);
			//bw1.write("\n" + lognumber);
			
			bw1.write("\n" + collectbutton);
			
//			System.out.println("S");			
			
			bw1.flush();
			sw1.flush();
			saveExpTexts = sw1.toString();
			bw1.close();
			sw1.close();
		}
		catch(Exception e){
			System.out.println("Text Writing ERROR saveExpTexts2");
		}
		FILEIO.TextFileWriteCode(new File(expFileName), saveExpTexts, "SJIS");
		
		
	}
	
	
	public void startArrangement(){
		
			myth=new Thread(this);
			myth.start();
		
	}
	
	public void run(){
	
	
	//for(int i=1;;i++){
	//Exp();
	/*
	//File file2 = new File("tetdm.exp");
	//File file3 = new File("NEWACTIONLOG");
	File file3 = new File("ACTIONLOG");
	try
		{
			BufferedReader br2 = new BufferedReader(new FileReader(file3));
			String line = null;
			//String[] strarray = new String[10000];
			String str = null;
			//String[] strtime = new String[6];
			while ((line = br2.readLine()) != null) {
               		str = line;
           		}
			String strtime[] = str.split("\\.");
			time1 = Integer.parseInt(strtime[0]);
			
			//System.out.println(strtime[0]);
			//time1 = Integer.parseInt(strarray[26]);
			
			br2.close();
		}
	catch(Exception e){
			System.out.println("Text Reading ERROR speechtext");
		}
	
	
	String timeInformation = String.format("%.0f",getDiffTime());
	int ntime = Integer.parseInt(timeInformation);
	
	//System.out.println(ntime);
	//System.out.println(time1);
	
	if(ntime > time1 + 60){
	//check++;
	totaltimeint = time1;
	
	}
	//time1 = Integer.parseInt(timetext[26]);
	
	try
		{
			BufferedReader br2 = new BufferedReader(new FileReader(file2));
			String line = null;
			String[] strarray = new String[1000];
			int j = 0;
			while ((line = br2.readLine()) != null) {
               		strarray[j] = line;
			j++;
           		}
			
			time1 = Integer.parseInt(strarray[26]);
			
			br2.close();
		}
	catch(Exception e){
			System.out.println("Text Reading ERROR speechtext");
		}
	
	
	//timetext = FILEIO.TextFileAllReadCodeArray(new File(settingData.absolutePath + "tetdm.exp"));
	//timetext = FILEIO.TextFileAllReadCode(expFile);
	//int timetext = Integer.parseInt(speechtext[26]);
	*/
	/*
	try{
        Thread.sleep(1000);
        }
        catch(InterruptedException e){
		e.printStackTrace();
	}
	*/
	/*
	//timetext2 = FILEIO.TextFileAllReadCodeArray(new File(control.absolutePath + "tetdm.exp"));
	//time2 = Integer.parseInt(timetext2[26]);
	
	try
		{
			BufferedReader br3 = new BufferedReader(new FileReader(file2));
			String line2;
			String[] strarray2 = new String[1000];
			int j2 = 0;
			while ((line2 = br3.readLine()) != null) {
               		strarray2[j2] = line2;
			j2++;
           		}
			
			time2 = Integer.parseInt(strarray2[26]);
			
			br3.close();
		}
	catch(Exception e){
			System.out.println("Text Reading ERROR speechtext");
		}
	
	if(time1 == time2){
	check++;
	saveExpFile();
	//control.bt99.doClick();
	}
	*/
	//}
	//}
	}

}
