Overclock.net - Overclocking.net
     
 
Home Gallery Reviews Blogs Register Today's Posts Mark Forums Read Members List


Go Back   Overclock.net - Overclocking.net > Software, Programming and Coding > Coding and Programming

Reply
 
LinkBack Thread Tools
Old 04-09-08   #1 (permalink)
Custom User Title
 
pauldovi's Avatar
 
intel nvidia

Join Date: Jul 2005
Location: Daytona Beach, Florida
Posts: 12,852
Blog Entries: 4

Rep: 869 pauldovi is becoming famouspauldovi is becoming famouspauldovi is becoming famouspauldovi is becoming famouspauldovi is becoming famouspauldovi is becoming famouspauldovi is becoming famous
Unique Rep: 479
FAQs Submitted: 4
Hardware Reviews: 2
Trader Rating: 33
Exclamation Java Help!

I don't understand where paintComponent(Graphics g) is being called in this program. Where is graphics g ever made?

Code:
import javax.swing.*;
import java.awt.Graphics;

public class TestPanelDrawing extends JFrame
{
     public TestPanelDrawing()
     {
          add(new NewPanel());
     }

     public static void main(String[] args)
     {
          TestPanelDrawing frame = new TestPanelDrawing();

          frame.setTitle("TestPanelDrawing");
          frame.setLocationRelativeTo(null);
          frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
          frame.setSize(100,100);
          frame.setVisible(true);
     }
}

class NewPanel extends JPanel
{
     protected void paintComponent(Graphics g)
     {
          super.paintComponent(g);
          g.drawLine(0,0,50,50);
          g.drawString("Banner",0,40);
     }
}
__________________
Intel Overclocking Guide * Need A New Password? * Dual Core Folding Guide * Intel Memory Guide * Use Vista's UAC * Don't Post News From Fudzilla!
"Rightful liberty is unobstructed action according to our will within limits drawn around us by the equal rights of others." - Thomas Jefferson
"If everyone is thinking alike, then somebody isn't thinking."
- General George Patton
"Make everything as simple as possible, but not simpler" -Albert Einstein

System: System
CPU
Q6600
Motherboard
ASUS P5Q
Memory
4GB DDR2-800
Graphics Card
EVGA 8800GT
Hard Drive
2 x 7200.10 RAID0 + 160GB
Sound Card
Onboard
Power Supply
Silverstone OP650
Case
Custom Stacker
CPU cooling
Stinger V6
GPU cooling
MCW60
OS
Vista Ultimate 64 bit
Monitor
Dual 20.1" Sceptre
pauldovi is offline Overclocked Account   Reply With Quote
Old 04-09-08   #2 (permalink)
Programmer
 
kdbolt70's Avatar
 
intel ati

Join Date: May 2007
Location: Walled Lake, MI
Posts: 1,100

Rep: 126 kdbolt70 is acknowledged by manykdbolt70 is acknowledged by many
Unique Rep: 91
Folding Team Rank: 154
Trader Rating: 1
Default

Its been a while since I've done java, but it looks like that paintComponent function is just overloaded from JPanel. Therefore, whenever a JPanel's paintComponent function would be called, the NewPanel's is instead. The graphics object is probably created in the constructor of the JPanel... or somewhere similar. Any Java nuts want to chime in?
__________________

~M Hail to the Victors M~

System: It's about time!
CPU
Q6600 G0 @3.3Ghz
Motherboard
Gigabyte P35-DS3L
Memory
2Gb Ballistix DDR2 800 @915Mhz
Graphics Card
Sapphire 2900Pro Flashed to XT
Hard Drive
Seagate Barracuda 320Gb
Sound Card
Onboard
Power Supply
Corsair HX 620W
Case
CM 690
CPU cooling
Tuniq Tower 120
GPU cooling
stock
OS
Vista Business and VMWare Ubuntu
Monitor
Acer AL2223W 22"
kdbolt70 is offline I fold for Overclock.net   Reply With Quote
Old 04-10-08   #3 (permalink)
Programmer
 
Licht's Avatar
 
amd ati

Join Date: Mar 2007
Location: Bel Air
Posts: 8,238
Blog Entries: 3

Rep: 234 Licht is acknowledged by manyLicht is acknowledged by manyLicht is acknowledged by many
Unique Rep: 157
Trader Rating: 0
Default

Its an argument for the function. 'Graphics' is used as a data type and 'g' is the assigned name of the value. For example.

Code:
paintComponent(20)
'g' would then be equal to 20 when executing the code. Thats just an example i didn't read it well enough to get the jist.

I'm not 100% sure i'm just guessing from what i know, and what i know comes from C#, not Java.

System: AMD-AMD-ATI
CPU
AMD Athlon X2 5200+
Motherboard
Gigabyte 790X AM2+
Memory
2x 1Gb Kingston && 2x 1Gb Wintec
Graphics Card
Saphire HD 3870
Hard Drive
[RAID0] [2X] WD 160GB 7,200RPM
Sound Card
X-Fi Extreme Gamer Fatality Professional
Power Supply
OCZ Game-X-Stream 700w
Case
NZXT Black Steel
CPU cooling
Stock Heatskin & Fan
GPU cooling
Stock Saphire 3870 Cooling
OS
Windows Vista Home Premium x64 SP1
Monitor
Samsung SyncMaster 19" Widescreen

Last edited by Licht : 04-10-08 at 12:09 AM.
Licht is online now Licht's Gallery   Reply With Quote
Old 04-10-08   #4 (permalink)
Custom User Title
 
pauldovi's Avatar
 
intel nvidia

Join Date: Jul 2005
Location: Daytona Beach, Florida
Posts: 12,852
Blog Entries: 4

Rep: 869 pauldovi is becoming famouspauldovi is becoming famouspauldovi is becoming famouspauldovi is becoming famouspauldovi is becoming famouspauldovi is becoming famouspauldovi is becoming famous
Unique Rep: 479
FAQs Submitted: 4
Hardware Reviews: 2
Trader Rating: 33
Default

Quote:
Originally Posted by Licht View Post
Its an argument for the function. 'Graphics' is used as a data type and 'g' is the assigned name of the value. For example.

Code:
paintComponent(20)
'g' would then be equal to 20 when executing the code. Thats just an example i didn't read it well enough to get the jist.

I'm not 100% sure i'm just guessing from what i know, and what i know comes from C#, not Java.
The thing is, the program never explicitly creates a graphics object, g and it never explicitly calls the method.
__________________
Intel Overclocking Guide * Need A New Password? * Dual Core Folding Guide * Intel Memory Guide * Use Vista's UAC * Don't Post News From Fudzilla!
"Rightful liberty is unobstructed action according to our will within limits drawn around us by the equal rights of others." - Thomas Jefferson
"If everyone is thinking alike, then somebody isn't thinking."
- General George Patton
"Make everything as simple as possible, but not simpler" -Albert Einstein

System: System
CPU
Q6600
Motherboard
ASUS P5Q
Memory
4GB DDR2-800
Graphics Card
EVGA 8800GT
Hard Drive
2 x 7200.10 RAID0 + 160GB
Sound Card
Onboard
Power Supply
Silverstone OP650
Case
Custom Stacker
CPU cooling
Stinger V6
GPU cooling
MCW60
OS
Vista Ultimate 64 bit
Monitor
Dual 20.1" Sceptre
pauldovi is offline Overclocked Account   Reply With Quote
Old 04-10-08   #5 (permalink)
Programmer
 
Licht's Avatar
 
amd ati

Join Date: Mar 2007
Location: Bel Air
Posts: 8,238
Blog Entries: 3

Rep: 234 Licht is acknowledged by manyLicht is acknowledged by manyLicht is acknowledged by many
Unique Rep: 157
Trader Rating: 0
Default

Quote:
Originally Posted by pauldovi View Post
The thing is, the program never explicitly creates a graphics object, g and it never explicitly calls the method.
Very puzzling.

