+ Reply to Thread
Results 1 to 5 of 5

Thread: Simple JString reader...

  1. #1
    Join Date
    May 2008
    Location
    Hell
    Posts
    3,852
    Blog Entries
    4
    Rep Power
    49

    Post Simple JString reader...

    I thought that I could show a thing I worked on this morning. Am pretty new on java and very new too the "java swing" thingy...lol

    So here is what I done;

    First of all we could start of the menu for input data and output...
    Code:
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    public class Jhello extends JFrame implements ActionListener {
    	
    	JTextField answer = new JTextField(25);//The size of inputscreen
    	JLabel welcoming = new JLabel();//The size of the outputscreen
    Now we can start on the function and GUI size of the program...
    Code:
    public Jhello () {
    		setLayout(new FlowLayout());//Declaring it's an active app
    		add(new JLabel("What is your name? ", JLabel.CENTER));//Postion of "questioning"(which is the "What is your name? ")
    		add(answer);//functions - Input
    		add(welcoming);/functions - Output
    		welcoming.setHorizontalAlignment(JLabel.CENTER);//Position of output "answer"
    		answer.addActionListener(this);//This catches your input
    		setSize(350, 100);//Size of the window
    		setVisible(true);//If the text should be visible nor not
    		setDefaultCloseOperation(EXIT_ON_CLOSE);//When you close it
            }
    Now the last part first is to set out the main function of the whole program...
    Code:
    public static void main (String[] arg) {
    		new Jhello();
    	}
    And the last thing our method!(This is the important part, without this the program won't have a meaning...(I guess)
    Code:
    public void actionPerformed(ActionEvent e) {//The catcher
    		String namne = answer.getText();//The one that catch'd it
    		welcoming.setText("Welcome " + namne + "!");//Output
    	}
    }
    So now here is the whole code...
    Code:
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    public class Jhello extends JFrame implements ActionListener {
    	
    	JTextField answer = new JTextField(25);
    	JLabel welcoming = new JLabel();
    	
    	public Jhello () {
    		setLayout(new FlowLayout());
    		add(new JLabel("What is your name? ", JLabel.CENTER));
    		add(answer);
    		add(welcoming);
    		welcoming.setHorizontalAlignment(JLabel.CENTER);
    		answer.addActionListener(this);
    		setSize(350, 100);
    		setVisible(true);
    		setDefaultCloseOperation(EXIT_ON_CLOSE);
    	}
    	public static void main (String[] arg) {
    		new Jhello();
    	}
    	public void actionPerformed(ActionEvent e) {
    		String namne = answer.getText();
    		welcoming.setText("Welcome " + namne + "!");
    	}
    }
    I hope this will be useful for people and am truly sorry if I couldn't explain in a better way. I understand thing on my own way and normally can't explain it
    So thats from me, cheers!

  2. CODECALL Circuit advertisement
    Join Date
    Always
    Location
    Advertising world
    Posts
    Many

     
  3. #2
    Jordan Guest

    Re: Simple JString reader...

    Nice tutorial! +rep

  4. #3
    Join Date
    May 2008
    Location
    Hell
    Posts
    3,852
    Blog Entries
    4
    Rep Power
    49

    Re: Simple JString reader...

    Quote Originally Posted by Jordan View Post
    Nice tutorial! +rep
    Thanks

  5. #4
    isuru's Avatar
    isuru is offline Programming Professional
    Join Date
    May 2010
    Posts
    228
    Rep Power
    8

    Re: Simple JString reader...

    Thanks! Added +. keep this up!!!

  6. #5
    GMVResources's Avatar
    GMVResources is offline Learning Programmer
    Join Date
    Jun 2010
    Posts
    72
    Rep Power
    0

    Re: Simple JString reader...

    Good job! This helped me a bit, thanks =P

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Simple Ajax RSS Reader
    By Modern Vision in forum AJAX
    Replies: 1
    Last Post: 08-02-2011, 12:16 PM
  2. HTML Reader
    By seph6664 in forum Java Help
    Replies: 0
    Last Post: 11-25-2009, 07:29 PM
  3. usb card reader
    By azizulkhn in forum Visual Basic Programming
    Replies: 5
    Last Post: 11-20-2008, 09:48 AM
  4. HTML Reader
    By xsonny in forum C# Programming
    Replies: 3
    Last Post: 07-13-2007, 05:16 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts