Random Stuff Forums
 

Go Back   Random Stuff Forums > RSF Exclusive Content > User Knowledgebase and Help

User Knowledgebase and Help Regular members will post their guides here.

Reply
 
LinkBack Thread Tools Display Modes
  #1  
Old 16-05-2007, 04:13 PM
Bootylove (Offline)
Glitch Team Leader
 
Join Date: Apr 2007
Location: Turn around slowly....
Posts: 1,177
Bootylove is an unknown quantity at this point
Default [TuT] Graphical User Interface & More

Tutorial 8:

Well let me explain what a gui is first gui mean Graphical User Interface. Meaning Buttons, text and other things. Lets get started.

Note: Dont attempt this if you are new to java.

First our imports we will just need the javax.swing import this time.

import javax.swing.*;
This is the set of classes we will need that hold the methods for drawing buttons and what not.

Now lets declare our class name
public class GUI1 {
You dont have to use this im just using it for a quick example.
now lets declare some objects.

public static JFrame frame;
public static JButton button;
You can call these whatever you want just make sure that you declare the frame and button correctly.

Now add a main method like so
public static void main(String[] args) {
Now we need to initialize our Frame and Button like so
frame = new JFrame("Gui");
button = new JButton("Click Me");
now we need to make the frame add the button like so.
frame.add(button);
Now if you closed the method and class now this would compile error free but when you ran it it would not show you the button because we have to tell the frame to show itself and were gonna tell it to pack itself to like so
frame.show();
frame.pack();
There you go thats it for now

Full-Code
import javax.swing.*;
public class GUI {
public static JFrame frame;
public static JButton button;

public static void main(String[] args) {
frame = new JFrame("Gui"); button = new JButton("Click Me"); frame.add(button); frame.show(); frame.pack(); }
}
if theres any errors with this coding please post here.
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -5. The time now is 01:24 AM.

Powered by vBulletin® Version 3.8.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.0
Copyright © 2006 - 2012, Rsforums.org