自写的整理 源代码文件的程序(本来是用来整理java的)

整理程序

本来是用来整理java的源程序的

  1.但是现在发现要有{ } ; 作为换行基准的都可以使用这个作为规格化代码的工具

  2.主要还是为java提供操作

  3.只需要安装java jre就可以了

可以直接在这里下也可以, 直接去下我传的内容

https://download.csdn.net/download/jsp13270124/11728993

  有时候看同学的代码, 那个格式…看的我脑阔大, 于是就想写一个整理程序
(这是我第一次在这种平台上写东西. 我菜鸟, 但是还是能用, 有什么建议欢迎留言给我)

  处理的例子一:
未编辑的文件样子在这里插入图片描述
  处理后:
在这里插入图片描述

例子二:
在这里插入图片描述
处理后:
在这里插入图片描述

  废话不多说, 直接上代码, 请分开见建文件
  第一个文件, 生成图形化界面, 按钮, 监听器, 读写文件的流操作等

// J_JFrame_Button 文件
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.io.*;

public class J_JFrame_Button extends JFrame
{
	
	public static void main( String[ ] args )
	{
		J_JFrame_Button sample = new J_JFrame_Button( "Test.txt" );
	}

	public J_JFrame_Button( String string_File )
	{
		super( "tool for dos with txt document" );
		Container container = getContentPane( );
		JPanel jPanel_TextArea = new JPanel( );
		JPanel jPanel_Button = new JPanel( );
		JPanel jPanel_DownSide = new JPanel( );
		JPanel jPanel_Change = new JPanel( new GridLayout( 5, 1, 0, 50 ) );
		
		final JTextArea save_JTextArea = new JTextArea( "Save Message:( First input 'R' will restart txt )\n", 20, 40 );
		JScrollPane save_JScrollPane = new JScrollPane( save_JTextArea );
		GetRadioButton RadioButton_Class = mb_SetButton_RedioButton( jPanel_DownSide );
		JLabel word_Number = new JLabel( "" );

		JButton [ ]button_Gourp = mb_GetButton_Annotation( save_JTextArea );			/// add the various elements
		for( JButton temp_Button : button_Gourp )
		{
			jPanel_Change.add( temp_Button );
		}
		jPanel_Change.add( word_Number );
		setLabel( save_JTextArea, word_Number );

		jPanel_TextArea.add( save_JScrollPane );
		jPanel_Button.add( mb_GetButton_Write( save_JTextArea, string_File, RadioButton_Class ) ); 
		jPanel_Button.add( mb_GetButton_Read( save_JTextArea, string_File ) );
		mb_GetKeyBoardListener( save_JTextArea, string_File, RadioButton_Class );
		
		mb_SetButton_Function( jPanel_Button, save_JTextArea );
		mb_SetJTextField( jPanel_DownSide, save_JTextArea );

		add( jPanel_Button, BorderLayout.NORTH );
		add( jPanel_TextArea, BorderLayout.CENTER );
		add( jPanel_DownSide, BorderLayout.SOUTH );
		add( jPanel_Change, BorderLayout.EAST );

		setSize( 600, 500 );
		setVisible( true );
		setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
	}

	public void setLabel( final JTextArea save_JTextArea, JLabel word_Number )
	{
		save_JTextArea.addFocusListener( new FocusAdapter( )
			{
				public void focusGained( FocusEvent e )
				{
					String Temp = save_JTextArea.getText( );
					String Out = "remain:";
					Out = Out.concat( String.valueOf( getLength( Temp ) ) );
					word_Number.setText( Out );
				}
				public void focusLost( FocusEvent e )
				{
					System.out.println( "Out of focus" );
				}
			}
		);
	}

	public GetRadioButton mb_SetButton_RedioButton( JPanel jPanel_DownSide )
	{
		final GetRadioButton RadioButton_Class = new GetRadioButton( );
		JRadioButton[ ] radioButton = RadioButton_Class.getRadioButton( );
		for( JRadioButton temp_Radio : radioButton )
		{
			jPanel_DownSide.add( temp_Radio );
		}
		return RadioButton_Class;
	}
	
	public void mb_SetButton_Function( JPanel jPanel_Button, final JTextArea save_JTextArea  )
	{
		JButton[ ] button_Function = mb_GetButton_Function( save_JTextArea );
		for( JButton function_button : button_Function )
		{
			jPanel_Button.add( function_button );
		}
	}
		
	public void mb_SetJTextField( JPanel jPanel_DownSide, final JTextArea save_JTextArea )
	{
		final JTextField file_Text = new JTextField( 10 );
		file_Text.addKeyListener( new KeyAdapter( )
			{
				public void keyPressed( KeyEvent e )
				{
					if( e.getKeyChar( ) == KeyEvent.VK_ENTER )
					{
						String string_File = file_Text.getText( );
						String string_Output = "Save Message:( First input 'R' will restart txt )\n";
						string_Output = string_Output.concat( mb_Read_Txt( string_File ) );
						save_JTextArea.setText( string_Output );	
					}
				}
			}
		);
		jPanel_DownSide.add( file_Text );

		JButton[ ] button_Function_Read = mb_GetButton_ReadFileName( save_JTextArea, file_Text );
		for ( JButton readButton : button_Function_Read )
		{
			jPanel_DownSide.add( readButton );
		}
	}
	
