Example usage for javax.swing JFrame JFrame

List of usage examples for javax.swing JFrame JFrame

Introduction

In this page you can find the example usage for javax.swing JFrame JFrame.

Prototype

public JFrame() throws HeadlessException 

Source Link

Document

Constructs a new frame that is initially invisible.

Usage

From source file:Main.java

public static void main(String... args) {
    JFrame frame = new JFrame();

    frame.addWindowListener(new WindowAdapter() {
        public void windowClosing(WindowEvent we) {
            int result = JOptionPane.showConfirmDialog(frame, "Do you want to Exit ?", "Exit Confirmation : ",
                    JOptionPane.YES_NO_OPTION);
            if (result == JOptionPane.YES_OPTION)
                frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            else if (result == JOptionPane.NO_OPTION)
                frame.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
        }//  w ww  .  j  a  v a 2 s.com
    });

    frame.setSize(300, 300);
    frame.setVisible(true);

}

From source file:Main.java

public static void main(String[] args) {
    JFrame frame = new JFrame();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    JPanel panel = new JPanel();
    final JButton button = new JButton("Select files...");
    button.addActionListener(e -> {/*from w w w  . ja v  a2s  .  c  o  m*/
        final JFileChooser chooser = new JFileChooser();
        chooser.setCurrentDirectory(chooser.getFileSystemView().getParentDirectory(new File("C:\\")));
        chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
        chooser.showDialog(button, "Select file");
    });
    panel.add(button);
    frame.add(panel);
    frame.pack();
    frame.setVisible(true);
}

From source file:UnicodeText.java

public static void main(String[] args) {
    JFrame f = new JFrame() {
        public void paint(Graphics g) {
            Graphics2D g2 = (Graphics2D) g;
            g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);

            Font font = new Font("Lucida Sans Regular", Font.PLAIN, 32);

            g2.setFont(font);/*from   ww w .jav  a 2  s.  c  o m*/
            g2.drawString("\u032e\u0624\u0639", 40, 80);
        }
    };
    f.setSize(200, 200);
    f.setVisible(true);
}

From source file:Main.java

public static void main(String[] args) {
    JFrame frame = new JFrame();
    frame.setMaximumSize(new Dimension(350, 250));
    frame.addComponentListener(new ComponentAdapter() {
        public void componentResized(ComponentEvent evt) {
            Dimension size = frame.getSize();
            Dimension max = frame.getMaximumSize();
            if (size.getWidth() > max.getWidth()) {
                frame.setSize((int) max.getWidth(), (int) size.getHeight());
            }/*from   w w  w .j  a  va2 s .c o m*/
            if (size.getHeight() > max.getHeight()) {
                frame.setSize((int) size.getWidth(), (int) max.getHeight());
            }
        }
    });
    frame.setSize(200, 100);
    frame.setVisible(true);
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}

From source file:MainClass.java

public static void main(final String args[]) {
    JFrame frame = new JFrame();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    JDesktopPane desktop = new JDesktopPane();

    JInternalFrame palette = new JInternalFrame("Palette", true, false, true, false);
    palette.setBounds(350, 150, 100, 100);
    palette.putClientProperty("JInternalFrame.isPalette", Boolean.TRUE);
    desktop.add(palette, JDesktopPane.PALETTE_LAYER);
    palette.setVisible(true);/*  www. ja v a 2  s.  c om*/

    frame.add(desktop, BorderLayout.CENTER);
    frame.setSize(500, 300);
    frame.setVisible(true);
}

From source file:Main.java

public static void main(String[] args) {
    JFrame frame = new JFrame();
    JComponent button = new JButton("Cut");
    String tooltiptext = "<html>" + "This is the " + "<img src=\"file:cut.gif\">" + " tool tip text."
            + "</html>";
    button.setToolTipText(tooltiptext);//from  w w w . j av a 2s .c om
    JPanel panel = new JPanel();
    panel.add(button);
    frame.add(panel, BorderLayout.CENTER);
    frame.setSize(400, 400);
    frame.setVisible(true);
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}

From source file:Main.java

public static void main(String[] args) {
    JFrame f = new JFrame();
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    f.add(new JTable(new Object[][] { { 1, 2, 3 }, { 4, 5, 6 } }, new Object[] { "one", "two", "three" }) {
        {//w  ww.j  a  va 2 s .  c o  m
            addMouseMotionListener(new MouseAdapter() {
                @Override
                public void mouseDragged(MouseEvent e) {
                    System.out.println("mouseDragged");
                }

                @Override
                public void mousePressed(MouseEvent e) {
                    System.out.println("mousePressed");
                }

                @Override
                public void mouseReleased(MouseEvent e) {
                    System.out.println("mouseReleased");
                }
            });
        }
    });
    f.setVisible(true);
}

From source file:Main.java

public static void main(String[] a) {
    JFrame frame = new JFrame();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    JTextField textField = new JTextField("A TextField");
    textField.addFocusListener(new FocusListener() {
        public void focusGained(FocusEvent e) {
            displayMessage("Focus gained", e);
        }//ww w .ja  v  a  2 s  . c  om

        public void focusLost(FocusEvent e) {
            displayMessage("Focus lost", e);
        }

        void displayMessage(String prefix, FocusEvent e) {
            System.out.println(e.getID() == FocusEvent.FOCUS_GAINED);
        }
    });
    frame.add(textField, "North");
    frame.add(new JTextField(), "South");
    frame.setSize(300, 200);
    frame.setVisible(true);
}

From source file:Main.java

public static void main(String[] a) {
    JFrame frame = new JFrame();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    JPanel outerPanel = new JPanel(new BorderLayout());
    JPanel topPanel = new JPanel(new BorderLayout());
    JLabel label = new JLabel("Name:");
    JTextField text = new JTextField();
    topPanel.add(label, BorderLayout.PAGE_START);
    topPanel.add(text, BorderLayout.CENTER);
    outerPanel.add(topPanel, BorderLayout.AFTER_LAST_LINE);

    frame.add(outerPanel);/*from w  w  w. j  a v a  2 s.  com*/
    frame.setSize(300, 200);
    frame.setVisible(true);

}

From source file:Main.java

public static void main(String[] a) {
    JFrame frame = new JFrame();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    JPanel outerPanel = new JPanel(new BorderLayout());
    JPanel topPanel = new JPanel(new BorderLayout());
    JLabel label = new JLabel("Name:");
    JTextField text = new JTextField();
    topPanel.add(label, BorderLayout.LINE_START);
    topPanel.add(text, BorderLayout.CENTER);
    outerPanel.add(topPanel, BorderLayout.AFTER_LAST_LINE);

    frame.add(outerPanel);/*from   w  w w .  jav a 2s  .  co m*/
    frame.setSize(300, 200);
    frame.setVisible(true);

}