Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 5 of 5

Thread: help with my machine project.

  1. #1
    Junior Member Irvine's Avatar
    Join Date
    Aug 2009
    Posts
    3
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default help with my machine project.

    hi, i'm a freshman in the degree course of BS Information Systems and i'm seeking help in completing my machine project in java programming. Can someone help me with my codes? I've gotten the gooey running...just the actionlistener i think won't listen. T_T


  2. #2
    Senile Half-Wit Freaky Chris's Avatar
    Join Date
    Mar 2009
    Posts
    834
    My Mood
    Cynical
    Thanks
    7
    Thanked 105 Times in 90 Posts

    Default Re: help with my machine project.

    Well give us some code so we can see what we are working with

    Chris

  3. #3
    Junior Member Irvine's Avatar
    Join Date
    Aug 2009
    Posts
    3
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: help with my machine project.

    here's what i've done

    import javax.swing.JFrame;
    import javax.swing.JButton;
    import javax.swing.JLabel;
    import java.awt.event.ActionListener;
    import javax.swing.JTextField;
    import java.awt.event.ActionEvent;
    import java.awt.TextArea;
    import java.io.Console;
    import facebookchat.common.FacebookChat;
    import facebookchat.common.FacebookUser;
    import facebookchat.common.FacebookMessage;
    import javax.swing.JPasswordField;
     
    public class GUI extends JFrame implements ActionListener
    {
     
     
    	FacebookChat a = new FacebookChat();
     
    	JButton log, send, logout, getbuddy, getmessage;
    	JLabel name, pass, buddy, history, id, message;
    	JPasswordField password;
    	JTextField text, userid, success;
    	TextArea yourmessage, onbuddy, messagehistory;
     
    	public GUI()
     
    	{
    	setTitle("Facebook Chat");
            setSize(600,750);
            setLocation(200,300);
    	setDefaultCloseOperation(EXIT_ON_CLOSE);
            setVisible(true);
            setLayout(null);
     
    	JLabel name = new JLabel("Username:");
    	name.setSize(100,20);
    	name.setLocation(2,2);
    	add(name);
    	setVisible(true);
     
    	JLabel pass = new JLabel("Password:");
    	pass.setSize(100,20);
    	pass.setLocation(2,45);
    	add(pass);
    	setVisible(true);
     
    	log = new JButton("Log In");
    	log.setSize(100,20);
    	log.setLocation(254,22);
    	add(log);
    	setVisible(true);
    	log.addActionListener(this);
     
    	logout = new JButton("Log Out");
    	logout.setSize(100,20);
    	logout.setLocation(356,22);
    	add(logout);
    	setVisible(true);
    	logout.addActionListener(this);
     
    	success = new JTextField();
    	success.setSize(100,20);
    	success.setLocation(460,22);
    	add(success);
    	setVisible(true);
     
    	JTextField text= new JTextField();
    	text.setSize(150,20);
    	text.setLocation(104,2);
    	add(text);
    	setVisible(true);
     
    	JPasswordField password = new JPasswordField();
    	password.setSize(150,20);
    	password.setLocation(104,45);
    	add(password);
    	setVisible(true);
     
    	getbuddy = new JButton("Get Buddies");
    	getbuddy.setSize(150,20);
    	getbuddy.setLocation(2,100);
    	add(getbuddy);
    	setVisible(true);
    	getbuddy.addActionListener(this);
     
    	JLabel buddy = new JLabel("Online Buddy List:");
    	buddy.setSize(200,20);
    	buddy.setLocation(2,125);
    	add(buddy);
    	setVisible(true);
     
     
    	JLabel id = new JLabel("Send message to ID:");
    	id.setSize(120,20);
    	id.setLocation(2,405);
    	add(id);
    	setVisible(true);
     
    	JTextField userid = new JTextField();
    	userid.setSize(150,20);
    	userid.setLocation(122,405);
    	add(userid);
    	setVisible(true);
     
    	TextArea onbuddy = new TextArea();
    	onbuddy.setSize(280,250);
    	onbuddy.setLocation(2,150);
    	add(onbuddy);
    	setVisible(true);
     
    	TextArea yourmessage = new TextArea();
    	yourmessage.setSize(280,220);
    	yourmessage.setLocation(2,450);
    	add(yourmessage);
    	setVisible(true);
     
    	send = new JButton("Send");
    	send.setSize(75,20);
    	send.setLocation(50,675);
    	add(send);
    	setVisible(true);
    	send.addActionListener(this);
     
    	JLabel history = new JLabel("Message history:");
    	history.setSize(150,20);
    	history.setLocation(300, 125);
    	add(history);
    	setVisible(true);
     
    	TextArea messagehistory = new TextArea();
    	messagehistory.setSize(260,210);
    	messagehistory.setLocation(300,150);
    	add(messagehistory);
    	setVisible(true);
     
    	JLabel sentmessages = new JLabel("Your sent messages:");
    	sentmessages.setSize(150,20);
    	sentmessages.setLocation(300,370);
    	add(sentmessages);
    	setVisible(true);
     
    	TextArea yoursent = new TextArea();
    	yoursent.setSize(260,210);
    	yoursent.setLocation(300,400);
    	add(yoursent);
    	setVisible(true);
     
     
    	getmessage = new JButton("Get Message");
    	getmessage.setSize(150,20);
    	getmessage.setLocation(300, 675);
    	add(getmessage);
    	setVisible(true);
    	getmessage.addActionListener(this);
     
    	}
     
    	public void actionPerformed(ActionEvent e)
    	{
    		if(e.getSource()==log)
    		{
    			String value = text.getText();
                		String value2 = password.getText();
                		boolean login = a.login(value,value2);
    			if(login)
    				success.setText("Logged In");
    					else
    						success.setText("Failed");
     
    		}
     
    		if (e.getSource() == logout)
       		{
       			a.logout();
       			success.setText("Logout Successful!");
       			name.setText(" ");
    			userid.setText(" ");
       			password.setText(" ");
       			onbuddy.setText(" ");
       			messagehistory.setText(" ");
       			yourmessage.setText(" ");
    		}
     
    		if(e.getSource()==getbuddy)
    		{
     
    		a.refreshBuddyList();
    		boolean buddy = a.hasNextBuddy();
    		if(buddy)
    		while(buddy==true)
    			{
    				FacebookUser b = a.getNextBuddy();
    				String c = b.getName();
    				String d = b.getUid();
    				onbuddy.append(c+ "-" +d);
    			}
    			else 
    			onbuddy.setText("No Online Buddies.");
    		}
     
    		if(e.getSource()==send)
    		{
    			String aa = yourmessage.getText();
    			String bb = id.getText();
    			a.postMessage(bb,aa);
    			yourmessage.setText(bb+":"+aa);
    		}
     
    		if(e.getSource()==getmessage)
    		{
    			boolean message = a.hasNewMessage();
    			if(message)
    			while(message==true)
    			{
    				FacebookMessage x = a.getNextMessage();
    				String x2 = x.getFromName();
    				String x3 = x.getText();
    				messagehistory.setText(x2+ ":" + x3);
    			}
     
    			else
    			messagehistory.setText("No new messages.");
    		}
     
     
     
     
     
    	}
     
    }
    Last edited by Freaky Chris; September 1st, 2009 at 03:32 AM.

  4. #4
    Super Moderator helloworld922's Avatar
    Join Date
    Jun 2009
    Posts
    2,896
    Thanks
    23
    Thanked 619 Times in 561 Posts
    Blog Entries
    18

    Default Re: help with my machine project.

    What you're doing is adding the frame to be actionListened... You need to add all the buttons/text fields to be listened to, not the main frame (though that is useful sometimes).

    this.addActionListener(listeningTo)

    this object listens to listeningTo

  5. The Following User Says Thank You to helloworld922 For This Useful Post:

    Irvine (September 1st, 2009)

  6. #5
    Junior Member Irvine's Avatar
    Join Date
    Aug 2009
    Posts
    3
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: help with my machine project.

    thank you!! ^_^

Similar Threads

  1. Java error "could not create java virtual machine"
    By aubrey4444 in forum Java Theory & Questions
    Replies: 17
    Last Post: October 3rd, 2010, 12:51 PM
  2. Moving MySql Database from one machine to another machine
    By vaishali in forum JDBC & Databases
    Replies: 5
    Last Post: July 21st, 2010, 01:21 AM
  3. need help with Vending Machine code...
    By mia_tech in forum Loops & Control Statements
    Replies: 3
    Last Post: April 20th, 2009, 05:24 AM
  4. Replies: 8
    Last Post: February 24th, 2009, 04:04 PM
  5. Replies: 6
    Last Post: November 14th, 2008, 03:09 PM