	public JButton[ ] mb_GetButton_Annotation( final JTextArea save_JTextArea )
	{
		class Button_Change_Listener implements ActionListener
		{
			String text;
			String after_Change;
			public void actionPerformed( ActionEvent e )
			{
				if( e.getActionCommand( ).intern( ) == "Annotation" )
				{
					JButton Middle = ( JButton )e.getSource( );
					text = ( save_JTextArea.getText( ) ).substring( 50 );
					after_Change = text.replaceAll("\\/\\/[^\\n]*|\\/\\*([^\\*^\\/]*|[\\*^\\/*]*|[^\\**\\/]*)*\\*+\\/", "");
				}
				else if( e.getActionCommand( ).intern( ) == "Format" )
				{
					text = ( save_JTextArea.getText( ) ).substring( 50 );
					TestString test = new TestString( );
					// System.out.println( "Text" + text );
					after_Change = test.change_Format_Ex( text );
					System.out.println( "success Deal Format" );
					// new JButton [ ] { button_ReadFile, button_ClearAll };
				}
				else if( e.getActionCommand( ).intern( ) == "Deal For" )
				{
					text = ( save_JTextArea.getText( ) ).substring( 50 );
					String_For test = new String_For( );
					// System.out.println( "Text" + text );
					after_Change = test.dealString( text );
					System.out.println( "success Deal For( ;; )" );
				}
				else if( e.getActionCommand( ).intern( ) == "Deal else" )
				{
					text = ( save_JTextArea.getText( ) ).substring( 50 );
					TestString test = new TestString( );
					// System.out.println( "Text" + text );
					after_Change = test.check_else( text );
					System.out.println( "success Deal else" );
					// System.out.println( after_Change );
				}
				after_Change = "Save Message:( First input 'R' will restart txt )\n".concat( after_Change );
				save_JTextArea.setText( after_Change );
			}
		}
		
		JButton button_Annotation = new JButton( "Annotation" );
		JButton button_Change = new JButton( "Format" );
		JButton button_For = new JButton("Deal For");
		JButton button_else = new JButton( "Deal else" );
			
		JButton [ ]button_Gourp = new JButton [ ] { button_Annotation, button_Change, button_For, button_else };
			
		for( JButton temp_Button : button_Gourp )
		{
			temp_Button.addActionListener( new Button_Change_Listener( ) );
		}
		//button_Change.addActionListener( new Button_Change_Listener( ) );
		//button_Annotation.addActionListener( new Button_Change_Listener( ) );
		//button_For.addActionListener( new Button_Change_Listener( ) );

		return button_Gourp;
	}
	
	public JButton[ ] mb_GetButton_ReadFileName( final JTextArea save_JTextArea, final JTextField file_Text )
	{
		class read_Specified_Listener implements ActionListener
		{
			public void actionPerformed( ActionEvent e )
			{
				if( e.getActionCommand( ).intern( ) == "Specified Read" )
				{
					String string_File = file_Text.getText( );
					String string_Output = "Save Message:( First input 'R' will restart txt )\n";
					string_Output = string_Output.concat( mb_Read_Txt( string_File ) );
					save_JTextArea.setText( string_Output );
					save_JTextArea.grabFocus( );
				}
				else
				{
					save_JTextArea.setText( "Save Message:( First input 'R' will restart txt )\n" );
					save_JTextArea.setCaretPosition( 50 );
					save_JTextArea.grabFocus( );	
				}
			}
		}
		JButton button_ReadFile = new JButton( "Specified Read" );
		JButton button_ClearAll = new JButton( "Clear All" );

		button_ReadFile.addActionListener( new read_Specified_Listener( ) );
		button_ClearAll.addActionListener( new read_Specified_Listener( ) );
		JButton[ ] button_Function_Read = new JButton [ ] { button_ReadFile, button_ClearAll };

		return button_Function_Read;
	}
	
	public JButton mb_GetButton_Write( final JTextArea save_JTextArea, final String string_File, final GetRadioButton RadioButton_Class )
	{
		JButton button_Write = new JButton( "Write txt" );
		button_Write.addActionListener( new ActionListener( )
			{
				public void actionPerformed( ActionEvent e )
				{
					JButton button_Write = ( JButton )e.getSource( );
					String string_Write_Text = ( save_JTextArea.getText( ) ).substring( 50 );
					
					mb_Write_Txt( string_Write_Text, string_File, RadioButton_Class );
					save_JTextArea.setText( "Save Message:( First input 'R' will restart txt )\n" );
					save_JTextArea.setCaretPosition( 50 );
					save_JTextArea.grabFocus( );				
				}
			}
		);
		return button_Write;
	}

	public JButton mb_GetButton_Read( final JTextArea save_JTextArea, final String string_File  )
	{
		JButton button_Read = new JButton( "Read Txt" );
		button_Read.addActionListener( new ActionListener( )
			{
				public void actionPerformed( ActionEvent e )
				{
					String string_Output = "Save Message:( First input 'R' will restart txt )\n";
					string_Output = string_Output.concat( mb_Read_Txt( string_File ) );
					save_JTextArea.setText( string_Output );
					save_JTextArea.grabFocus( );
					System.out.println( string_Output );
				}
			}
		);
		return button_Read;
	}
//
	public JButton mb_GetButton_Changeformat( final JTextArea save_JTextArea, final String string_File )
	{
		JButton button_Format = new JButton( "Format" );
		button_Format.addActionListener( new ActionListener( )
			{
				public void actionPerformed( ActionEvent e )
				{
					String string_Output = "Save Message:( First input 'R' will restart txt )\n";
					string_Output = string_Output.concat( mb_Read_Txt( string_File ) );
					System.out.println( string_Output );
					save_JTextArea.setText( changeFormat( string_Output ) );
					save_JTextArea.grabFocus( );
					System.out.println( "Change_Format" );
				}
			}
		);
		return button_Format;
	}

