• Log in or sign up for an account here: https://www.sythe.org/login

Creating a Java GUI Project using Netbeans

db0winsanity

Active Member
Joined
Dec 28, 2008
Sythe Gold
0
Messages
109
Location
Wisconsin
Creating a Project in Netbeans
netbeans.png

*note this, unlike my eclipse for android tutorial does not need to be set up, its ready to go from download, download from their website*

Difficulty: 1/10

Part I: Creating a new Project
  • go to File > New Project
  • select Java in Categories
  • select Java Application in Projects
  • click Next
netbeansnewproject.png


  • name your project My First GUI
  • deselect Create Main Class

myfirstgui.png

  • now click Finish
  • right click My First GUI > New > JFrame Form
  • set both class name and package to GUI
rightclickn.png

  • now click Finish
  • switch to your Design tab
clickdesign.png

  • now, using your Swing controls (at right), drag 3 Text Field's and one Button to the pallet
swingcontrols.png

(your Swing Controlls)
  • now set up your Text Fields and Button as such
  • remove all extra room by dragging in the corner of the GUI at bottom right
layoutm.png

  • now change what everything says by right clicking on them, one at a time and selecting "Edit Text"
  • for the Text Fields, delete all the text, for the Button, set the text as solve
  • to make them all the same size, to make it look decent Ctrl click all 4 items, then go to Same Size > Same Width
guie.png

  • now the making it work part, but first, lets name the window, at the bottom left of your screen, you'll see something that says [JFrame], click on this, and in the property editor, Change title to Simple Calculator
  • now, before we make it work, lets just look at the GUI, click the outlined button:
outlinedbutton.png

now we see what it looks like!
gui2.png

  • now, lets make this work, close the window that popped up now
  • double click the button
  • you're now in source mode! (remember the button that we switched to design? now we switched to source, but remember to double click the button, dont just change it because that sets up an onClick listener that we're going to add code to)
  • now find:
Code:
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
 // TODO add your handling code here:
    }
  • and make it:
Code:
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
        double a = Double.valueOf(jTextField1.getText());
        double b = Double.valueOf(jTextField2.getText());
        double answer = a+b;
        jTextField3.setText(""+answer);
        
    }
  • now, lets go back to the Design tab, and make a few quick changes
  • remember how to set text? well lets set the texts to make it look like this:
changeto.png

  • now, after all of that work, lets run this thing!
  • go to Run > Run main Project
  • Select OK, (or whatever the button is, sorry closed to early, can someone verify button name?)
  • and there you go! your first java program + GUI!
finishedo.png


and there you go! keep a look out for more tutorials made by me!, they're going to keep coming :)
 
This reminds me of V.B. Anyways, nice guide & well written, that program looks nice but I just don't know what I could use it for. =P
 
Runescape Gamblingrunescape gambling
Back
Top