Java代码运行器

欢迎进入Java社区论坛,与200万技术人员互动交流 >>进入

  public void exec(String Content) {

  cmd = Content;

  }

  public String getName(String str) {

  String name = “”;

  if (str.indexOf(“class”) != -1) {

  String[] s = str.split(“\\s+”);

  for (int i = 0; i < s.length; i++) {

  if (s[i].equals(“class”)) {

  if ((i + 1) < s.length)

  name = s[i + 1];

  int a = 0;

  if((a=name.indexOf(“{“))!=-1){

  name= name.substring(0,a);

  }

  }

  }

  }

  return name;

  }

  public void OutputData() {

  try {

  FileOutputStream out = new FileOutputStream(file);

  byte buf[] = textArea_1.getText().getBytes();

  out.write(buf);

  out.flush();

  out.close();

  } catch (Exception e) {

  e.printStackTrace();

  }

  }

  public void InputData() {

  try {

  FileInputStream in = new FileInputStream(file);

  int a = (int)file.length();

  byte buf[] = new byte[a];

  int len = in.read(buf);

  if (len == -1){

  System.out.println(“文件为空”);

  }else{

  textArea_1.setText(new String(buf, 0, len));

  }

  } catch (Exception e) {

  e.printStackTrace();

  }

  }

  /**

  * @param str 内容

  * @param col 颜色

  * @param bold 是否粗体

  * @param fontSize 字体大小

  */

  public void setDocs(String str, Color col, boolean bold, int fontSize) {

  SimpleAttributeSet attrSet = new SimpleAttributeSet();

  StyleConstants.setForeground(attrSet, col);

  // 颜色

  if (bold == true) {

  StyleConstants.setBold(attrSet, true);

  }// 字体类型

  StyleConstants.setFontSize(attrSet, fontSize);

  // 字体大小

  Document doc = textArea_1.getDocument();

  try {

  doc.insertString(doc.getLength(), str, attrSet);

  } catch (BadLocationException e) {

  System.out.println(“BadLocationException: ” + e);

  }

  }

  }

  //未写完的…我想写成Eclipse一样 让Java关键字变色“

[1][2][3][4]

背着背包的路上,看过许多人,听过许多故事,

Java代码运行器

相关文章:

你感兴趣的文章:

标签云: