Jump to content

Hello World - GUI

- - - - -

  • Please log in to reply
12 replies to this topic

#1
Khaotic

Khaotic

    Learning Programmer

  • Members
  • PipPipPip
  • 62 posts
Well just so I get back into the groove of making tutorials, I am going to make a quick Hello World graphical user interface window. I'm not with my compiler right now and it has been a few weeks since I have worked on a GUI (currently working on an IRCd made in java with services written in tcl{i know lol}

Alright here we go.

import javax.swing.*; 

import java.awt.*; 

import java.awt.event.*; 

public class helloWorld extends JFrame {
    helloWorld(String title) { 
        this.setSize(500,500); 
        setTitle(title); 
    }

    public static void main(String[] args) {
       helloWorld window = new helloWorld("Hello CodeCall");
       window.setVisible(true);
       window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 
    }
}
Basically this opens a 500x500 window titled "Hello CodeCall"

Please remember I did this without my compiler(yes, I know this is simple, but also consider I havent done a GUI in a matter of weeks, if not months)

Edited by Khaotic, 13 July 2010 - 11:55 AM.

Check out my site: www.khaoticirc.net

#2
Lions

Lions

    Newbie

  • Members
  • Pip
  • 6 posts
Thanks for this, helped me out! :)

#3
isuru

isuru

    Programming Professional

  • Members
  • PipPipPipPipPip
  • 233 posts
Thanks! Keep Posting!

#4
fyhring4

fyhring4

    Newbie

  • Members
  • PipPip
  • 13 posts
Thx vervy nice :D

#5
femi

femi

    Newbie

  • Members
  • Pip
  • 4 posts
Nice one. what if i want to write A GUI password programme?

#6
Alexander

Alexander

    It's Science!

  • Moderators
  • 4,118 posts
  • Location:Vancouver, Eh! Cleverness: 200

femi said:

Nice one. what if i want to write A GUI password programme?
Java has an awesome tutorial to mask input and things: Password Masking in the Java Programming Language
Be sure to read the updated FAQ! || Health is achieved through the same 10,000 steps.
If a suggested code/method fails, informing us is less important than telling us why or what errors occurred.

#7
femi

femi

    Newbie

  • Members
  • Pip
  • 4 posts
Thank you

Hi Nullw0rm but the code is not running on BlueJ

Edited by Alexander, 03 December 2010 - 06:41 PM.
Merged three posts


#8
Alexander

Alexander

    It's Science!

  • Moderators
  • 4,118 posts
  • Location:Vancouver, Eh! Cleverness: 200
It uses AWT/Swing, so you may need to edit it a bit to get it to work. There are other password input tutorials on the web too if you search which are quite nice. Try not to create so many posts in one place!
Be sure to read the updated FAQ! || Health is achieved through the same 10,000 steps.
If a suggested code/method fails, informing us is less important than telling us why or what errors occurred.

#9
femi

femi

    Newbie

  • Members
  • Pip
  • 4 posts
okay . thank you

#10
Walizzay

Walizzay

    Newbie

  • Members
  • Pip
  • 5 posts
You dont need these imports:

Quote

import java.awt.*;

import java.awt.event.*;

The code can run on Swing by itself.

#11
try

try

    Newbie

  • Members
  • PipPip
  • 11 posts
hello.. well, on the same topic.. u can build this hello world using IDE (i choose Netbeans)

how ? ok, simple..
1-just made new project
2- add JButton on the JPanel
3 - right click on JButton that we add before > choose "event" > "ActionPerformed"
4 - add this code above the TODO (as IDE will generate it default to made u code it faster)
String msg = "Hello dunia!";

    JOptionPane.showMessageDialog(null,msg);

    System.out.println(msg)
5 - now try execute by compiling it!

example :
Posted Image
[ATTACH=CONFIG]4272[/ATTACH]
* I from Malaysia, thus text in picture are in Malay language

ok, look at the picture..thus code will popup a msg hello world!
hope u like it.. thanks.

Edited by try, 24 October 2011 - 05:01 PM.
adding a picture


#12
Gman

Gman

    Learning Programmer

  • Members
  • PipPipPip
  • 49 posts
very nice :) thanks




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users