	public String changeFormat( String str_Input )
	{
		String str_Clear = "";
		String str_Fin = "";
		String str_Temp = "";
		String str_Temp_Save = "";
		boolean flag = false;
		boolean judge1, judge2, judge3, judge4; 
		for( int i = 0; i < str_Input.length( ); i++ )
		{
			str_Temp = str_Input.substring( i, i +1 );

			judge1 = str_Temp.intern( ) == "\n".intern( );
			judge2 = ( str_Temp.intern( ) ==  " ".intern( ) ) || ( str_Temp.intern( ) == "\t".intern( ) ) && flag;
			judge3 = ( str_Temp.intern( ) != " ".intern( ) )  || ( str_Temp.intern( ) != "\t".intern( ) ) && flag;

			if( judge1 )
			{
				flag = true;
			}
			else if( judge2 )
			{}
			else if( judge3 )
			{
				str_Clear = str_Clear.concat( str_Temp );
				flag = false;
			}
			else if( !flag )
			{
				str_Clear = str_Clear.concat( str_Temp );
			}
		}
		System.out.println( str_Clear );
		str_Temp = "";
		int blank_Number = 0;
		for( int i = 0; i < str_Clear.length( ); i++ )
		{
			str_Temp = str_Clear.substring( i, i + 1 );
			if( blank_Number == 0 )
			{
				str_Fin = str_Fin.concat( str_Temp );
			}
		}
		System.out.println( str_Clear );
		return str_Clear;
	}
//
	public JButton[ ] mb_GetButton_Function( final JTextArea save_JTextArea )
	{
		class button_Function_Listener implements ActionListener
		{
			public void actionPerformed( ActionEvent e )
			{
				System.out.println( e.getActionCommand( ) );
				if( ( e.getActionCommand( ) ).intern( ) == "Clear".intern( ) )
				{
					save_JTextArea.setText( "Save Message:( First input 'R' will restart txt )\n" );
					save_JTextArea.grabFocus( );
				}
				else if( (e.getActionCommand( ) ).intern( ) == "Upside".intern( ) )
				{
					save_JTextArea.setCaretPosition( 50 );
					save_JTextArea.grabFocus( );
				}
				else
				{
					save_JTextArea.setCaretPosition( ( save_JTextArea.getDocument( ) ).getLength( ) );
					save_JTextArea.grabFocus( );
				}
			}
		}
		JButton[ ] button_Function = new JButton[ 3 ];

		JButton button_Clear = new JButton( "Clear" );
		JButton button_Upside = new JButton( "Upside" );
		JButton button_Downside = new JButton( "Downside" );

		button_Function_Listener Function_Button_Listener = new button_Function_Listener( );

		button_Clear.addActionListener( Function_Button_Listener );
		button_Upside.addActionListener( Function_Button_Listener );
		button_Downside.addActionListener( Function_Button_Listener );

		button_Function = new JButton [ ] { button_Clear, button_Upside, button_Downside };
		return button_Function;
	}

	public void mb_GetKeyBoardListener( final JTextArea save_JTextArea, final String string_File, final GetRadioButton RadioButton_Class )
	{
		save_JTextArea.addKeyListener( new KeyAdapter( )
			{
				public void keyPressed( KeyEvent e )
				{
					if( e.getKeyChar( ) == KeyEvent.VK_ENTER || e.isControlDown( ) )
					{
						String string_Write_Text;
						if( false )// e.getKeyChar( ) == KeyEvent.VK_ENTER allow Enter press
						{
							string_Write_Text = ( save_JTextArea.getText( ) ).substring( 50 );
							mb_Write_Txt( string_Write_Text, string_File, RadioButton_Class );
							save_JTextArea.setText( "Save Message:( First input 'R' will restart txt )" );
							save_JTextArea.setCaretPosition( 49 );
						}
						else if( e.isControlDown( ) )
						{
							string_Write_Text = ( save_JTextArea.getText( ) ).substring( 50 );
							mb_Write_Txt( string_Write_Text, string_File, RadioButton_Class );
							save_JTextArea.setText( "Save Message:( First input 'R' will restart txt )\n\n" );
							save_JTextArea.setCaretPosition( 50 );
						}
						// String string_Arrary_Write_Text[ ] = string_Write_Text.split( "\n" );
						save_JTextArea.grabFocus( );
					}
				}
			}
		);
	}
	
	// This method can solve the write can't  line feed. and get
	public void mb_Write_Txt( String string_Write_Text, String string_File, final GetRadioButton RadioButton_Class )
	{	
		try
		{
			boolean write_Judge;
			System.out.println( string_Write_Text );
			String string_Arrary_Write[ ];
			boolean save_Judge1;
			boolean save_Judge2;
			boolean save_Judge3;
	
			if( string_Write_Text.length( ) == 1 )
			{
				save_Judge1 = string_Write_Text.substring( 0, 1 ).intern( ) == "R".intern( );
				save_Judge2 = false;
				save_Judge3 = false;
			}
			else if( string_Write_Text.length( ) >= 2 )
			{
				save_Judge1 = string_Write_Text.substring( 0, 1 ).intern( ) == "R".intern( );
				save_Judge2 = string_Write_Text.substring( 0, 2 ).intern( ) == "R ".intern( );
				save_Judge3 = string_Write_Text.substring( 0, 2 ).intern( ) == "R\n".intern( );
			}
			else
			{
				save_Judge1 = false;
				save_Judge2 = false;
				save_Judge3 = false;
			}

			// System.out.println( string_Write_Text.substring( 0, 1 ) );
			if( save_Judge2 || save_Judge3 )
			{
				write_Judge = false;
				string_Arrary_Write = ( string_Write_Text.substring( 2 ) ).split( "\n" );
			}
			else if( save_Judge1 )
			{
				write_Judge = false;
				string_Arrary_Write = ( string_Write_Text.substring( 1 ) ).split( "\n" );
				// System.out.println( "Test" );
			}
			else
			{
				write_Judge = true;
				string_Arrary_Write = string_Write_Text.split( "\n" );
			}

			//  When we don't depend on charater 'R', we depend on GetRadio
			if ( ( save_Judge1 || save_Judge2 || save_Judge3 ) != true )
			{
				write_Judge = RadioButton_Class.getRe_AddProperty( );
			}
			
			FileOutputStream outputStream_File = new FileOutputStream( string_File, write_Judge );
			for( String string_Write : string_Arrary_Write )
			{
				if( string_Write.length( ) != 0 )
				{
					byte byte_Output_Middle[ ] = string_Write.getBytes( );
					outputStream_File.write( byte_Output_Middle );
					outputStream_File.write( "\r\n".getBytes( ) );
				}
			}
			outputStream_File.flush( );
			outputStream_File.close( );
		
			// byte byte_Output[ ] = string_Write_Text.getBytes( );
			// outputStream_File.write( byte_Output );
		}
		catch( IOException e )
		{
			System.err.println( "Exception: " + e.getMessage( ) );
		}
	}

/* ///old InputStream
	public String mb_Read_Txt( String string_File )
	{
		String string_fin = "";
		try
		{
			FileInputStream inputStream_file = new FileInputStream( string_File );
			int int_Byte_Input;
			while ( ( int_Byte_Input = inputStream_file.read( ) ) != -1 )
			{
				string_fin = string_fin.concat( String.valueOf( ( char )int_Byte_Input ) );
			}
			return string_fin;
		}
		catch( IOException e )
		{
			System.err.println( "Exception: " + e.getMessage( ) );
		}
		return "error!";
	}
/  */
		
	public String mb_Read_Txt( String string_File )
	{
		String string_Fin = "";
		try
		{
			FileInputStream inputStream_file = new FileInputStream( string_File );
			BufferedReader string_Reader = new BufferedReader( new InputStreamReader( inputStream_file, "GBK" ) );
			String string_Middle;
			while( ( string_Middle = string_Reader.readLine( ) ) != null )
			{
				string_Fin = string_Fin.concat( string_Middle );
				string_Fin = string_Fin.concat( "\n" );
			}
			return string_Fin;
		}
		catch( IOException e )
		{
			System.err.println( "Exception: " + e.getMessage( ) );
		}
		return "error";
	}
	
	public int getLength( String str_Input )				// request total have word quantity
	{
		String str_Temp;
		int total = -41;					// remain	word minus start word	
		for( int i = 0; i < str_Input.length( ); i++ )
		{
			str_Temp = str_Input.substring( i, i + 1 );
			if( str_Temp.intern( ) != " ".intern( ) && str_Temp.intern( ) != "\t".intern( ) && str_Temp.intern( ) != "\n".intern( ) )
			{
				total++;
			}
		}
		return total;
	}

			// System.out.println( string_Write_Text.substring( 1 ) );
			// for( String save : string_Arrary_Write )
			// {
			// 	System.out.println( save );
			// }

	/* ///Test:( row : 97 )
			// System.out.println( string_Write_Text.substring( 0, 3 ) ); 
			// System.out.println( string_Write_Text.substring( 0, 2 ).intern( ) == "R ".intern( )  );  
			// System.out.println( "R ".intern( ) == "R ".intern( )  );
	/// */

	public String mb_Combine( String string_Middle_Write[ ] )
	{
		String combine_String = "";
		for( String  middle : string_Middle_Write )
		{
			combine_String = combine_String.concat( middle );
		}
		return combine_String;
	}
}

第二个程序文件, 处理整理的问题

// J_JFrame_Button 文件
public class TestString
{

	public static void main( String[ ] args )
	{
		TestString sample = new TestString( );
		// System.out.println( sample.get_Format_Right( "public{public static main(){abc(){fuck;println();for(){fuck;}}abd(){ fuck agin;}}}" ) );
		// System.out.println( "public{public static main(){abc(){fuck;println();for(){fuck;}}abd(){ fuck agin;}}}" ) ;// "\n\t\t fuck\n\n\t\tfuck fuck;\n"
		// System.out.println( sample.change_Format_Ex( "public\n\t{\npublic static main(){\nabc(){\n fuck;println();for(){fuck;}}abd(){ fuck agin;}}}" ) );
		// System.out.println( "Finally:\n\n" + sample.change_Format( "public{public static void main(String args[ ]){abc(){fuck(getName(), getName2());while(ret.next(TestSysmbol)){System.out.println(ret.getString(1));}println();for(){fuck;}}abd(){ fuck agin;}}}" ) );
		// System.out.println( sample.check_Array( "public class Test\n{\n\tpublic static void main( String args[ ] )\n\t{\n\t\t{\n\t\t\t{\n\t\t\t\tFuck, you\n\t\t\t}\n\t\t\t;\n\t\t\tSystem.out.println( Test );\n\t\t}\n\t}\n}" ) );
		// System.out.println( "public class Test\n{\n\tpublic static void main( String args[ ] )\n\t{\n\t\t{\n\t\t\t{Fuck, you};\n\t\t\tSystem.out.println( Test );\n\t\t}\n\t}\n}" );
		// System.out.println( "public class Test\n{\n\tpublic static void main( String args[ ] )\n\t{\n\t\t{\n\t\t\t{\n\t\t\t\tFuck, you\n\t\t\t}\n\t\t\t;\n\t\t\tSystem.out.println( Test );\n\t\t}\n\t}\n}" ); 
		//System.out.println( sample.check_Array("\t\t{\n\t\t\t{Fuck, you}\t;\n\t\t\tSystem.out.println( Test );\n\t\t}") );
		//System.out.println( "\t\t{\n\t\t\t{Fuck, you}\t;\n\t\t\tSystem.out.println( Test );\n\t\t}" );
		System.out.println( sample.check_else( "elseSystem" ) );
	}


