JDesktopPane demo : InternalFrame « Swing JFC « Java

Java
1. 2D Graphics GUI
2. 3D
3. Advanced Graphics
4. Ant
5. Apache Common
6. Chart
7. Collections Data Structure
8. Database SQL JDBC
9. Design Pattern
10. Development Class
11. Email
12. Event
13. File Input Output
14. Game
15. Hibernate
16. J2EE
17. J2ME
18. JDK 6
19. JSP
20. JSTL
21. Language Basics
22. Network Protocol
23. PDF RTF
24. Regular Expressions
25. Security
26. Servlets
27. Spring
28. Swing Components
29. Swing JFC
30. SWT JFace Eclipse
31. Threads
32. Tiny Application
33. Velocity
34. Web Services SOA
35. XML
Microsoft Office Word 2007 Tutorial
Java Tutorial
Java Source Code / Java Documentation
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
C# / C Sharp
C# / CSharp Tutorial
ASP.Net
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
PHP
Python
SQL Server / T-SQL
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Java » Swing JFC » InternalFrameScreenshots 
JDesktopPane demo
JDesktopPane demo

/*
Definitive Guide to Swing for Java 2, Second Edition
By John Zukowski     
ISBN: 1-893115-78-X
Publisher: APress
*/

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Component;
import java.awt.Container;
import java.awt.Graphics;
import java.awt.GridLayout;
import java.awt.Polygon;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.Icon;
import javax.swing.JButton;
import javax.swing.JDesktopPane;
import javax.swing.JFrame;
import javax.swing.JOptionPane;

public class Examples {
  public static void main(String args[]) {

    JFrame frame = new JFrame("Example Popup");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    Container contentPane = frame.getContentPane();
    contentPane.setLayout(new GridLayout(01));

    JFrame frame2 = new JFrame("Desktop");
    final JDesktopPane desktop = new JDesktopPane();
    frame2.getContentPane().add(desktop);
    JButton pick = new JButton("Pick");
    pick.addActionListener(new ActionListener() {
      public void actionPerformed(ActionEvent actionEvent) {
        System.out.println("Hi");
      }
    });
    frame2.getContentPane().add(pick, BorderLayout.SOUTH);

    JButton messagePopup = new JButton("Message");
    contentPane.add(messagePopup);
    messagePopup.addActionListener(new ActionListener() {
      public void actionPerformed(ActionEvent actionEvent) {
        Component source = (ComponentactionEvent.getSource();
        JOptionPane.showMessageDialog(source, "Printing complete");
        JOptionPane.showInternalMessageDialog(desktop,
            "Printing complete");
      }
    });

    JButton confirmPopup = new JButton("Confirm");
    contentPane.add(confirmPopup);
    confirmPopup.addActionListener(new ActionListener() {
      public void actionPerformed(ActionEvent actionEvent) {
        Component source = (ComponentactionEvent.getSource();
        JOptionPane.showConfirmDialog(source, "Continue printing?");
        JOptionPane.showInternalConfirmDialog(desktop,
            "Continue printing?");
      }
    });

    JButton inputPopup = new JButton("Input");
    contentPane.add(inputPopup);
    inputPopup.addActionListener(new ActionListener() {
      public void actionPerformed(ActionEvent actionEvent) {
        Component source = (ComponentactionEvent.getSource();
        JOptionPane.showInputDialog(source, "Enter printer name:");
        // Moons of Neptune
        String smallList[] "Naiad""Thalassa""Despina",
            "Galatea""Larissa""Proteus""Triton""Nereid" };
        JOptionPane.showInternalInputDialog(desktop, "Pick a printer",
            "Input", JOptionPane.QUESTION_MESSAGE, null, smallList,
            "Triton");
        // Moons of Saturn - includes two provisional designations to
        // make 20
        String bigList[] "Pan""Atlas""Prometheus""Pandora",
            "Epimetheus""Janus""Mimas""Enceladus""Tethys",
            "Telesto""Calypso""Dione""Helene""Rhea",
            "Titan""Hyperion""Iapetus""Phoebe""S/1995 S 2",
            "S/1981 S 18" };
        //        Object saturnMoon = JOptionPane.showInputDialog(source, "Pick
        // a printer", "Input", JOptionPane.QUESTION_MESSAGE, null,
        // bigList, "Titan");
        Object saturnMoon = JOptionPane.showInputDialog(source,
            "Pick a printer""Input",
            JOptionPane.QUESTION_MESSAGE, null, bigList, null);
        System.out.println("Saturn Moon: " + saturnMoon);
      }
    });

    JButton optionPopup = new JButton("Option");
    contentPane.add(optionPopup);
    optionPopup.addActionListener(new ActionListener() {
      public void actionPerformed(ActionEvent actionEvent) {
        Component source = (ComponentactionEvent.getSource();

        Icon greenIcon = new DiamondIcon(Color.green);
        Icon redIcon = new DiamondIcon(Color.red);
        Object iconArray[] greenIcon, redIcon };
        JOptionPane.showOptionDialog(source, "Continue printing?",
            "Select an Option", JOptionPane.YES_NO_OPTION,
            JOptionPane.QUESTION_MESSAGE, null, iconArray,
            iconArray[1]);

        Icon blueIcon = new DiamondIcon(Color.blue);
        Object stringArray[] "Do It""No Way" };
        JOptionPane.showInternalOptionDialog(desktop,
            "Continue printing?""Select an Option",
            JOptionPane.YES_NO_OPTION,
            JOptionPane.QUESTION_MESSAGE, blueIcon, stringArray,
            stringArray[0]);
      }
    });

    frame.setSize(300200);
    frame.setVisible(true);
    frame2.setSize(300200);
    frame2.setVisible(true);
  }
}

