0
import javax.swing.*;
import javax.swing.JFrame;
public class Ejer1 {
	public static void main(String [] args){
		JFrame frame = new JFrame (Box);
		frame.setVisible(true);
		frame.setSize(300,300);
		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		
		JLabel label = new JLabel();
		JPanel panel = new JPanel();
		frame.add(panel);
		frame.add(label);
		
		
	System.out.println("*********");
	System.out.printf("%s\n%s\n%s\n%s\n%s\n", "*       *","*       *","*       *",
			"*       *", "*       *","*", "*       *","*     *","*        *","*        *","*         *","*        *");
	System.out.println("*********");
	
	}
	}
3
Contributors
2
Replies
5
Views
6 Years
Discussion Span
Last Post by kramerd
0

Put what you are attempt to System.out as a string in an object like JTextArea. Then add the JTextArea to the panel...

0

You can also use html format with a JLabel like this:

String text = "<html><pre>"; 
      text += "*********<br>";
      text += "*       *<br>";
      text += "*       *<br>";
      text += "*       *<br>";
      text += "*       *<br>";
      text += "*       *<br>";
      text += "*********<br>";

      JLabel label = new JLabel(text);

Note that in your code above, you add the panel to the frame and then you add the label to the frame. This makes the label overwrite the panel, so the panel isn't doing anything. You should add the label to the panel first, and then add the panel to the frame. Also, you should make the frame visible at the very end of the method, after everything has been added.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.