java类中的finish_【Eclipse】使用指南(13)创建Java类

In the Package Explorer view, select the JUnit project. Click the New Java Package button in the toolbar, or select New > Package from the project's context menu .

在包管理器视图中选择JUnit工程,点击工具栏中的New Java Package 按钮,或右键选择New > Package菜单。

In the Name field, type test as the name for the new package. Then click Finish.

在Name 输入框输入test,点击Finish按钮。

In the Package Explorer view, select the new test package and click the New Java Class button in the toolbar.

选择test包,点击工具栏中的New Java Class 按钮,或右键选择New > Class菜单。

Make sure that JUnit appears in the Source Folder field and that test appears in the Package field. In the Name field, type MyTestCase.

确认Source Folder和Package输入框中的内容,并在Name 输入框中输入MyTestCase。

a3e9c5424c6e40485de3d469a869b20c.png

Click the Browse button next to the Superclass field.

点击Superclass 输入框右边的Browse 按钮。

In the Choose a type field in the Superclass Selection dialog, type Test to narrow the list of available superclasses.

在Choose a type输入框中输入test。

c04c485424025c8701cc080a43fcb4f8.png

Select the TestCase class and click OK.

选择TestCase 类,然后点击OK。

Select the checkbox for Constructors from superclass.

勾选Constructors from superclass复选框。

Click Finish to create the new class.

点击Finish 按钮。

9c017573a457b3df0c6f95031b1ce061.png

The new file is opened in the editor. It contains the new class, the constructor and comments.  You can select options for the creation and configuration of generated comments in the Java > Code Style > Code Templates preference page.

新创建的文件会在编辑器中打开,它包含了新的类、构造器和注释。你可以在Java > Code Style > Code Templates首选页中更改类创建和注释的配置信息。

5068cefe455ab81797542a802da33ad8.png

In the Outline view select the new class MyTestCase. Open the context menu and select Source > Override/Implement Methods....

在Outline视图中选择MyTestCase类,右键选择Source > Override/Implement Methods…菜单。

0894da3cb157eb40ae99906b58cd6c12.png

In the Override Methods dialog, check setUp() and tearDown() and click OK. Two methods are added to the class.

在弹出的对话框中,勾选setUp() 和tearDown()并点击OK。

3114dfe331f2d5e36a9fcc83f8eb48f2.png

Change the body of setUp() tocontainer= new Vector();

把setUp() 方法体改成container= new Vector();

container and Vector are underlined with a problem highlight line as they cannot be resolved. A light bulb appears on the marker bar. Move the mouse over the underlined word Vector. A hover appears that shows the error message and contains quick fixes. Move the mouse into the hover and clickImport 'Vector' (java.util). This adds the missing import declaration.

container 和Vector 因无法被解析而高亮显示,同时,左侧标记栏出现电灯泡记号,把鼠标悬停在Vector 上会出现错误提示以及快速修复建议,选择Import 'Vector' (java.util)。

abf87d83e47e4b86c576854f2c96adcf.png

The blinking cursor should still be on the line that contains the error (if not, set it to the end of the line). PressCtrl+1. This lets the cursor jump to the nearest error location and opens the quick fix proposals. Choose Create field 'container' to add the new field.

闪烁的光标所在行仍然有错,按下Ctrl+1快捷键(并不能跳到container错误处,需手动将光标移动到container上) ,在弹出的快速修复建议中选择Create field 'container' 。

e370e6015105ca114e9fbe2b592d7393.png

In the Outline view, select the class MyTestCase. Open the context menu and select Source > Generate Getters and Setters....

在Outline视图中,选择MyTestCase类右键Source > Generate Getters and Setters…菜单。

21afa4f4bd660ad54775d9df60402027.png

The Generate Getter and Setter dialog suggests that you create the methods getContainer and setContainer. Select both and click OK. A getter and setter method for the field container are added.

弹出对话框建议创建getContainer 和setContainer方法,都勾选然后点击OK按钮。

a24a6b989717fb5715060c69f7d52550.png

Save the file.

保存文件。

The formatting of generated code can be configured in the  Java > Code Style > Formatter preference page. If you use a prefix or suffix for field names (e.g. fContainer), you can specify this in the  Java > Code Style preference page so that generated getters and setters will suggest method names without the prefix or suffix.

自动生成的代码格式可以在Java > Code Style > Formatter 首选页中配置,如果你喜欢为field加上前缀或者后缀,可以在Java > Code Style 首选页中配置,默认生成的getters 和setters 是没有前后缀的。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值