Beginner Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
FaxWave - Free Trial.
Go Back   Dev Shed ForumsOtherBeginner Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
You don't need a fax machine to get faxes. Get a fax-to-email fax number from CallWave. Try it free.
  #1  
Old November 10th, 2002, 07:29 AM
Hargos Hargos is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2002
Posts: 8 Hargos User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Simple JAVA question from a beginner

Hi there, i wonder if anyone could help me understand this simple applet.
I am just a beginner programmer in Java (although experienced in other non OOP languages) and still having difficulty with objects etc.
In the applet below i dont really understand whats happening in line 6.

Font header = new Font("TimesRoman",3,24);

I know that Font is a class and that the three arguments of Fonts are its three properties but
its the word 'header' that confuses me. Is this line creating an object, called header, of the Font class and
therefore takes on its three properties? Is header a referenced variable? If you could explain exactly
what it is i would be very grateful.

and lastly could you explain what the g is on line 10

public void paint(Graphics g)

is it an object? and what does it have to do in the following lines?

g.setFont(header);
g.drawString("Times Roman, Bold & Italic, 24 Point",0,30);

thanks very much in advance, this would be a great help.

--------------------------------------------------

import java.awt.*;
import java.applet.*;

public class Fonts extends Applet
{
Font header = new Font("TimesRoman",3,24);
Font subhead = new Font("Helvetica",Font.BOLD,218);
Font body = new Font("Courier",0,14);

public void paint(Graphics g)
{

g.setFont(header);
g.drawString("Times Roman, Bold & Italic, 24 Point",0,30);
g.setFont(subhead);
g.drawString("Helvetica, Bold, 18 Point",0,60);
g.setFont(body);
g.drawString("Courier, 14 Point",0,90);
}
}

Reply With Quote
  #2  
Old November 11th, 2002, 12:39 PM
M.Hirsch M.Hirsch is offline
Contributing User
Dev Shed God 1st Plane (5500 - 5999 posts)
 
Join Date: Oct 2000
Location: Back in the real world.
Posts: 5,969 M.Hirsch User rank is First Lieutenant (10000 - 20000 Reputation Level)M.Hirsch User rank is First Lieutenant (10000 - 20000 Reputation Level)M.Hirsch User rank is First Lieutenant (10000 - 20000 Reputation Level)M.Hirsch User rank is First Lieutenant (10000 - 20000 Reputation Level)M.Hirsch User rank is First Lieutenant (10000 - 20000 Reputation Level)M.Hirsch User rank is First Lieutenant (10000 - 20000 Reputation Level)M.Hirsch User rank is First Lieutenant (10000 - 20000 Reputation Level)M.Hirsch User rank is First Lieutenant (10000 - 20000 Reputation Level) 
Time spent in forums: 1 Month 1 Day 22 h 39 m 55 sec
Reputation Power: 184
let me try to explain (i am not a java pro but i am quite good at oop)
Code:
Font header = new Font("TimesRoman",3,24);


create a new variable called "header" of type "Font" (the first Font in the line) and then make it an instance of class Font with calling the constructor of class Font that takes three parameters (one string, two numbers).
after passing this this line, "header" is an object, an instance of class "Font".
thus you can eg. call methods:
Code:
header.setFontName("Arial");
int myFontSize=header.getFontSize();

(those names are inventions by me as i am not in the mood to look up the Font class in the reference right now...)

for your second question:
Code:
public void paint(Graphics g)


this is the code to define a function (aka method if itīs inside a class). itīs name is "paint", it has no return parameter and it takes one parameter called "g" which should be an instance of class "Graphics".

this function is called by the virtual machine to make the program paint itself. the virtual machine passes one parameter of type "Graphics" that is the main graphical context of your applet. there you can paint on and the virtual machine will make sure that what you paint on it will appear on the screen.

if you still have questions, go ahead
__________________
--
Manuel Hirsch - Linux, FreeBSD, programming, administration articles, tutorials and more.

Last edited by M.Hirsch : November 11th, 2002 at 12:41 PM.

Reply With Quote
  #3  
Old November 12th, 2002, 02:55 AM
Hargos Hargos is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2002
Posts: 8 Hargos User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Thanks

Thanks M.Hirsch ,

that has really cleared a few things up, i have been working through a beginners Java course and that part wasnt explained properly.
Cheers, Hargos

Reply With Quote
Reply

Viewing: Dev Shed ForumsOtherBeginner Programming > Simple JAVA question from a beginner


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

 Free IT White Papers!
 
Accelerating Trading Partner Performance
One in five. That's how many partner transactions have at least one error. That is an amazing statistic, particularly given the extraordinary leaps in innovation across the global supply chain during the past two decades. Download this white paper to learn more.

 
Competing on Analytics
This Tech Analysis is designed to help identify characteristics shared by analytics competitors, and includes information about 32 organizations that have made a commitment to quantitative, fact-based analysis.

 
Cost Effective Scaling with Virtualization and Coyote Point Systems
An overview of the industry trend toward virtualization, how server consolidation has increased the importance of application uptime and the steps being taken to integrate load balancing technology with virtualized servers.

 
Five Checkpoints to Implementing IP Telephony
Implementation planning for IP PBX software and IP telephony has become vital as businesses replace discontinued legacy PBX phone systems. This informative whitepaper outlines five "checkpoints" for any implementation plan that will help make IP communications a successful proposition.

 
Hosted Email Security: Staying Ahead of New Threats
In the last two years, email has become a fierce battleground between the nefarious forces of spam and malware, and the heroes of messaging protection. The spam volumes increased alarmingly every month, bringing clever new forms of phishing and virus propagation attacks.

 

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway