|
|
|
#1 (permalink) | |||||||||||||
|
Custom User Title
|
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
|
|||||||||||||
|
|
|
|
#2 (permalink) | |||||||||||||
|
Programmer
|
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?
__________________
Whats this folding I've been hearing about? Crucial Ballistix Club ![]() Member of the OCN Diablo III Club ~M Hail to the Victors M~
|
|||||||||||||
|
|
|
|
#3 (permalink) | |||||||||||||
|
Programmer
|
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) I'm not 100% sure i'm just guessing from what i know, and what i know comes from C#, not Java.
__________________
Last edited by Licht : 04-10-08 at 12:09 AM. |
|||||||||||||
|
|
|
|
#4 (permalink) | ||||||||||||||
|
Custom User Title
|
Quote:
__________________
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
|
||||||||||||||
|
|
|
|
#5 (permalink) | ||||||||||||||
|
Programmer
|
Quote:
![]()
__________________
|
||||||||||||||
|
|
|
|
#6 (permalink) | |||||||||||||
|
Intel Overclocker
|
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 Killed my first motherboard due to overclock on 5/17/08 - I'll miss you P5N-E SLI
|
|||||||||||||
|
|
|
|
#7 (permalink) | |||||||||||||
|
Kernel Sanders
|
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
|
|||||||||||||
|
|
|
|
#8 (permalink) | ||||||||||||
|
Hebrew Hammer
![]() |
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
|
||||||||||||
|
|
|
|
#9 (permalink) | |||||||||||||
|
Custom User Title
|
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
|
|||||||||||||
|
|
|
|
#10 (permalink) | ||||||||||||
|
Hebrew Hammer
![]() |
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
|
||||||||||||
|
|
![]() |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
|
|