class DiamondIcon implements Icon {
  private Color color;

  private boolean selected;

  private int width;

  private int height;

  private Polygon poly;

  private static final int DEFAULT_WIDTH = 10;

  private static final int DEFAULT_HEIGHT = 10;

  public DiamondIcon(Color color) {
    this(color, true, DEFAULT_WIDTH, DEFAULT_HEIGHT);
  }

  public DiamondIcon(Color color, boolean selected) {
    this(color, selected, DEFAULT_WIDTH, DEFAULT_HEIGHT);
  }

  public DiamondIcon(Color color, boolean selected, int width, int height) {
    this.color = color;
    this.selected = selected;
    this.width = width;
    this.height = height;
    initPolygon();
  }

  private void initPolygon() {
    poly = new Polygon();
    int halfWidth = width / 2;
    int halfHeight = height / 2;
    poly.addPoint(0, halfHeight);
    poly.addPoint(halfWidth, 0);
    poly.addPoint(width, halfHeight);
    poly.addPoint(halfWidth, height);
  }

  public int getIconHeight() {
    return height;
  }

  public int getIconWidth() {
    return width;
  }

  public void paintIcon(Component c, Graphics g, int x, int y) {
    g.setColor(color);
    g.translate(x, y);
    if (selected) {
      g.fillPolygon(poly);
    else {
      g.drawPolygon(poly);
    }
    g.translate(-x, -y);
  }
}

           
       
Related examples in the same category
1. A quick demonstration of setting up an internal frame in an applicationA quick demonstration of setting up an internal frame in an application
2. A simple extension of the JInternalFrame class that contains a list
3. Working with Internal Frames within a Desktop
4. Internal Frames DemoInternal Frames Demo
5. InternalFrame TestInternalFrame Test
6. JDesktopPane Cascade DemoJDesktopPane Cascade Demo
7. Java X WindowsJava X Windows
8. Desktop Manager DemoDesktop Manager Demo
9. Internal Frame Listener Demo Internal Frame Listener Demo
10. Layered Pane DemoLayered Pane Demo
11. LayeredPane Demo 2: Custom MDILayeredPane Demo 2: Custom MDI
12. LayeredPane Demo 3: Custom MDILayeredPane Demo 3: Custom MDI
13. LayeredPane Demo 4: Custom MDILayeredPane Demo 4: Custom MDI
14. Implements InternalFrameListenerImplements InternalFrameListener
15. InternalFrame demoInternalFrame demo
16. InternalFrameEvent DemoInternalFrameEvent Demo
17. A few interesting things using JInternalFrames, JDesktopPane, and DesktopManagerA few interesting things using JInternalFrames, JDesktopPane, and DesktopManager
18. A quick setting up an Internal Frame in an applicationA quick setting up an Internal Frame in an application
19. Interesting things using JInternalFrames, JDesktopPane, and DesktopManager 2Interesting things using JInternalFrames, JDesktopPane, and DesktopManager 2
w_ww__._java2s__.__co_m__ | Contact Us
Copyright 2003 - 08 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.