-1

So this is my 3rd post for this project, hopefully the last. So when my program does on the math in the other classes, it needs to come out to a JLabel. the problem is, it doesn't show up. Maby one of you could help me? Sorry the code will be f'ed up when I post it, I cant fix it.

import java.awt.Color;

import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;


public class AFA {

    public void answer() {
        System.out.println("1");
        int area = (int) (AF.length * AF.width);

        String an = String.valueOf(area);

        JFrame answer = new JFrame();

        answer.setBackground(Color.yellow);
        JPanel pan2 = new JPanel();
        JLabel a = new JLabel("The answer is " + an + "We got this by multiplying the Lenght by the width");
        pan2.add(a);
        System.out.println("1");
        answer.setVisible(true);            
    }    
}
Eng.Fouad
  • 115,165
  • 71
  • 313
  • 417
  • Oh for pity's sake, post an [SSCCE](http://sscce.org/) like I posted as an answer to your last question. I was going to run the code to see if this is a duplicate of the last question, but could not be bothered turning your code into an SSCCE *again!* – Andrew Thompson Jul 05 '12 at 08:17
  • possible duplicate of [simple GUI not showing up?](http://stackoverflow.com/questions/11339398/simple-gui-not-showing-up) – Andrew Thompson Jul 05 '12 at 08:18
  • Same code, different question. – Timothy O'Connell Jul 06 '12 at 01:25

2 Answers2

5

You never added the panel to the frame. Adding the below line should fix this.

answer.setContentPane(pan2);
Manoj
  • 5,542
  • 9
  • 54
  • 80
0

You could try using the JPanel's revalidate() and repaint() methods. This question might provide more information.

Community
  • 1
  • 1
Matt
  • 3,820
  • 16
  • 50
  • 73