站内搜索: 请输入搜索关键词

当前页面: 开发资料首页Netbeans 专题添加按钮的功能(初学者指南)(2)

添加按钮的功能(初学者指南)(2)

摘要: This tutorial teaches you how to build a simple GUI with back-end functionality. This tutorial is geared to the beginner and introduces the basic construction of a GUI with functionality. A basic understanding of the Java Programming Language is required.

Exercise 2: Building the Front End

After creating the new application, you may have noticed that the Source Packages folder in the Projects window contains an empty <default package> node. To proceed with building our interface, we need to create a Java container within which we will place the other required GUI components. In this step we'll create a container using the JFrame component and place the container in a new package.

Create a JFrame container

  1. In the Projects window, right-click the NumberAddition node and choose New > JFrame Form.
  2. Enter NumberAdditionUI as the Class Name.
  3. Enter my.NumberAddition as the package.
  4. Click Finish.

The IDE creates the NumberAdditionUI form and the NumberAdditionUI class within the NumberAdditionUI.java application, and opens the NumberAdditionUI form in the GUI Builder. Notice that the my.NumberAddition package replaces the default package.

Adding Components: Making of the Front End

Next we are going to populate our application's front end with one JPanel, and three JLabels, JTextFields and JButtons each. The JFrame with the aforementioned components will look like this.


Select Windows > Palette to open the Palette if you don't see it. You use the Palette to drag and drop UI components to the design area.

  1. Start by selecting a JPanel from the Palette and drop it onto the JFrame.
  2. While the JPanel is highlighted, go to the Properties window and click the "..." button next to Border to choose a border style.
  3. In the Border dialog, select Titled Border from the list, and type in Number Addition in the Title field. Click OK to save the changes and exit the dialog.
  4. You should now see an empty titled JFrame that says Number Addition like in the screenshot. Look at the screenshot and add three JLabels, three JTextFields and three JButtons as you see above.

↑返回目录
前一篇: 添加按钮的功能(初学者指南)(2)
后一篇: 添加按钮的功能(初学者指南)(3)