⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 javacodegenerator.java

📁 基于eclipse的工具开发代码
💻 JAVA
字号:
package com.cownew.uidesigner.builder;

import java.util.*;
import com.cownew.uidesigner.model.*;

public class JavaCodeGenerator
{
  protected static String nl;
  public static synchronized JavaCodeGenerator create(String lineSeparator)
  {
    nl = lineSeparator;
    JavaCodeGenerator result = new JavaCodeGenerator();
    nl = null;
    return result;
  }

  protected final String NL = nl == null ? (System.getProperties().getProperty("line.separator")) : nl;
  protected final String TEXT_1 = "  ";
  protected final String TEXT_2 = NL + "package ";
  protected final String TEXT_3 = ";" + NL + "" + NL + "import javax.swing.*;" + NL + "import java.awt.*;" + NL + "" + NL + "public class ";
  protected final String TEXT_4 = " extends JFrame" + NL + "{" + NL + "" + NL + "\tprivate static final long serialVersionUID = 1L;" + NL + "" + NL + "\tprivate JPanel jContentPane = null;" + NL + "" + NL + "\tpublic static void main(String[] args)" + NL + "\t{" + NL + "\t\t";
  protected final String TEXT_5 = " frame = new ";
  protected final String TEXT_6 = "();" + NL + "\t\tframe.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);" + NL + "\t\tframe.setVisible(true);" + NL + "\t}" + NL + "" + NL + "\tpublic ";
  protected final String TEXT_7 = "()" + NL + "\t{" + NL + "\t\tsuper();" + NL + "\t\tinitialize();" + NL + "\t}" + NL + "" + NL + "\tprivate void initialize()" + NL + "\t{" + NL + "\t\tthis.setSize(800, 600);" + NL + "\t\tthis.setContentPane(getJContentPane());" + NL + "\t\tthis.setTitle(\"JFrame\");" + NL + "\t}" + NL + "" + NL + "\tprivate JPanel getJContentPane()" + NL + "\t{" + NL + "\t\tif (jContentPane != null)" + NL + "\t\t{" + NL + "\t\t\treturn jContentPane;" + NL + "\t\t}" + NL + "\t\tjContentPane = new JPanel();" + NL + "\t\tjContentPane.setLayout(null);";
  protected final String TEXT_8 = NL + "\t\t";
  protected final String TEXT_9 = NL + "\t\t\t";
  protected final String TEXT_10 = NL + "\t\t" + NL + "\t\treturn jContentPane;" + NL + "\t}" + NL + "" + NL + "}";
  protected final String TEXT_11 = NL;

  public String generate(Object argument)
  {
    final StringBuffer stringBuffer = new StringBuffer();
    stringBuffer.append(TEXT_1);
    
	ArgInfo argInfo = (ArgInfo)argument;
	Form form = argInfo.getForm();
	String className = argInfo.getClassName();
	String packageName = argInfo.getPackageName();	

    stringBuffer.append(TEXT_2);
    stringBuffer.append(packageName);
    stringBuffer.append(TEXT_3);
    stringBuffer.append(className);
    stringBuffer.append(TEXT_4);
    stringBuffer.append(className);
    stringBuffer.append(TEXT_5);
    stringBuffer.append(className);
    stringBuffer.append(TEXT_6);
    stringBuffer.append(className);
    stringBuffer.append(TEXT_7);
    		
		List<Component> components = form.getComponents();
		for(Component component:components)
		{
			List<String> srcList = component.generateCode("jContentPane");
			for(String src:srcList)	
			{

    stringBuffer.append(TEXT_8);
    stringBuffer.append(src);
    stringBuffer.append(TEXT_9);
    			
			}	
		}

    stringBuffer.append(TEXT_10);
    stringBuffer.append(TEXT_11);
    return stringBuffer.toString();
  }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -