|
|
JPanel MyPanel = new JPanel(); |
JLabel L = new JLabel("Hello World !"); JPanel P = new JPanel(); P.add(L); |
Note:
|
import java.awt.*; import javax.swing.*; public class Frame4a { public static void main(String[] args) { JFrame f = new JFrame("JFrame with a JPanel"); JLabel L = new JLabel("Hello World !"); // Make a JLabel; JPanel P = new JPanel(); // Make a JPanel; P.add(L); // (1) Add lable L to JPanel P f.getContentPane().add(P); // (2) Then add panel P to JFrame f f.setSize(400,300); f.setVisible(true); } } |
How to run the program:
|
|