在texarea中使用system.out.print() [英] using system.out.print() in a texarea

查看:94
本文介绍了在texarea中使用system.out.print()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

正在开发一个应用程序以查询表并在JTextarea中将其打印出来,但没有响应,而是标记了一个错误的表达式的非法开始",请提供新的帮助,这是我的代码谢谢

Am developing an application to query the table and print it out in the JTextarea but not responding instead flagging an error 'illegal start of expression' please am new with i need help and this is my code thanks

try{
  //get connection to the database
      Connection myconn=DriverManager.getConnection("jdbc:mysql://localhost:3306/cbt_for_java", "root","");
  //create a statement
      Statement mystmt=myconn.createStatement();
  //execute sql query
      ResultSet myrs = mystmt.executeQuery("select * from  jamb WHERE ID = '1'");
  //process the result set

     // System.out.println(myrs.getString("ID") + "." + myrs.getString("question"));


  }
  catch(Exception exc){
  exc.printStackTrace();
  }

  BorderLayout questionareaLayout = new BorderLayout();
  JPanel questionp = new JPanel();
  JTextArea question=new

//this is where the problem is
JTextArea(System.out.println(myrs.getString("ID") + "." + myrs.getString("question"));,22,111);
  question.setEditable(false);
  questionp.add(question);
  add(questionp);

推荐答案

System.out.println()确实具有返回值,因此您不能使用它来设置值.它所做的就是写入控制台.

System.out.println() does have a return value, thus you cannot use it to set a value. What it does is write to the console.

要在文本字段中设置值,请使用setText(),而不使用System.out.println

To set a value in a textfield use the setText(), without the System.out.println

这篇关于在texarea中使用system.out.print()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