I just want to make a JFrame that will say "Hello world", nothing big, no interaction needed. How do I do this?
I can create the JFrame, however I do not know how to put a JPanel with simple text in it.
Here is what I got so far
JFrame frame = new JFrame("Relief Valve");
frame.setResizable(false);
frame.setLocation(500,300);
JPanel p1 = new JPanel();
frame.setVisible(true);
Instead of creating the JPanel
, try:
JLabel label = new JLabel("this is my text");
frame.add(label);
frame.pack();
JFrame window = new JFrame("Hello World App");
window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
window.setLayout(new BorderLayout());
window.add(new JLabel("Hello World"), BorderLayout.CENTER);
window.pack();
window.setVisible(true);
window.setLocationRelativeTo(null);
I'm currently on a mobile device but I'll be happy to document that when I get on a computer, feel free to ask any questions though.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With