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("*********");
	
	}
	}

Recommended Answers

All 2 Replies

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

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.