0
public class Window extends JFrame implements ActionListener{
public static void main(String[] args) {
   new Window();
}
    public Window() {

        ImageIcon fileIcon = new ImageIcon ("assets/icon.png");
        ImageIcon exitIcon = new ImageIcon ("assets/exit.png");
        JButton exitButton = new JButton("Label");
        JLabel text = new JLabel("Luminate Media");
        JPanel panel = new JPanel();

        setTitle("Luminate");
        setIconImage(fileIcon.getImage());
        setBounds(0, 688, 1366, 40);
        setLayout(null);
        setUndecorated(true);
        setResizable(false);
        setVisible(true);
        setAlwaysOnTop(true);
        getContentPane().setBackground(Color.DARK_GRAY);
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

        text.setFont(new Font("dandelion in the spring", Font.PLAIN, 32));
        text.setBounds(0, 0, 0, 0);
        text.setHorizontalAlignment(SwingConstants.CENTER);
        text.setSize(0, 0);
        text.setForeground(Color.black);
        text.setHorizontalAlignment(0);

        exitButton.setBorder(null);
        exitButton.setBounds(1326, 0, 40, 40);
        exitButton.setIcon(exitIcon);
        exitButton.addActionListener(this);

        panel.setLayout(null);
        panel.setBackground(Color.DARK_GRAY);
        panel.add(exitButton);
        panel.add(text);
        add(panel);
}
    public static void load() {
        //MY PROBLEM IS HERE
                    //HOW DO I CALL THE public Window(){
                    //AS THIS IS NOT THE MAIN CLASS

    }
    @Override
    public void actionPerformed(ActionEvent e) {
        // ALSO I NEED THE CODE THE END THE ENTIRE APPLICATION HERE

    }
}

you can probably see the error and I am unsure of why it is happening. So I am just extremely curious of how to call the window into the load method and if possible could someone tell me the code to end the entire application ?

Hayden Sim
  • 33
  • 1
  • 5
  • 1
    *"you can probably see the error"* What 'error'? -- 1) For better help sooner, post an [SSCCE](http://sscce.org/). 2) Java GUIs might have to work on a number of platforms, on different screen resolutions & using different PLAFs. As such they are not conducive to exact placement of components. To organize the components for a robust GUI, instead use layout managers, or [combinations of them](http://stackoverflow.com/a/5630271/418556), along with layout padding & borders for [white space](http://stackoverflow.com/q/17874717/418556). .. – Andrew Thompson Nov 30 '13 at 12:11
  • .. 3) Don't extend frame or other top level containers. Instead create & use an instance of one. – Andrew Thompson Nov 30 '13 at 12:12

1 Answers1

1

You want to start the application ?

Create a new class (or the same class, does not matter). Add the main method to it. Then use SwingUtilities.invokeLater() to start your application.

See here:http://docs.oracle.com/javase/tutorial/uiswing/concurrency/initial.html

As for closing, clicking the X button on the titlebar will.close it automatically. Is there something special you want to do when window closes ? Like notify the user ?

SSCCE:

import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.SwingUtilities;

public class StartASwingApp extends JFrame{

    JButton close = new JButton("Close");

    public StartASwingApp(){
        getContentPane().add(close,BorderLayout.CENTER);
        pack();
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

        close.addActionListener(new ActionListener(){
            @Override
            public void actionPerformed(ActionEvent arg0) {
                System.exit(0); // closes the application
            }
        });

        setVisible(true);
    }   
//------------------------------------------------------------------------------

    public static void main(String[] args) {
        SwingUtilities.invokeLater(new Runnable(){
            @Override
            public void run(){
                new StartASwingApp();
            }
        });
    }
//------------------------------------------------------------------------------    
}  

Listen to what Andrew Thompson said. Do not extend Swing top-level containers. I have done it here simply to be consistent with your code snippet.

An SO User
  • 24,612
  • 35
  • 133
  • 221