[英]How should I display my code inside of my Java program?
I apologize if this question is too "general"; 如果这个问题太“笼统”,我深表歉意。 But my question is very specific to what I am programming and I was not able to find a descent answer anywhere else.
但是我的问题非常针对我在编程的内容,在其他任何地方都找不到下降的答案。
I am creating a "Proof of Concept" program for extra credit in my calc class. 我正在为自己的calc类创建一个“概念验证”程序,以增加学分。 Now that the program is finished, I want to make a way to view the coding of the program to show the teacher and explain what I did.
既然程序已经完成,我想找到一种查看程序编码的方法,以向老师展示并解释我的工作。
My first thought was to use a JTextPane, but how would that work? 我的第一个想法是使用JTextPane,但是它将如何工作? I want to find some way to display all the lines of coding, keeping the structure of coding that Java/Eclipse uses.
我想找到一种显示所有编码行的方法,以保持Java / Eclipse使用的编码结构。
What is the best way to do this? 做这个的最好方式是什么?
Thanks, 谢谢,
-Steven -史蒂文
use system.out.println and get a free account at https://github.com/ and upload your code and the output of your programs . 使用system.out.println并在https://github.com/上获得一个免费帐户,然后上载代码和程序输出。 Send the link to your professor ..I think he will be impressed not only by your work but also by how you are presenting your code to him/her to review it.
将链接发送给您的教授..我认为他不仅会给您留下深刻的印象,而且会给您将代码呈现给他/她的方式留下深刻的印象。
good luck, I am already impressed that you are searching online to best present your work for that you deserve an A+ too. 祝您好运,您已经在网上搜索以最好地展示您的作品,这也给我留下了深刻的印象,因为您也应该获得A +。 keep up the good work.
保持良好的工作。
If I was your teacher, I'd prefer to be shown your code within an IDE (such as Eclipse). 如果我是您的老师,则希望在IDE(例如Eclipse)中向您显示代码。 Then I could browse around as I pleased and see it execute in front of me.
然后我可以随意浏览并看到它在我眼前执行。
IDEs are built for looking at code :-) IDE是为查看代码而构建的:-)
I am preferring you to use your IDE , but anyway : Maybe i am wrong but I think the only way is to get the codes from the (.java) file and copy it to TextArea but it's not perfect like your IDE. 我希望您使用自己的IDE,但是无论如何:也许我错了,但是我认为唯一的方法是从(.java)文件中获取代码并将其复制到TextArea,但它并不像您的IDE那样完美。 I will not post the whole program just the function hope it will be useful for you
我不会发布整个程序,只是希望它对您有用的功能
Scanner sc = null;
try{
sc=new Scanner(new File("yourProgram.java"));
}catch(Exception ex){System.out.println(ex.getMessage());}
String line = "";
while (sc.hasNextLine()){
jTextArea1.append(line=sc.nextLine()+"\n");
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.