wood burning stoves 2.0
The moose likes Beginning Java and the fly likes Sorry - Newbie question... Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Sorry - Newbie question..." Watch "Sorry - Newbie question..." New topic

Sorry - Newbie question...

Mark Owens

Joined: Feb 24, 2000
Posts: 26
I am having a hard start here. I am trying to write my first applets and I cannot even get the System.out.println method to work. Since I cannot even print "hello world" this is not very fun. Here is an example below that I typed in out of Roberts/Heller about event handling. I think the event handling would work if I could get the text to print...
It compiles but I can not get any simple strings to print. Maybe they are printing the same color as the background?
All help appreciated. There are tufts of hair on my desk I am so frustrated!
Here is my short program:
import java.applet.Applet;
import java.awt.*;
import java.awt.event.*;
import java.lang.*;

class MyActionListener implements ActionListener
public void actionPerformed(ActionEvent ae)
System.out.println("Action Performed");
public class ListenerTest extends Applet
public void init()
Button btn = new Button("OK");
MyActionListener listener = new MyActionListener();

Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
u cant use system.out.println inside applets. u got to define another method called public void paint(Graphics g) and pass the string "Action performed" through a string. u also got to use drawString(msg,x,y) to print the string msg at (x,y) inside ur appletwindow.
U better check it up in some standard text. Hope this helps.
Thandapani Saravanan
Ranch Hand

Joined: Oct 17, 1999
Posts: 117
I think if you use Netscape (also IE?) it allows you to see Java console which displays the outputs.
Alternatively, you can convert your applet into an application by defining main method in ListenerTest class. Try adding this:

Mark Owens

Joined: Feb 24, 2000
Posts: 26
Thanks for your answers. I have made considerable progress. Inside the java console, my "listener" applet was indeed handling the button press event. I can also print out a line of text in an applet now. It would have been nice if one of these fancy books would summarize the differences between applets and applications. I am reading "thinking in Java" next, perhaps it will make it clear.
I still can not make my applet work yet. I cannot put the Paint() method into the MyActionListener class where the System.outprintln statement was before. I get some errors that do not seem like syntax errors. Can I put the paint method inside another method?
Thanks again,
Theresa Duick

Joined: Feb 16, 2000
Posts: 27
Since paint(){ } is a method, it stands alone & is overridden by whatever commands you put within it's brackets. I have not seen any examples where paint() is used inside another method. That may not be possible.
I agree. Here's the link: http://aspose.com/file-tools
subject: Sorry - Newbie question...
It's not a secret anymore!