• Advertisement

Archived

This topic is now archived and is closed to further replies.

Need some java help

This topic is 5069 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I''m just learning java, and I''m on action listeners. I need to make a button that does stuff, but I don''t have a good example available. Does someone know where I can get an example source file that when compiled has a button that will display text when it is pushed? I''m really trying to understand this, but I just can''t.

Share this post


Link to post
Share on other sites
Advertisement
Java''s website is your tutorial friend:

http://java.sun.com/docs/books/tutorial/uiswing/TOC.html#events

http://java.sun.com/docs/books/tutorial/

Share this post


Link to post
Share on other sites
After I put in the action, how do I get it to print some words? When I use the standard println, it just prints it in the dos command, not the application

Share this post


Link to post
Share on other sites
You have to be abit more specific than that, in what component do you wont the text to be displayed? post your code

Share this post


Link to post
Share on other sites
Well, suppose you make a TextField called displayText. Then in your actionPerformed method, do this :


public void actionPerformed (ActionEvent e) {
displayText.append("You pushed the BUTTON! This means WAR!\n");
}

Share this post


Link to post
Share on other sites
Well, really now. This is where Google is your friend. Go to
http://java.sun.com/j2se/1.3/docs/api/overview-summary.html and look at the AWT package, or Swing if you prefer. Bookmark the place, it's very useful.

If you want the TextField to pop up at the touch of your button, you might want to extend the Dialog class. Give it a String argument to the constructor, make it a MouseListener, and discard it when a mouse button is clicked.

[edited by - King of Men on June 8, 2004 9:02:01 PM]

Share this post


Link to post
Share on other sites

  • Advertisement