	public String change_Format_Ex( String str_Input )
	{
		str_Input = change_Clear_Blank( str_Input );
		// System.out.println( str_Input );
		str_Input = change_Format( str_Input );
		str_Input = check_Array( str_Input );
		// str_Input = check_else( str_Input );
		return str_Input;
	}
	
	public String change_Clear_Blank( String str_Input )
	{
		String str_Clear = "";
		String str_Temp = "";
		String str_Save = "";
		String str_Compare = "";
		boolean flag_Enter = true;
		boolean flag_Bracket = true;			/ record state
		boolean judge1, judge2, judge3, judge4; 
		int j = 1;

		for( int i = 0; i < str_Input.length( ); i++ )
		{
			
			str_Temp = str_Input.substring( i, i + 1 );     		 if flag_Enter == false means it's can't be changed direct adding after
			
			// System.out.println(  j < str_Input.length( ) );
			if( j < str_Input.length( ) )
			{
				str_Save = str_Input.substring( j, j + 1 );
				j = j + 1;
			}

			if( str_Temp.intern( ) == "{".intern( ) )// && ( str_Compare.intern( ) == " ".intern( ) || str_Compare.intern( ) == "\t".intern( ) )
			{
				str_Clear = str_Clear.concat( "{" );
				flag_Bracket = false;
			}			

			if( str_Temp.intern( ) == "\n".intern( ) ) ///have Enter
			{
				flag_Enter = false;				// flag_Enter means that we should ignore after '\n' figure
			}
			else if( !flag_Enter )					// ( str_Save.intern( ) != " ".intern( ) && str_Save.intern( ) != "\t".intern( ) ) &&
			{
				if( str_Temp.intern( ) != " ".intern( ) && str_Temp.intern( ) != "\t".intern( ) )
				{
					flag_Enter = true;
				}
			}
			
			if( str_Temp.intern( ) == "\n".intern( ) && !flag_Bracket && str_Temp.intern( ) != "{".intern( ) )
			{
				flag_Bracket = true;
			}
	
			if( ( str_Temp.intern( ) != " ".intern( ) && str_Temp.intern( ) != "\t".intern( ) ) && !flag_Bracket && str_Temp.intern( ) != "{".intern( ) )
			{
				flag_Bracket = true;
			}

			if( flag_Enter && str_Temp.intern( ) != "\n" && flag_Bracket )
			{
				str_Clear = str_Clear.concat( str_Temp );
			}
		}
		// System.out.println( str_Clear );
		return str_Clear;
	}
	
	public String check_Array( String str_Input )				/// BIG problem translate many smile problem
	{
		String str_Fin = "";
		String str_Temp = "";
		String str_Save = "";
		String str_Next = "";
		boolean flag_Bracket = false;					/// is Symbol that after that we should care whether have ';'
		int count_Bracket = -1;					/// count_Bracket == -1 for start state
		int record_Location[ ] = new int[ 100 ];
		
		for( int i = 0; i < str_Input.length( ); i++ )
		{
			str_Temp = str_Input.substring( i, i + 1 );
	
			str_Fin = str_Fin.concat( str_Temp );

			if( str_Temp.intern( ) == "{".intern( ) )				// only save '{'
			{	//\t\t{\n\t\t\t{Fuck, you}\t;\n\t\t\tSystem.out.println( Test );\n\t\t}
				count_Bracket++;
				record_Location[ count_Bracket ] = str_Fin.length( ) - 1;	// location not Number	
				System.out.println( str_Fin.length( ) - 1 + "  i: " + i );
			}


			if( str_Temp.intern( ) == "}" )
			{
				flag_Bracket = true;
				count_Bracket++;
			}							// deal with
			else if( str_Temp.intern( ) == ";".intern( ) && flag_Bracket )		//	{ <- upper
			{							//		7, 8, 6
				int upper, floor;					//	} 
				floor = str_Fin.length( );				//	; <- floor
				upper = record_Location[ count_Bracket ];		// start from -1
				//System.out.println( count_Bracket + " count Test\n" + record_Location[ count_Bracket + 1 ] );
				//for( int Test : record_Location )
				//{System.out.println( Test );}
				System.out.println( "Test upper, floor\n" + str_Fin.substring( upper  , floor ) + "\nupper " + upper + " floor " + floor );
				System.out.println( "Test Fuck you:\n" + change_Clear_Blank( str_Fin.substring( upper , floor ) ) );
				str_Fin = ( str_Fin.substring( 0, upper ) ).concat( change_Clear_Blank( str_Fin.substring( upper , floor ) ) );
			}	// ( upper, floor )
			else if( str_Temp.intern( ) != " ".intern( ) && str_Temp.intern( ) != "\t".intern( ) && str_Temp.intern( ) != "\n".intern( ) )
			{
				flag_Bracket = false;
			}

			if( str_Temp.intern( ) == "}".intern( ) )				// delete '{'
			{
				record_Location[ count_Bracket ] = 0;	
				count_Bracket--;
			}

			
		}
		return str_Fin;
	}
	
