Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Newbie Java Applet help

Posted on 2011-09-05
3
Medium Priority
?
321 Views
Last Modified: 2013-11-23
Good day Experts.
So I just started taking a Java class (no pun intended).

Instructor gave us an assignment to write an applet based on Hello World program (see attached code).  Need to output information like Name, college, age - each on their own line.

Question is, if g.drawString puts everything on one line, what's the command to go to the next line?
/* FILE: Applet1.java */
/* A Java applet. */
import java.awt.Graphics;
import java.applet.Applet;
public class Applet1 extends Applet {
public void paint( Graphics g )
{
g.drawString("Hello World!", 25, 25);
}
}
<!-- FILE: Applet1.html -->
<html>
<applet code="Applet1.class" width=275 height=125>
</applet>
</html>

Open in new window

0
Comment
Question by:Geisrud
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
3 Comments
 
LVL 47

Accepted Solution

by:
for_yan earned 500 total points
ID: 36485616
g.drawString(String s, int x, int y) - has arguments x and y which pint to exact location
where the string starts - so you need to calcyulate new values x and y so that new string starte below the previous string.
0
 
LVL 47

Expert Comment

by:for_yan
ID: 36485628


value x is number of pixels counted horizontally form the left border of your
component where you are drawing
value y is counted vertically from the top borde

so ig you have

g.drawString("Name", 25, 50)
g.darwString("Address",25, 70)

you'll see Address start just below the plcae  where "Name" starts

so next string

g.drawSring("Phone", 25, 90);

will be one line lowere

0
 
LVL 47

Expert Comment

by:for_yan
ID: 36485632
In comparison to say
System.out.println(String) command
with darwString you have much more flexibility - you can even print
one on top of another or with minimal itervals, etc, etc

On the other hand you should take care of all formatting in your code
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:

610 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question