Creating a Java GUI Project using Netbeans

Discussion in 'Archives' started by db0winsanity, Aug 5, 2010.

Creating a Java GUI Project using Netbeans
  1. Unread #1 - Aug 5, 2010 at 5:04 AM
  2. db0winsanity
    Joined:
    Dec 28, 2008
    Posts:
    109
    Referrals:
    0
    Sythe Gold:
    0

    db0winsanity Active Member

    Creating a Java GUI Project using Netbeans

    Creating a Project in Netbeans
    [​IMG]
    *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
    [​IMG]

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

    [​IMG]
    • now click Finish
    • right click My First GUI > New > JFrame Form
    • set both class name and package to GUI
    [​IMG]
    • now click Finish
    • switch to your Design tab
    [​IMG]
    • now, using your Swing controls (at right), drag 3 Text Field's and one Button to the pallet
    [​IMG]
    (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
    [​IMG]
    • 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
    [​IMG]
    • 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:
    [​IMG]
    now we see what it looks like!
    [​IMG]
    • 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:
    [​IMG]
    • 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!
    [​IMG]

    and there you go! keep a look out for more tutorials made by me!, they're going to keep coming :)
     
  3. Unread #2 - Oct 29, 2010 at 11:33 AM
  4. xron89
    Joined:
    Jan 9, 2009
    Posts:
    193
    Referrals:
    0
    Sythe Gold:
    0

    xron89 Active Member
    Banned

    Creating a Java GUI Project using Netbeans

    eek

    i got an error

    no main classes found :(

    any help on where i went wrong
     
  5. Unread #3 - Dec 21, 2010 at 11:49 AM
  6. iLikePaper
    Joined:
    Jan 22, 2010
    Posts:
    702
    Referrals:
    0
    Sythe Gold:
    0

    iLikePaper I heard you liek "paper"?
    Do Not Trade

    Creating a Java GUI Project using Netbeans

    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
     
< Vote Wildy/Free Trade [CONFIRMED] NOT FAKE | JaGeX Are Bringing Back OLD TRADE & PVP WITH >

Users viewing this thread
1 guest


 
 
Adblock breaks this site