	public String check_else( String str_Input )					// this method is for else
	{
		String str_Temp = "";
		String str_Fin = "";
		String str_Next = "";
		boolean flag_Word = false;						// confirm word
		boolean flag_Confirm = false;						// judge for 'else' should have blank after it
	
		
		for( int i = 0; i < str_Input.length( ); i++ )
		{
			str_Temp = str_Input.substring( i, i + 1 );				
			
			str_Fin = str_Fin.concat( str_Temp );				// Shouldn't Deal things adding after sentives
			
			if( i + 1 < str_Input.length( ) )
			{
				str_Next = str_Input.substring( i + 1, i + 2 );
			}

			if( str_Temp.intern( ) == "e".intern( ) && !flag_Word )
			{
				flag_Word = true;
			}
			else if( str_Temp.intern( ) == "l".intern( ) && flag_Word )
			{	}
			else if( str_Temp.intern( ) == "s".intern( ) && flag_Word )
			{	}
			else if( str_Temp.intern( ) == "e".intern( ) && flag_Word )
			{
				//System.out.println( "Test" );
				if( str_Next.intern( ) != " " && str_Next.intern( ) != "\t" && str_Next != "\n" )
				{
					str_Fin = str_Fin.concat( " " );
				}
			}
			else
			{
				flag_Word = false;
			}
		}
		return str_Fin;
	}
	
	public String change_Format( String str_Input )
	{
		String str_Temp = "";
		String str_Fin = "";
		String str_Next = "";
		int blank_Number = 0;
		int i;
		for( i = 0; i < str_Input.length( ); i++ )
		{
			str_Temp = str_Input.substring( i, i + 1 );
			
			if( i + 1 < str_Input.length( ) )
			{
				str_Next = str_Input.substring( i + 1, i + 2 );
			}
			
			if( str_Temp.intern( ) != "{".intern( ) && str_Temp.intern( ) != "}".intern( ) && str_Temp.intern( ) != ";".intern( ) )
			{
				str_Fin = str_Fin.concat( str_Temp );		// demand \n { } 
			}
			else if( str_Temp.intern( ) == ";".intern( ) )
			{
				if( str_Next.intern( ) != "}".intern( ) )
				{
					str_Fin = str_Fin.concat( ";\n" );			// add ; same time add \n
					for( int j = 0;j < blank_Number;j++ )
					{
						str_Fin = str_Fin.concat( "\t" );		// blank for next line
					}
				}
				else if( str_Next.intern( ) == "}".intern( ) )
				{
					str_Fin = str_Fin.concat( ";" );
				}
			}
			else if( str_Temp.intern( ) == "{".intern( ) )
			{
				str_Fin = str_Fin.concat( "\n" );			// next line
				for( int j = 0; j < blank_Number; j++ )		// blank for {
				{
					str_Fin = str_Fin.concat( "\t" );
				}
				str_Fin = str_Fin.concat( "{" );				// add {
				blank_Number++;								// blank_Number + 1
				str_Fin = str_Fin.concat( "\n" );			// next line
				for( int j = 0; j < blank_Number; j++ )		// blank for next line
				{
					str_Fin = str_Fin.concat( "\t" );
				}
			}
			else if( str_Temp.intern( ) == "}".intern( ) )
			{
				str_Fin = str_Fin.concat( "\n" );
				blank_Number--;								// blank_Number - 1
				for( int j = 0; j < blank_Number; j++ )		// blank for {
				{
					str_Fin = str_Fin.concat( "\t" );
				}
				str_Fin = str_Fin.concat( "}" );				// add {
				str_Fin = str_Fin.concat( "\n" );			// next line
				for( int j = 0; j < blank_Number; j++ )		// blank for next line
				{
					str_Fin = str_Fin.concat( "\t" );
				}
			}

				
		}
		return str_Fin;
	}

