- Right-click on the project
- Select properties
- Java build path
- Library > Add Library > Add JRE SYSTEM Library
- Execution Environment
- Select JavaSE-1.7
- Finish
摘要
本文,首先复习 新建 Java 工程;然后,给出 system.out.println 代码示例,浅析方法的输入变量;最后,通过复写 JFrame 的方法以及 system.err.println 代码示例,进一步加深对 system.out.println 的学习。
1)在 Project Explorer --> 右键 --> New --> 新建 Java Project --> Name --> My_Proj;
2)右键Src --> New Package --> My_Pack;
3)右键My_Pack --> New Class --> My_Class --> 并勾取 public static void main(String[] args) 选项;
4) 【system.out.println 代码示例】
package My_Pack; import javax.swing.JFrame; public class My_Class { /** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub System.out.println("Hello World !"); System.out.println(true); System.out.println(1234); System.out.println(new JFrame()); } }
Access restriction: The type JFrame is not accessible due to restriction on required library C:\ProgramFiles\Java\jre8\lib\rt.jar
爬 Stack Over Flow 得到解释和解决方案,如下:
When you make a new java project at JRE choose "Use an execution environment JRE and from there select JavaSE-1.7 or 1.8 and just should solve the problem.
Steps are as follow :
这里说明,system.out.println 可以输出,字符串、数字、布尔 以及 JFrame 默认转换为 2String 的形式 。
代码输出如下:
Hello World !
true
1234
javax.swing.JFrame[frame0,0,0,0x0,invalid,hidden,layout=java.awt.BorderLayout,title=,resizable,normal,defaultCloseOperation=HIDE_ON_CLOSE,rootPane=javax.swing.JRootPane[,0,0,0x0,invalid,layout=javax.swing.JRootPane$RootLayout,alignmentX=0.0,alignmentY=0.0,border=,flags=16777673,maximumSize=,minimumSize=,preferredSize=],rootPaneCheckingEnabled=true]
另,这里还可以对 JFrame 方法复写 :
package My_Pack; import javax.swing.JFrame; public class My_Class { /** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub System.out.println("Hello World !"); System.out.println(true); System.out.println(1234); System.out.println(new JFrame() { public String toString() { return "this is my JFrame"; } }); } }此时输出为 :
Hello World !
true
1234
this is my JFrame
注:
system.out.println 与 system.err.println 输入变量类似,不过输出显示为红色字体。