System: AMD-AMD-ATI
CPU
AMD Athlon X2 5200+
Motherboard
Gigabyte 790X AM2+
Memory
2x 1Gb Kingston && 2x 1Gb Wintec
Graphics Card
Saphire HD 3870
Hard Drive
[RAID0] [2X] WD 160GB 7,200RPM
Sound Card
X-Fi Extreme Gamer Fatality Professional
Power Supply
OCZ Game-X-Stream 700w
Case
NZXT Black Steel
CPU cooling
Stock Heatskin & Fan
GPU cooling
Stock Saphire 3870 Cooling
OS
Windows Vista Home Premium x64 SP1
Monitor
Samsung SyncMaster 19" Widescreen
Licht is online now Licht's Gallery   Reply With Quote
Old 04-10-08   #6 (permalink)
Intel Overclocker
 
h33b's Avatar
 
intel nvidia

Join Date: Feb 2008
Location: $Texas
Posts: 1,149

Rep: 124 h33b is acknowledged by manyh33b is acknowledged by many
Unique Rep: 106
Folding Team Rank: 231
Team Name: Lone Folders
Trader Rating: 11
Default

i'm not familiar much with java, but could it be a parent method called from the two imports at the top of the code?
__________________
My lapped q6600 and Tuniq Tower
Folding for OCN
Quote:
Originally Posted by pioneerisloud View Post
And NEVER go AS5 to mouth!
Killed my first motherboard due to overclock on 5/17/08 - I'll miss you P5N-E SLI

System: Monster Mash
CPU
C2Q Q6600 G0 @ 3.4 (lapped)
Motherboard
Asus p5k Deluxe Wifi
Memory
4x1GB OCZ SLI PC8500
Graphics Card
Asus 8800GTX 768MB
Hard Drive
WD 250GB x2 Raid 0; WD 640AAKS
Sound Card
X-Fi Xtreme Music + Front Panel
Power Supply
OCZ Xtreme 700W
Case
Antec P182
CPU cooling
Tuniq Tower 120 (lapped)
GPU cooling
HR-03 Plus
OS
Vista Ultimate x64
Monitor
Sceptre x22wg-Gamer
h33b is offline I fold for Overclock.net   Reply With Quote
Old 04-10-08   #7 (permalink)
Kernel Sanders
 
rabidgnome229's Avatar
 
intel nvidia

Join Date: Feb 2006
Location: Pittsburgh
Posts: 4,894
Blog Entries: 1

Rep: 548 rabidgnome229 is becoming famousrabidgnome229 is becoming famousrabidgnome229 is becoming famousrabidgnome229 is becoming famousrabidgnome229 is becoming famousrabidgnome229 is becoming famous
Unique Rep: 326
FAQs Submitted: 6
Trader Rating: 5
Default

Java does that stuff behind the scenes. When you do something with graphics it makes a new thread which is invisible to you. Somewhere in that thread it creates the graphics object and calls paintComponent. You don't need to know the context in which it is called, but you do need to specify what happens when the call is made
__________________
BIG BROTHER
I put on my robe and wizard hat...

IS WATCHING

System: It goes to eleven
CPU
E6300
Motherboard
DS3
Memory
2GB XMS2 DDR2-800
Graphics Card
EVGA 8600GTS
Hard Drive
1.294 TB
Sound Card
Audigy 2 ZS
Power Supply
Corsair 520HX
Case
Lian-Li v1000B Plus
CPU cooling
TTBT
GPU cooling
Thermalright V2
OS
Arch Linux/XP
Monitor
Samsung 226bw
rabidgnome229 is offline Overclocked Account   Reply With Quote
Old 04-10-08   #8 (permalink)
Hebrew Hammer
 
TheLegend's Avatar
 
intel nvidia

Join Date: Jan 2006
Location: Milwaukee, WI
Posts: 5,719

FAQs Submitted: 1
Trader Rating: 21
Default

Is this code that was provided to you by your professor?
__________________
|
PC Audio Setup:
JRiver Media Center ASIO(FLAC) > E-MU 0404 USB > LD MKIII > Grado SR225 / HD555