	public String get_Format_Right( String str_Input )
	{
		String str_Fin = "";
		String str_Temp = "";
		String str_Save = "";
		int blank_Number = 0;
		int bracket_Number = 0;
		boolean flag = true;
		
		str_Fin = str_Input.substring( 0 , 1 );
		for( int j = 1; j < str_Input.length( ); j++ )
		{
			str_Temp = str_Input.substring( j, j+1 );

			if( str_Temp.intern( ) == "(" )
			{
				bracket_Number++;
				System.out.println( "str_Save:\n" + str_Save + "\nstr_Temp:\n" +str_Temp + "\nstr_Fin:\n" + str_Fin);
			}
			else if( str_Temp.intern( ) == ")" )
			{
				bracket_Number--;
				System.out.println( "str_Save:\n" + str_Save + "\nstr_Temp:\n" + "\nstr_Fin:\n" + str_Fin);
			}

			if( str_Temp.intern( ) != ")" && flag )
			{
				
				if( str_Temp.intern( ) == "{".intern( ) )
				{
					str_Fin = str_Fin.concat( "\n" );
					for( int i = 0; i < blank_Number; i++ )			// insert Enter
					{
						str_Fin = str_Fin.concat( "\t" );
					}
					blank_Number = blank_Number + 1;
					str_Fin = str_Fin.concat( "{\n" );
					// System.out.println( str_Fin );
					for( int i = 0; i < blank_Number; i++ )			// insert Enter
					{
						str_Fin = str_Fin.concat( "\t" );
					}
				}
				else
				{
					str_Fin = str_Fin.concat( str_Temp );
				}
				// flag = false;
			}
			else if( str_Temp.intern( ) == ")".intern( ) )
			{
				str_Save = ")";
				int Count_Temp = bracket_Number;
				if( Count_Temp > 1 )
				{
					while( Count_Temp > 0 )			///
					{
						str_Fin = str_Fin.concat( ")" );
						Count_Temp--;
					}
				}
				flag = false;
			}
			else if( str_Save.concat( str_Temp ).intern( ) == ");".intern( ) )
			{
				str_Fin = str_Fin.concat( ");" );
				for( int i = 0; i < blank_Number; i++ )			// insert Enter
				{
					str_Fin = str_Fin.concat( "\t" );
				}
				flag = true;
			}
			else if(  str_Save.concat( str_Temp ).intern( ) == "){".intern( ) )
			{
				str_Fin = str_Fin.concat( ")\n" );			// insert Enter

				
				System.out.println( "blank_Number " + blank_Number );
				for( int i = 0; i < blank_Number; i++ )			// insert Enter
				{
					str_Fin = str_Fin.concat( "\t" );
				}
				str_Fin = str_Fin.concat( "{" );
				blank_Number = blank_Number + 1;
				str_Fin = str_Fin.concat( "\n" );

				// System.out.println( blank_Number );
				for( int i = 0; i < blank_Number; i++ )			// insert Enter
				{
					str_Fin = str_Fin.concat( "\t" );
				}

				flag = true;
			}
			else if( str_Save.concat( str_Temp ).intern( ) == ") ".intern( ) )
			{
				str_Save = ") ";
				flag = false;
			}
			else if( str_Save.concat( str_Temp ).intern( ) == ") ;".intern( ) )
			{
				str_Fin = str_Fin.concat( ");" );
				for( int i = 0; i < blank_Number; i++ )			// insert Enter
				{
					str_Fin = str_Fin.concat( "\t" );
				}
				flag = true;
			}
			else if( str_Save.concat( str_Temp ).intern( ) == ") {".intern( ) )
			{
				str_Fin = str_Fin.concat( ")\n" );			// insert Enter

				
				System.out.println( "blank_Number " + blank_Number );
				for( int i = 0; i < blank_Number; i++ )			// insert Enter
				{
					str_Fin = str_Fin.concat( "\t" );
				}
				str_Fin = str_Fin.concat( "{" );
				blank_Number = blank_Number + 1;
				str_Fin = str_Fin.concat( "\n" );

				// System.out.println( blank_Number );
				for( int i = 0; i < blank_Number; i++ )			// insert Enter
				{
					str_Fin = str_Fin.concat( "\t" );
				}

				flag = true;
			}
			else if( str_Save.concat( str_Temp ).intern( ) == ")\t".intern( ) )
			{
				str_Save = ")\t";
				flag = false;
			}
			else if( str_Save.concat( str_Temp ).intern( ) == ")\t{".intern( ) )
			{
				str_Save = ")".concat( "\n" );			// insert Enter
				// System.out.println( blank_Number );
				// System.out.println( "use this" );

				blank_Number = blank_Number + 1;
				str_Save = str_Save.concat( "{" );

				str_Save = str_Save.concat( "\n" );

				// System.out.println( blank_Number );
				for( int i = 1; i < blank_Number; i++ )			// insert Enter
				{
					str_Save = str_Save.concat( "\t" );
				}

				str_Fin = str_Fin.concat( str_Save );
				
				str_Save = "";
				flag = true;
			}
			//( str_Save.intern( ) == ")".intern( ) || str_Save.intern( ) == ") ".intern( ) ) && str_Temp.intern( ) !="}".intern( )
			else if( str_Save.intern( ) == ")" && !flag && str_Save.intern( ) != "}"  ) //&& str_Save.intern( ) != "}"
			{
				// System.out.print( j + "Number" + str_Save.concat( str_Temp ) );
				str_Fin = str_Fin.concat( str_Save.concat( str_Temp ) );
				str_Save = "";
				flag =true;
			}
			else 
			{
				flag = true;
				str_Save = "";
			}



			if( str_Temp.intern( ) == ";" )
			{
				String advance;
				if( j + 1 < str_Input.length( ) )
				{
					advance = str_Input.substring( j + 1, j + 2 );
				}
				else
				{
					advance = "error";
				}
			
				if( ( advance.intern( ) != " ".intern( ) || advance != "\t".intern( ) ) && advance.intern( ) != "}".intern( ) )
				{
					// System.out.println( advance );
					str_Fin = str_Fin.concat( "\n" );
					for( int i = 0; i < blank_Number; i++ )			// insert Enter
					{
						str_Fin = str_Fin.concat( "\t" );
					}
				}
			}			
			


			if( str_Temp.intern( ) == "}".intern( ) )
			{
				str_Fin = str_Fin.substring( 0, str_Fin.length( ) - 1 );
				blank_Number = blank_Number - 1;
				str_Fin = str_Fin.concat( "\n" );
				// System.out.println( blank_Number );
				for( int i = 0; i < blank_Number; i++ )			// insert Enter
				{
					str_Fin = str_Fin.concat( "\t" );
				}
				str_Fin = str_Fin.concat( "}\n" );
				for( int i = 0; i < blank_Number; i++ )			// insert Enter
				{
					str_Fin = str_Fin.concat( "\t" );
				}
			}
		}

		// System.out.println( str_Fin );
		return str_Fin;
	}
}

第三个文件按钮组

///按钮组的类
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.io.*;

public class GetRadioButton
{
	public boolean re_Add;

	public boolean getRe_AddProperty( )
	{
		return re_Add;
	}

	public JRadioButton[ ] getRadioButton(  )
	{
		JRadioButton reButton = new JRadioButton( "ReStart" );
		JRadioButton addButton = new JRadioButton( "Adding",true );
		JRadioButton[ ] reStart_Or_Adding = new JRadioButton [ ] { reButton, addButton };
		addListener( reStart_Or_Adding );
		
		ButtonGroup button_Group = new ButtonGroup( );

		for( JRadioButton radio_Button : reStart_Or_Adding )
		{
			button_Group.add( radio_Button );
			System.out.println( radio_Button.getText( ) );
		}
		return reStart_Or_Adding;
	}
	
