Welcome Guest ( Log In | Register)



 
Reply to this topicStart new topic
> Making a java based program
onyxgem
post Jun 26 2007, 03:42 AM
Post #1


Newbie
*

Group: Members
Posts: 7
Joined: 26-June 07
Member No.: 45,460



Java GUI

Making a Little Java Program

Sec. 1: Imports and starting it off
Sec. 2: Variables
Sec. 3: Frame and Stuff
Sec. 4: Declaring buttons
Sec. 5: Adding buttons
Sec. 6: Action Listening
Sec. 7: Using this for a learning experience

Section 1

Now, let's think. What imports do we need? We obviously need GUI imports. We also need the action Listener. So,
let's declare this at the very top:

Code:
CODE
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
That's all we need to get all our supplies. Now to start us off.
Skip a couple lines and add:

Code:
CODE
public class Tutorial extends JFrame implements ActionListener
      {
Section 2

Let's declare our variables.
Right below the class, add

Code:
CODE
private static Tutorial frame;
       private static JTextField text;
I will tell you about this later.

Section 3

This is in all java programs. To start it and load everything, you must add:

Code:
CODE
public static main(String[] args)
{
We must now add the frame, so skip a 2 lines and add:

Code:
CODE
frame = new Tutorial();
          frame.setTitle("Tutorial of GUI");
          frame.setSize(400, 100);
          frame.setDefaultCloseOperation(EXIT_ON_CLOSE);
          frame.setVisible(true);
Ending the statement, add one last "}"

Section 4

Now add:

Code:
CODE
public Tutorial()
    {Next add:


Code:
CODE
setLayout(new BorderLayout());

              JTextField text = new JTextField(10);
              JButton button = new JButton("JButton1");
              JButton button1 = new JButton("JButton2");
              JButton button2 = new JButton("JButton3");
              JButton button3 = new JButton("JButton4");


              JPanel panel = new JPanel();
That adds the button vars.

Section 5

Let's add the buttons now. Add right below that, add:

Code:
CODE
panel.setLayout(new FlowLayout());


              panel.add(button);
              panel.add(button1);
              panel.add(button2);
              panel.add(button3);



       add(panel, BorderLayout.NORTH);
          button.addActionListener(this);
           button1.addActionListener(this);
            button2.addActionListener(this);
             button3.addActionListener(this);
         }
That adds the buttons on.

Section 6

Let's make the outcome of clicking the button. Add:

Code:
CODE
public void actionPerformed(ActionEvent e)
          {

           JOptionPane.showMessageDialog(frame, " was selected." );


          }
     }That tells you what button was selected.


Now save and compile. Now run the program and see what the outcome is.

Section 7

You can view other things like this at:
http://java.sun.com/developer/online.....;/contents.html
This will help you understand all the functions of java GUI.

-Bill for Unkn


note:i copied this from my word and pasted it here hope this helps ya out im sorry if i misspelled anything i type fast cool.gif
Go to the top of the page
 
+Quote Post
galexcd
post Jun 27 2007, 04:55 PM
Post #2


Define:EVIL PROGRAMMER (ē'vəl prō'grăm'ər)- n. An organism that converts caffeine into evil software.
*********

Group: [HOSTED]
Posts: 975
Joined: 25-September 05
From: The dungeon deep below the foundation of trap17
Member No.: 12,251



Great tutorial! I still hate java though. I remember learning gui in java about four years ago, and it was hell for me. This probably would have made it a bit easier but I much prefer c++ to java when making gui applications. Anyway great tut! Keep up the good work!
Go to the top of the page
 
+Quote Post
zak92
post Jun 29 2007, 06:47 AM
Post #3


Super Member
*********

Group: Members
Posts: 225
Joined: 5-January 07
Member No.: 36,560



These languages confuse me but at the same time fascinate me as some gibberish can turn into such good creation such as a great and a profitable web site. Thanks man love you as I wanted to just learn this.
Go to the top of the page
 
+Quote Post
master_bacarra
post Jun 29 2007, 11:32 AM
Post #4


I'm back... well, sort of.
*********

Group: [HOSTED]
Posts: 697
Joined: 26-December 05
From: somewhere in the middle of nowhere
Member No.: 16,226
Spam Patrol



the reason why i like java more is because i could just use the exception handling for the errors. but i have to admit i'm not a great programmer at all. i never really appreciated c/c++ because of the complicated pointers. programming with pointers was hell for me.

anyways, great tutorial for starters.
Go to the top of the page
 
+Quote Post

Reply to this topicStart new topic

Collapse

> Similar Topics

Topics Topics
  1. Making A Webserver Directory Listing(6)
  2. Making Shadows Without Images(4)
  3. An Introduction To Java And Graphics(5)
  4. Tutorial: Installing D-shoutbox For Ipb V1.2(12)
  5. Making Winrar Archives(12)
  6. Making And Editing A New Ipb V1.2 Skin(0)
  7. Php Navigation(7)
  8. Css Based Photo Gallery Code(3)
  9. How To: Make A Simple Php Site(21)
  10. Creating A Timer Program(8)
  11. Making Interactive Cds With Flash(2)
  12. Building An Address Book With Java(1)
  13. Beginner's Guide To Skiing(4)
  14. Making A Dynamic Page On Blogspot(5)
  15. How To Make A Simple File Based Shoutbox Using Php And Html(8)
  1. Css-based "i-frames" (sort Of)(1)
  2. Making The Popular Id Browsing For Your Site.(17)
  3. Making A One Page Does All Website In Phph(2)
  4. Faux Ajax Loading - Css Only(3)
  5. Creating A Resume(1)
  6. Background Image Swap Script(15)
  7. Making A Song In Fruity Loops Part 2(0)
  8. Making A Song In Fruity Loops Part Three(1)
  9. Ftp In Visual Basic 6.0(0)
  10. Make A Flat Based Shoutbox, With Auto Refresh.(6)
  11. How To Make An Ultimate Game List.(0)
  12. Making Calculators with PHP(4)


 



- Lo-Fi Version Time is now: 27th July 2008 - 01:34 AM