Fold for 37726
Folding Team "Just Be Cause" Honorary Member

System: Legendary
CPU
E6750
Motherboard
ASUS P5B Deluxe
Memory
2 x 2GB G.Skill PQ
Graphics Card
XFX 8800GT [721|1802|2050]
Hard Drive
Seagate 250GB x 2
Sound Card
X-Fi XtremeMusic
Power Supply
PC P&C Quad 750W Silencer
Case
Thermaltake Tsunami Dream
CPU cooling
Tuniq Tower 120 | Lapped
OS
Vista x64
Monitor
Samsung 225BW
TheLegend is offline Overclocked Account   Reply With Quote
Old 04-10-08   #9 (permalink)
Custom User Title
 
pauldovi's Avatar
 
intel nvidia

Join Date: Jul 2005
Location: Daytona Beach, Florida
Posts: 12,852
Blog Entries: 4

Rep: 869 pauldovi is becoming famouspauldovi is becoming famouspauldovi is becoming famouspauldovi is becoming famouspauldovi is becoming famouspauldovi is becoming famouspauldovi is becoming famous
Unique Rep: 479
FAQs Submitted: 4
Hardware Reviews: 2
Trader Rating: 33
Default

Quote:
Originally Posted by TheLegend View Post
Is this code that was provided to you by your professor?
Book. And it doesn't make logical sense to me.
__________________
Intel Overclocking Guide * Need A New Password? * Dual Core Folding Guide * Intel Memory Guide * Use Vista's UAC * Don't Post News From Fudzilla!
"Rightful liberty is unobstructed action according to our will within limits drawn around us by the equal rights of others." - Thomas Jefferson
"If everyone is thinking alike, then somebody isn't thinking."
- General George Patton
"Make everything as simple as possible, but not simpler" -Albert Einstein

System: System
CPU
Q6600
Motherboard
ASUS P5Q
Memory
4GB DDR2-800
Graphics Card
EVGA 8800GT
Hard Drive
2 x 7200.10 RAID0 + 160GB
Sound Card
Onboard
Power Supply
Silverstone OP650
Case
Custom Stacker
CPU cooling
Stinger V6
GPU cooling
MCW60
OS
Vista Ultimate 64 bit
Monitor
Dual 20.1" Sceptre
pauldovi is offline Overclocked Account   Reply With Quote
Old 04-10-08   #10 (permalink)
Hebrew Hammer
 
TheLegend's Avatar
 
intel nvidia

Join Date: Jan 2006
Location: Milwaukee, WI
Posts: 5,719

FAQs Submitted: 1
Trader Rating: 21
Default

Quote:
Originally Posted by pauldovi View Post
Book. And it doesn't make logical sense to me.
Wish I could be of more help, but I don't have much experience with Java graphics.
__________________
|
PC Audio Setup:
JRiver Media Center ASIO(FLAC) > E-MU 0404 USB > LD MKIII > Grado SR225 / HD555

Fold for 37726
Folding Team "Just Be Cause" Honorary Member

System: Legendary
CPU
E6750
Motherboard
ASUS P5B Deluxe
Memory
2 x 2GB G.Skill PQ
Graphics Card
XFX 8800GT [721|1802|2050]
Hard Drive
Seagate 250GB x 2
Sound Card
X-Fi XtremeMusic
Power Supply
PC P&C Quad 750W Silencer
Case
Thermaltake Tsunami Dream
CPU cooling
Tuniq Tower 120 | Lapped
OS
Vista x64
Monitor
Samsung 225BW
TheLegend is offline Overclocked Account   Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools



All times are GMT -4. The time now is 11:51 PM.


Overclock.net is a Carbon Neutral Site Creative Commons License Internet Security By ControlScan

Terms of Service / Forum Rules | Privacy Policy | Advertising | Become an Official Vendor
Copyright © 2008 Shogun Interactive Development. Most rights reserved.
Page generated in 0.20620 seconds with 9 queries