	public void addListener( JRadioButton[ ] reStart_Or_Adding )
	{
		class RedioButton_Listener implements ActionListener
		{
			public void actionPerformed( ActionEvent e )
			{
				System.out.println( e.getActionCommand( ) );
				if( ( e.getActionCommand( ) ).intern( ) == "ReStart".intern( ) )
				{
					re_Add = false;
				}
				else
				{
					re_Add = true;
				}
			}
		}
		
		for( JRadioButton readio_Button : reStart_Or_Adding )
		{
			readio_Button.addActionListener( new RedioButton_Listener( ) );
		}
	}
}

第四个文件, 处理for语句的bug, 和在TestString有点不好和, 但是降低了速度…
如果可以的话希望有人能指点一下…

public class String_For
{
	public static void main( String args[ ] )
	{
		String_For sample = new String_For( );
		String str_Test = "public static void main( String args[ ] )\n{\n\tfor( int i = 0;\n\t i < getName( fuck.getName( ) );\n\t i++ )\n\t{\n\t\tSystem.out.println( );\n\t}\n}";
		System.out.println( str_Test + "\n\n" + sample.dealString( str_Test ) );
	}	
	
	public String dealString( String str_Input )			//Find (;;) sentence
	{
		boolean flag_Frist = false;			// ( 'on-off'
		boolean flag_Second;
		int count = 0;
		int count_Parentheses = 0;
		String str_Temp;
		String str_Fin = "";
		String str_Save = "";
		for( int i = 0; i < str_Input.length( ); i++ )		// regular expression
		{
			str_Temp = str_Input.substring( i, i + 1 );

			if( str_Temp.intern( ) == "(".intern( ) )
			{
				count_Parentheses++;
			}
			else if( str_Temp.intern( ) == ")".intern( ) )
			{
				count_Parentheses--;
			}

			if( str_Temp.intern( ) == "(".intern( ) )
			{
				str_Save = str_Save.concat( str_Temp );
				flag_Frist = true;
			}
			else if( str_Temp.intern( ) == ";".intern( ) && flag_Frist )
			{
				str_Save = str_Save.concat( str_Temp );
				count = count + 1;
			}
			else if( str_Temp.intern( ) == ")".intern( ) && flag_Frist && count == 2 )
			{
				str_Save = str_Save.concat( str_Temp );

				flag_Frist = false;
				count = 0;

				System.out.println( "Deal Enter: " + str_Save );

				// str_Save Deal	
				str_Save = dealEnterBlank( str_Save );		
				
				str_Fin = str_Fin.concat( str_Save );
				str_Save = "";
			}
			else if( str_Temp.intern( ) == ")".intern( ) && flag_Frist && count_Parentheses == 0 )
			{
				str_Save = str_Save.concat( str_Temp );

				flag_Frist = false;
				count = 0;

				System.out.println( "Shouldn't deal Enter: " + str_Save );
				
				// nothing
				
				str_Fin = str_Fin.concat( str_Save );
				str_Save = "";
			}
			else if( flag_Frist )
			{
				str_Save = str_Save.concat( str_Temp );
			}
			else if( !flag_Frist )
			{
				str_Fin = str_Fin.concat( str_Temp );
			}
			
		}
		return str_Fin;
	}

	public String dealEnterBlank( String str_Input )
	{
		String str_Fin = "";
		String str_Temp = "";
		String str_Save = "";
		int count_Parentheses = 0;				// count parentheses Number
		boolean flag = false;
		
		for( int i = 0; i < str_Input.length( ); i++ )
		{
			str_Temp = str_Input.substring( i, i + 1 );
			
			if( str_Temp.intern( ) == "(".intern( ) )
			{
				count_Parentheses++;
			}
			else if( str_Temp.intern( ) == ")".intern( ) )
			{
				count_Parentheses--;
			}

			if( str_Temp.intern( ) == ";".intern( ) && !flag )
			{
				flag = true;
				str_Save = str_Save.concat( str_Temp );
				str_Save = str_Save.concat( " " );
			}
			else if( str_Temp.intern( ) == ";".intern( ) && flag )
			{
				str_Save = str_Save.concat( "; " );
				str_Fin = str_Fin.concat( str_Save );
				str_Save = "";
			}
			else if( str_Temp.intern( ) != "\n".intern( ) && str_Temp.intern( ) != "\t".intern( ) && str_Temp.intern( ) != " ".intern( ) && flag && str_Temp.intern( ) != ")".intern( ) )
			{
				str_Save = str_Save.concat( str_Temp );
			}
			else if( str_Temp.intern( ) == ")".intern( ) )
			{
				str_Save = str_Save.concat( " )" );
				str_Fin = str_Fin.concat( str_Save );
				// System.out.println( "Count" + " str_Save: " + str_Save + "\n\n" );
				str_Save = "";
			} 
			else if( !flag )
			{
				str_Fin = str_Fin.concat( str_Temp );
			}

			
		}
		return str_Fin;
	}


			/*

			*/
			/*
			else if( ( str_Temp.intern( ) != "\n".intern( ) && str_Temp.intern( ) != "\t".intern( ) && str_Temp.intern( ) != " ".intern( ) ) && flag )
			{
				
			}
			*/
}

可以把他编做.bat文件
中间写这写就可以运行了
javac GetRadioButton.java
javac TestString.java
javac String_For.java
javac J_JFrame_Button.java
java J_JFrame_Button
pause

运行结果
运行结果
在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值