Having trouble with first GUI
This is my first whack at making a program that has an actually GUI instead of runing in the console. I'm having a hard time though. I'm reading through the stuff on oracle but I can't seem to get this to work. I'm trying to get it to display a window with said background.(Image is in the directory.) How can I make this work?
[Edit] Got in a hurry and forgot the code.]
Code:
import java.awt.*;
import javax.swing.ImageIcon;
import javax.swing.*;
public class DisplayGUI {
public DisplayGUI(){}
public void showDisplay(){
JFrame frame = new JFrame("blah blha asdfsadfd duurrrppp");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JMenuBar greenMenuBar = new JMenuBar();
greenMenuBar.setOpaque(true);
greenMenuBar.setBackground(new Color(154, 165, 127));
greenMenuBar.setPreferredSize(new Dimension(200, 20));
ImageIcon label = createImageIcon("Zexanima.jpeg");
frame.getContentPane().add(label, BorderLayout.CENTER);
frame.setSize(400,500);
frame.setVisible(true);
}
}
Re: Having trouble with first GUI
Can you tell how you run it?
Re: Having trouble with first GUI
Quote:
How can I make this work?
you need to have a main() method in the class that you pass to the java command.