PDA

Click to See Complete Forum and Search --> : Writing text?


Evan
May 15th, 2001, 06:45 PM
Newbie! hehe.
I downloaded JBuilder 4. Then I went and I made a default aplet.
It came up with this Java code.


package untitled1;

import java.awt.*;
import java.awt.event.*;
import java.applet.*;
import javax.swing.*;

/**
* Title: fdvdfs
* Description: df
* Copyright: Copyright (c) 2001
* Company: ds
* @author dsf
* @version 1.0
*/

public class Applet1 extends JApplet {
boolean isStandalone = false;
/**Get a parameter value*/
public String getParameter(String key, String def) {
return isStandalone ? System.getProperty(key, def) :
(getParameter(key) != null ? getParameter(key) : def);
}

/**Construct the applet*/
public Applet1() {
}
/**Initialize the applet*/
public void init() {
try {
jbInit();
}
catch(Exception e) {
e.printStackTrace();
}
}
/**Component initialization*/
private void jbInit() throws Exception {
this.setSize(new Dimension(400,300));
}
/**Start the applet*/
public void start() {
}
/**Stop the applet*/
public void stop() {
}
/**Destroy the applet*/
public void destroy() {
}
/**Get Applet information*/
public String getAppletInfo() {
return "Applet Information";
}
/**Get parameter info*/
public String[][] getParameterInfo() {
return null;
}

//static initializer for setting look & feel
static {
try {
//UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
//UIManager.setLookAndFeel(UIManager.getCrossPlatformLookAndFeelClassName());
}
catch(Exception e) {
}
}
}


So then I decided I wanted to write something on the main screen.
I tried this:


public void start() {
System.out.println("HI there!");
}


That DID NOT WORK!!
Can someone tell me how to write text on it?

moonguy
May 16th, 2001, 05:01 AM
the System.out.println() statement prints a line of string to the standard output ie generally the console .To print a string on the applet u need to use the drawString method of the Graphics class.
u use it like this. In your class add this method:

public void paint(Graphics g)
{
g.drawString("string",xloc,yloc);
}