Jump to content


Check out our Community Blogs

Register and join over 40,000 other developers!


Recent Status Updates

View All Updates

Photo
- - - - -

Hello World - GUI

java hello world

  • Please log in to reply
12 replies to this topic

#1 Khaotic

Khaotic

    CC Resident

  • Just Joined
  • PipPipPipPip
  • 62 posts

Posted 19 June 2010 - 09:57 PM

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.

  • 0
Check out my site: www.khaoticirc.net

#2 Lions

Lions

    CC Lurker

  • Just Joined
  • Pip
  • 6 posts

Posted 13 July 2010 - 07:54 AM

Thanks for this, helped me out! :)
  • 0

#3 isuru

isuru

    CC Addict

  • Advanced Member
  • PipPipPipPipPip
  • 249 posts

Posted 25 July 2010 - 12:33 PM

Thanks! Keep Posting!
  • 0

#4 fyhring4

fyhring4

    CC Newcomer

  • Just Joined
  • PipPip
  • 12 posts

Posted 24 October 2010 - 02:26 AM

Thx vervy nice :D
  • 0

#5 femi

femi

    CC Lurker

  • Just Joined
  • Pip
  • 4 posts

Posted 03 December 2010 - 06:02 PM

Nice one. what if i want to write A GUI password programme?
  • 0

#6 Alexander

Alexander

    YOL9

  • Moderator
  • 3963 posts
  • Location:Vancouver, Eh! Cleverness: 200
  • Programming Language:C, C++, PHP, Assembly

Posted 03 December 2010 - 06:26 PM

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
  • 0

All new problems require investigation, and so if errors are problems, try to learn as much as you can and report back.


#7 femi

femi

    CC Lurker

  • Just Joined
  • Pip
  • 4 posts

Posted 03 December 2010 - 06:32 PM

Thank you

Hi Nullw0rm but the code is not running on BlueJ

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

  • 0

#8 Alexander

Alexander

    YOL9

  • Moderator
  • 3963 posts
  • Location:Vancouver, Eh! Cleverness: 200
  • Programming Language:C, C++, PHP, Assembly

Posted 03 December 2010 - 06:41 PM

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!
  • 0

All new problems require investigation, and so if errors are problems, try to learn as much as you can and report back.


#9 femi

femi

    CC Lurker

  • Just Joined
  • Pip
  • 4 posts

Posted 03 December 2010 - 07:17 PM

okay . thank you
  • 0

#10 idrivebears

idrivebears

    CC Lurker

  • New Member
  • Pip
  • 5 posts

Posted 23 October 2011 - 06:55 PM

You dont need these imports:

import java.awt.*;
import java.awt.event.*;


The code can run on Swing by itself.
  • 0

#11 try

try

    CC Newcomer

  • Just Joined
  • PipPip
  • 11 posts

Posted 24 October 2011 - 04:59 PM

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

  • 0

#12 Gman

Gman

    CC Resident

  • Advanced Member
  • PipPipPipPip
  • 97 posts
  • Location:Donegal, Ireland
  • Learning:Java, C#, PHP, (Visual) Basic, JavaScript, Assembly, Others

Posted 28 October 2011 - 12:21 PM

very nice :) thanks
  • 0





Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download