
-----------------------------------
Talion
Wed Oct 24, 2007 10:32 pm

Problems seeing Swing
-----------------------------------
Erm I'm not entirely sure what my problem is, but I'm just practicing some rather simple Java stuff and i'm having issues. Just decided as a refresher i'd make a really really basic face :P so basic in fact well...you can see for yourself.

import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Rectangle;
import java.awt.geom.Ellipse2D;
import java.awt.geom.Line2D;
import javax.swing.JPanel;
import javax.swing.JComponent;

public class FaceComponent extends JComponent
{
  public void paintcomponent (Graphics g)
  {
    Graphics2D g2 = (Graphics2D) g;
    
    //head
    Ellipse2D.Double head = new Ellipse2D.Double(5,10,100,150);
    g2.draw(head);
    
    //eye1
    Line2D.Double eye1 = new Line2D.Double(25,70,45,90);
    g2.draw(eye1);
    
    //eye2
    Line2D.Double eye2 = new Line2D.Double(5,70,65,90);
    g2.draw(eye2);
     
    //mouth
    Rectangle mouth = new Rectangle(30,130,50,5);
    g2.setColor(Color.RED);
    g2.fill(mouth);
    
    g2.setColor(Color.BLUE);
    g2.drawString("Hello World!Remember me?",5,175);
  }
}

As you can see, just refreshing myself on really really simple things >>;

import javax.swing.JFrame;

public class FaceViewer
{
  public static void main(String[] args)
  {
    JFrame frame = new JFrame();
    frame.setSize(300,400);
    frame.setTitle("Hello Face");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    FaceComponent component = new FaceComponent();
    frame.add(component);
    frame.setVisible(true);
  }
}

This is what i've done to run it. I assumed that would work, and it compiles fine and runs itself, but when it does it's just a blank screen. Am I missing something here? :S I hate to ask such a question but the sooner I remember all this stuff the better and i'm not above asking for help in relearning stuff i've forgotten :P Please help? If i'd like to move on to bigger and better things >>; but if I can't even run this properly kind of hard....hm, hopefully by the time someone answers i'll have figured it out myself. >>;;i

-----------------------------------
Aziz
Sun Oct 28, 2007 12:41 pm

RE:Problems seeing Swing
-----------------------------------
Not quite sure, but it could probably be something to do with the fact that you're using a JComponent. Usually you can just subclass JPanel. See if that makes a difference.
